Details
-
Bug
-
Resolution: Won't Do
-
P3: Somewhat important
-
None
-
4.8.7, 5.5.1
-
None
Description
QDom::setContent creates excess xmlns attribute for child element when enabled namespace processing. For source xml
<?xml version="1.0" encoding="utf-8"?> <ns:root xmlns:ns="example:com"> <ns:child> text </ns:child> </ns:root>
after QDomDocument I get
<?xml version="1.0" encoding="utf-8"?> <ns:root xmlns:ns="example:com"> <ns:child xmlns:ns="example:com"> text </ns:child> </ns:root>
Another problem here it that setPrefix works only for root element. So if I try to change namespace I get
<?xml version="1.0" encoding="utf-8"?> <ns1:root xmlns:ns1="example:com"> <ns:child xmlns:ns="example:com"> text </ns:child> </ns:root>
My code:
#include <QDebug> #include <QDomDocument> #include <QDomElement> #include <QDomAttr> #define DOC \ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" \ "<ns:root xmlns:ns=\"example:com\">\n" \ " <ns:child>\n" \ "text\n" \ " </ns:child>\n" \ "</ns:root>" int main(int argc, char *argv[]) { Q_UNUSED(argc); Q_UNUSED(argv); QDomDocument doc; doc.setContent(QString(DOC), true); doc.firstChildElement().setPrefix("ns1"); qDebug() << qPrintable(doc.toString(2)); return 0; }