Details
-
Bug
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
5.15
-
None
Description
In the XML specification, 2.10 White Space Handling https://www.w3.org/TR/xml/#sec-white-space the behavior of xml:space="preserve" is defined as
In editing XML documents, it is often convenient to use "white space" (spaces, tabs, and blank lines) to set apart the markup for greater readability. Such white space is typically not intended for inclusion in the delivered version of the document. On the other hand, "significant" white space that should be preserved in the delivered version is common, for example in poetry and source code.
An XML processor must always pass all characters in a document that are not markup through to the application. A validating XML processor must also inform the application which of these characters constitute white space appearing in element content.
A special attribute named xml:space may be attached to an element to signal an intention that in that element, white space should be preserved by applications. In valid documents, this attribute, like any other, must be declared if it is used. When declared, it must be given as an enumerated type whose values are one or both of "default" and "preserve". For example:
<!ATTLIST poem xml:space (default|preserve) 'preserve'>
<!ATTLIST pre xml:space (preserve) #FIXED 'preserve'>
The value "default" signals that applications' default white-space processing modes are acceptable for this element; the value "preserve" indicates the intent that applications preserve all the white space. This declared intent is considered to apply to all elements within the content of the element where it is specified, unless overridden with another instance of the xml:space attribute. This specification does not give meaning to any value of xml:space other than "default" and "preserve". It is an error for other values to be specified; the XML processor may report the error or may recover by ignoring the attribute specification or by reporting the (erroneous) value to the application. Applications may ignore or reject erroneous values.The root element of any document is considered to have signaled no intentions as regards application space handling, unless it provides a value for this attribute or the attribute is declared with a default value.
Unfortunately, QXmlStreamReader with QDomDocument does not respect this MUST requirement. Using the attached test
void QDomDocumentWithSpacesTest::entityWithSpaceAndPreserve() { // an XML document where <Description> has a whitespace as content and uses // xml:space="preserve" QString const xmlDocumentWithSpacePreserve = R"(<?xml version="1.0" encoding="UTF-8"?> <Message xmlns:xs="http://www.w3.org/2001/XMLSchema"> <Description xml:space="preserve"> </Description> </Message> )"; auto const doc = parse(xmlDocumentWithSpacePreserve); QCOMPARE(doc.firstChild().toElement().text(), " "); }
fails
********* Start testing of QDomDocumentWithSpaces *********
Config: Using QtTest library 5.15.3, Qt 5.15.3 (x86_64-little_endian-llp64 shared (dynamic) debug build; by MSVC 2019), windows 10
PASS : QDomDocumentWithSpaces::initTestCase()
PASS : QDomDocumentWithSpaces::entityWithoutSpace()
PASS : QDomDocumentWithSpaces::entityWithSpace()
FAIL! : QDomDocumentWithSpaces::entityWithSpaceAndPreserver() Compared values are not the same
Actual (doc.firstChild().toElement().text()): ""
Expected (" ") :
C:\code\QDomDocument_and_spaces\QDomDocumentWithSpaces.cpp(65) : failure location
PASS : QDomDocumentWithSpaces::cleanupTestCase()
Totals: 4 passed, 1 failed, 0 skipped, 0 blacklisted, 12ms
********* Finished testing of QDomDocumentWithSpaces *********
Attachments
Issue Links
- relates to
-
QTBUG-104130 QDomDocument::setContent() with QXmlStreamReader discards whitespace-only Text nodes
- Closed