I'm trying to get to the root of a problem in some library, and it seems like I don't understand how QDomElement::namespaceURI work, or don't understand how xmlns works.
Here is my minimal isolated code fragment:
#include <iostream>
#include <QString>
#include <QDomDocument>
int main() {
QString request = "<iq from='[email protected]' id='disco1' to='[email protected]' type='get'>";
request = "<query node='someAddress' xmlns='http://jabber.org/protocol/disco#info'/>";
request = "</iq>";
QDomDocument doc;
doc.setContent(request);
QDomElement iq = doc.documentElement();
QDomElement query = iq.firstChildElement();
std::cout << query.tagName().toStdString() << " " << query.namespaceURI().toStdString() << std::endl;
return 0;
}
I compile it this way
g -o xmlTest xmlTest.cpp -lQt5Core -lQt5Xml -I /usr/include/qt -I /usr/include/qt/QtCore -I /usr/include/qt/QtXml
I expect it to print query http://jabber.org/protocol/disco#info
Instead it prints query
and I do not understand why.
What am I doing wrong?
CodePudding user response:
By default QtXml does not do namespace processing. There is an optional bool namespaceProcessing
flag you can pass to setContent()
to enable it.
Modifying that line like so, produces the expected behaviour:
doc.setContent(request, true);
$ ./xmlTest
query http://jabber.org/protocol/disco#info