XMLReader* XMLReader::getStringReader(const std::string& content) { XMLReader* result = new XMLReader() ; result->m_reader = xmlReaderForDoc((const xmlChar*) content.c_str(), NULL, NULL, 0) ; result->processNode() ; return result ; }
//## @Native XmlReader String.convertToXml(); static KMETHOD String_convertToXml(KonohaContext *kctx, KonohaStack *sfp) { xmlChar* input = (xmlChar *)kString_text(sfp[0].asString); xmlTextReaderPtr r = xmlReaderForDoc(input, NULL, NULL, 1); //xmlTextReaderPtr r = xmlReaderForDoc(input, NULL, "UTF-8", 1); struct kXmlReaderVar *xml = (struct kXmlReaderVar *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), 0); if(r == NULL) { //kreportf(ErrTag, sfp[K_RTNIDX].uline, "could not create XmlReader Object from String"); } xml->reader = (xmlTextReaderPtr)r; KReturn(xml); }
// This function needs to be re-entrant, it can be called recursively from inside of resolveAll // to load files that the first file depends on. daeInt daeLIBXMLPlugin::read(daeURI& uri, daeString docBuffer) { // Make sure topMeta has been set before proceeding if (topMeta == NULL) { return DAE_ERR_BACKEND_IO; } // Generate a version of the URI with the fragment removed daeURI fileURI(uri.getURI(),true); // Create the right type of xmlTextReader on the stack so this function can be re-entrant xmlTextReaderPtr reader; if(docBuffer) { // Load from memory (experimental) #if 0 //debug stuff printf("Reading %s from memory buffer\n", fileURI.getURI()); #endif reader = xmlReaderForDoc((xmlChar*)docBuffer, fileURI.getURI(), NULL,0); } else { // Load from URI #if 0 //debug stuff printf("Opening %s\n", fileURI.getURI()); #endif reader = xmlReaderForFile(fileURI.getURI(), NULL,0); } if(!reader) { printf( "no libxml2 reader\n"); return DAE_ERR_BACKEND_IO; } // Start parsing the file daeElementRef domObject = startParse(topMeta, reader); // Parsing done, free the xmlReader and error check to make sure we got a valid DOM back xmlFreeTextReader(reader); if (!domObject) { #if defined(_DEBUG) && defined(WIN32) fprintf(stderr,"daeLIBXMLPlugin::read(%s) failed - XML Parse Failed\n", fileURI.getFile()); fflush(stdout); #endif printf("not able to load\n"); return DAE_ERR_BACKEND_IO; } // Insert the document into the database, the Database will keep a ref on the main dom, so it won't gets deleted // until we clear the database daeDocument *document = NULL; int res = database->insertDocument(fileURI.getURI(),domObject,&document); if (res!= DAE_OK) return res; // Make a vector to store a list of the integration items that need to be processed later // postProcessDom will fill this in for us (this should probably not be done in the IOPlugin) std::vector<INTEGRATION_ITEM> intItems; //insert the elements into the database, for this DB the elements are the Collada object which have //an ID. //this function will fill the _integrationItems array as well postProcessDom(document, domObject, intItems); database->validate(); daeElement::resolveAll(); //create the integration objects int size = (int)intItems.size(); int i; for (i=0;i<size;i++) intItems[i].intObject->createFromChecked(intItems[i].element); for (i=0;i<size;i++) intItems[i].intObject->fromCOLLADAChecked(); for (i=0;i<size;i++) intItems[i].intObject->fromCOLLADAPostProcessChecked(); //clear the temporary integration items array intItems.clear(); return DAE_OK; }
XmlTextReader XmlTextReader::CreateFromString(RCString s) { XmlTextReader r; r.m_str = s; r.m_p = XmlCheck(xmlReaderForDoc(BAD_CAST r.m_str.c_str(), 0, 0, XML_PARSE_NOBLANKS)); return r; }