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

Duplicate xmlns in child elements

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 4.8.7, 5.5.1
    • XML: DOM
    • 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;
      }
      

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            taurus Ivan Romanov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes