Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.15.2
-
None
-
-
26a73e1b31 (qt/qtbase/dev) 26a73e1b31 (qt/tqtc-qtbase/dev)
Description
QDomDocument help states:
Text nodes consisting only of whitespace are stripped and won't appear in the QDomDocument. If this behavior is not desired, one can use the setContent() overload that allows a QXmlReader to be supplied.
However overload using QXmlReader is deprecated. There is only QXmlStreamReader overload which doesn't behave same way. There are still no whitespace nodes in the result document.
Code to reproduce:
#include <QDomDocument> #include <QXmlSimpleReader> #include <QXmlStreamReader> #include <QDebug> int main(){ QString xmlString("<original> </original>"); QDomDocument doc; doc.setContent(xmlString); QDomElement docElem = doc.documentElement(); qDebug() << "Without QXmlSimpleReader \t- element contains" <<docElem.text() << "\tlength="<< docElem.text().length(); // 0 doc.clear(); QXmlInputSource source; //Deprecated source.setData(xmlString); QXmlSimpleReader reader; //Deprecated doc.setContent(&source, &reader); //Deprecated docElem = doc.documentElement(); qDebug() << "With QXmlSimpleReader \t- element contains" <<docElem.text() << "\tlength="<< docElem.text().length(); // 6 doc.clear(); QXmlStreamReader str_reader(xmlString); doc.setContent(&str_reader, true); docElem = doc.documentElement(); qDebug() << "With QXmlStreamReader \t- element contains" <<docElem.text() << "\tlength="<< docElem.text().length(); // 0 doc.clear(); return 0; }
Output is:
Without QXmlSimpleReader - element contains "" length= 0 With QXmlSimpleReader - element contains " " length= 6 With QXmlStreamReader - element contains "" length= 0
Attachments
Issue Links
- depends on
-
QTBUG-104507 QDomDocument: improve the setContent() API
-
- Closed
-