Hi all,
I need to parse an XML file. When a specific node, is found, I need to get the exact test inside that tag, not only the "xml text".
Example:
<root>
<a>11111</a>
<a><b>test 123</b></a>
</root>
<root>
<a>11111</a>
<a><b>test 123</b></a>
</root>
To copy to clipboard, switch view to plain text mode
In this XML I need to be able to get: "1111" and "<b>test 123</b>".
I am using this code in Qt5:
void test1() {
"<root>"
" <a>11111</a>"
" <a><b>test 123</b></a>"
"</root>";
QXmlStreamReader xml(rawXML);
QStringRef s;
xml.readNextStartElement();
s = xml.name();
if (s!="root") {
return;
}
while (!xml.atEnd()) {
xml.readNextStartElement();
s = xml.name();
if (s!="a") {
break;
}
QString ss
= xml.
readElementText(QXmlStreamReader
::IncludeChildElements);
qDebug("%s", qPrintable(ss));
}
}
void test1() {
QString rawXML =
"<root>"
" <a>11111</a>"
" <a><b>test 123</b></a>"
"</root>";
QXmlStreamReader xml(rawXML);
QStringRef s;
xml.readNextStartElement();
s = xml.name();
if (s!="root") {
return;
}
while (!xml.atEnd()) {
xml.readNextStartElement();
s = xml.name();
if (s!="a") {
break;
}
QString ss = xml.readElementText(QXmlStreamReader::IncludeChildElements);
qDebug("%s", qPrintable(ss));
}
}
To copy to clipboard, switch view to plain text mode
This is not working as I expect. I am getting "test 123" and not "<b>test 123</b>".
What is the best approach to handle this situation? How can I parse the XML and getting the desired result?
xml-test1.cpp
EDIT: similar stackoverflow question: http://stackoverflow.com/questions/5...ing-html-in-qt
Bookmarks