Repository navigation
Preserve spacing in string literal within element #478
Description
Activity
I'm not sure I understand the logic of that graphic.
Why is it that the whitespace within the
<Directions>tag is significant but the whitespace within<Address>is not significant? How can you tell the difference without a schema? Is it just a guess based on whether or not there are child elements in the body of the element? In which case if you add a<foo>into the body of<Directions>does all of the sudden the entire body become whitespace-significant?The whitespace surrounding text within an XML element or attribute value are considered to be "Significant whitespace".
In the case of
<Address>tag, all the immediate child nodes are not text, so the spaces are not significant.
In the case of<Directions>tag, the immediate child nodes are text, so the spaces are significant.If you add a
<foo>into the body of<Direction>, only the spaces within and surrounding the text are significant whitespaces. The children of<foo>may or may not have significant whitespace (that will depend on the content of the<foo>)Reacted by Stéphane BidoulThat's not my understanding of the XML spec. From what I understand unless you specify an
xml:spaceattribute or you're using a DTD schema, all whitespace outside of tags is significant. Can you link me to a spec where that's not the case?You are absolutely correct.
When
xmlWhitespaceSensitivityisstrict, all white spaces must be preserve according to section 2.10: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.
However, this issue is about formatting when
xmlWhitespaceSensitivityisignore. The current implementation is to trim all spaces surrounding and within text nodes. This issue is to propose a new optionpreserveSignificantWhitespaceto preserve the spaces within and surrounding text nodes whenxmlWhitespaceSensitivityisignore.Reacted by Stéphane Bidoul, rrahir and Adrien Minne@kddnewton , please let me know if more clarification is required on this issue.
Instead of additional attribute, I would think having additional options "semantic" or something to that effect would be more easier to consume. As current options is meant to alter how whitespaces are treated and this proposal is just different way to treating it so additional option is not not warranted.
@brsanthu , I agree with your proposal.
SoxmlWhitespaceSensitivitycan have three values:strictall white spaces are preservedignoretrim all spaces surrounding and within text nodesemantic(new) preserve "Significant Whitespace" within XML element and attributes
@kddnewton , what do you think?
- added a commit that references this issue
on Dec 13, 2022
I'm reopening this issue #138 .
I'm suggesting a new option (
preserveSignificantWhitespace: true/false) to preserve "Significant Whitespace" within XML element and attributes. (As shown by the green spaces in the diagram below)