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

QXmlStreamWriter::writeCharacters called with an empty string makes the end tag non-self-closing

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.9.1
    • None
    • macOS

    Description

       

      The code:

      QString output1;
      QXmlStreamWriter stream1(&output1);
      stream1.setAutoFormatting(true);
      stream1.writeStartDocument();
      stream1.writeStartElement("tag");
      //stream2.writeCharacters(QString());
      stream1.writeEndElement();
      stream1.writeEndDocument();
      
      QString output2;
      QXmlStreamWriter stream2(&output2);
      stream2.setAutoFormatting(true);
      stream2.writeStartDocument();
      stream2.writeStartElement("tag");
      stream2.writeCharacters(QString());
      stream2.writeEndElement();
      stream2.writeEndDocument();
      
      QString output3;
      QXmlStreamWriter stream3(&output3);
      stream3.setAutoFormatting(true);
      stream3.writeStartDocument();
      stream3.writeTextElement("tag", QString());
      stream3.writeEndDocument();
      
      qDebug() << output1;
      qDebug() << output2;
      qDebug() << output3;
      

      Produces:

      "<?xml version=\"1.0\"?>\n<tag/>\n"
      "<?xml version=\"1.0\"?>\n<tag></tag>\n"
      "<?xml version=\"1.0\"?>\n<tag></tag>\n"
      

      I would expect output2/output3 to be the same as output1, i.e. with a self-closing tag. The only difference is the additional call of writeCharacters(QString()).

      Obviously, output3 is the same as output2 because writeTextElement is just a convenience function.

       

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            boernsen boernsen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes