tags:

views:

91

answers:

3

I am developing an application in that after making a web service I got the response from the server which is in the XML tag.

The response:

<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n
<string...... /\">Hello World</string>

I want to read only the "Hello World" string. How should I parse it?

A: 

You could use the the QString::replace ( const QString & before, const QString & after, Qt::CaseSensitivity cs = Qt::CaseSensitive ) to replace the XML tokens by blanks.

If the XML tags you will be receiving can be many things, I woulds suggest you implement an XML handler to be able to strip the XML tags from you string.

Live
+1  A: 

I hope this helps:

QByteArray xmlText;
//Get your xml into xmlText(you can use QString instead og QByteArray)
QDomDocument doc;
doc.setContent(xmlText);
QDomNodeList list=doc.elementsByName("string");
QString helloWorld=list.at(0).toElement().text();
metdos
A: 

The best way is to use Qt's XML Patterns module.

http://doc.trolltech.com/4.6/qxmlquery.html

guruz