05-23-2012 06:25 AM
Hello
Is there a way to parse XML in a QString? All the examples on the web shows how to parse the xml from file but none of them shows how to parse XML from a QString. I have a server that my app connects to via TCP/IP and the server then sends XML to the client (app) that needs to be parsed, it will be a waste of resources to first write the xml to a file.
I have the basic sax parser and my implementation looks like this
XMLHandler *m_handler;
QXmlInputSource *source = new QXmlInputSource(new QFile("asset:///responseMessage.xml"));
QXmlSimpleReader reader;
reader.setContentHandler(m_handler);
reader.parse(source);
How do i change this line
QXmlInputSource *source = new QXmlInputSource(new QFile("asset:///responseMessage.xml"));
to use a string as input and not a file? I know the QXmlInputSource class does not support a string implementation so is there another approach in the API that i can use?
Thank you for any advice!
Solved! Go to Solution.
05-23-2012 07:53 AM
Perhaps QRegExp is what your looking for? Here is a brief example in case it may help: http://stackoverflow.com/questions/3582039/parse-a
Good luck!
Jon
05-23-2012 08:12 AM
Hi Jon
Thanks for the reply. I think that could definitely work (although it would be rather tedious), I just wanted to use XML parsing standars to do this (as you can do this in the older java blackberry sdk). I think that I will go with that method if I cannot find a solution that uses the xml standards.
05-23-2012 11:41 AM
05-24-2012 02:02 AM
I found the solution. I changed my class rather to use a QXmlStreamReader. This can accept QByteArray values in its constructor so i just called the QString toAscii method to convert the string recieved from my server to a QByteArray and passed it to the QXmlStreamReader. This implementation didn't require major changes to my handler so i think this will work the best for my situation. Thanks for all the help guys.