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

QDomDocument silently erases empty CDATA section

    XMLWordPrintable

Details

    • edb64351cd (qt/qtbase/dev) 67baa15458 (qt/qtbase/6.3) 8b369de926 (qt/qtbase/6.2) 8b369de926 (qt/tqtc-qtbase/6.2) 67baa15458 (qt/tqtc-qtbase/6.3) edb64351cd (qt/tqtc-qtbase/dev)

    Description

      If an XML document contains "<![CDATA[]]>", then the corresponding QDomCDATASection node is not created in Qt 6. Qt 5 does not have this issue.

      There are some documented behaviour changes due to replacing the parser with QXmlStreamReader: https://doc.qt.io/qt-6/xml-changes-qt6.html#qdom-and-qdomdocument However, this does not explain the new behaviour of QDomDocument because QXmlStreamReader does output the empty CDATA section.

      Furthermore, QDomDocument::createCDATASection can produce such an empty section.

       

      Example

      QString xmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                        "<content><![CDATA[]]></content>";
      
      QDomDocument doc;
      doc.setContent(xmlData, false);
      qDebug("RAW:");
      qDebug() << doc.toString();
      
      doc.elementsByTagName("content").at(0).appendChild( doc.createCDATASection("") );
      qDebug("APPENDED:");
      qDebug() << doc.toString();
      

       

      Qt 5 output (correct)

      RAW:
      "<?xml version='1.0' encoding='UTF-8'?>\n<content><![CDATA[]]></content>\n"
      APPENDED:
      "<?xml version='1.0' encoding='UTF-8'?>\n<content><![CDATA[]]><![CDATA[]]></content>\n"
      

       

      Qt 6 output (wrong)

      RAW:
      "<?xml version='1.0' encoding='UTF-8'?>\n<content/>\n"
      APPENDED:
      "<?xml version='1.0' encoding='UTF-8'?>\n<content><![CDATA[]]></content>\n"
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mmutz Marc Mutz
            skoh-qt Sze Howe Koh
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes