views:

291

answers:

1

I have read the tutorial on XML parsing in Bada. But I don't want to use a file. I need to parse my XML from a Osp::Base::String. Any ideas which methods should I use? So far I have replaced

xpathCtx = xmlXPathNewContext(doc);
if(xpathCtx == NULL) {
   AppLog("Error: unable to create new XPath context");
   xmlFreeDoc(doc);
   return(E_IO);
}

with

xpathCtx = (xmlXPathContextPtr) xmlXPathNewCString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><title lang=\"en\">XQuery Kick Start</title><title lang=\"en\">Learning XML</title>");

But the emulator simply closes.

Thank you.

+1  A: 

Your code is wrong because you cannot cast from xmlXPathObjectPtr to xmlXPathContextPtr: they are different structs.

The code given in the tutorial is right, just use

xmlDocPtr xmlReadDoc (const xmlChar * cur, const char * URL, const char * encoding, int options)

instead of

xmlReadFile(..)

To understand how to use this function have a look at the docs and at the examples on libXML2 website.

3mpty
You are quite right my friend. I just wish you had answered my question correctly before I solved the problem myself. The irony here is that I am not currently parsing my XML from a String but from a file, just like in the tutorial. I hope this won't decrease my application performance greatly.
Boris Rusev