Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-89690

Functions and classes that allow to get whitespace-only text nodes are deprecated without any alternatives

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P3: Somewhat important P3: Somewhat important
    • 6.5.0 Beta1
    • 5.15.2
    • XML: DOM
    • None
    • All
    • 26a73e1b31 (qt/qtbase/dev) 26a73e1b31 (qt/tqtc-qtbase/dev)

      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

        For Gerrit Dashboard: QTBUG-89690
        # Subject Branch Project Status CR V

            sonakur Sona Kurazyan
            asc7uni Mikhail
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes