You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I work with XML documents that contain a lot CDATA sections. These are mostly used for content that has to contain some exact value and is sensitive to whitespace changes.
When I use the formatter to format the document, an element like this:
<Payload><![CDATA[x < y]]></Payload>
becomes this:
<Payload>
<![CDATA[x < y]]>
</Payload>
In many cases the added newlines are fine (e.g. if the content is canonicalized or if additional whitespace doesn't matter) but I have to send the document to a system that is very picky about whitespace and doesn't process the element correctly because of the additional newlines.
Another case (this one is fictional though) where this is an issue, is using CDATA for xs:enumeration values. For example, if we have an enumeration that allows values like "<" and ">":
<Operator><![CDATA[<]]></Operator>
is valid, but when formatting it becomes invalid:
<Operator>
<![CDATA[<]]>
</Operator>
which results in an error:
Value '
<
' is not in the enumeration list.
Of course for these small examples, using entities instead CDATA would work. In other cases that's not always feasible though. Is there an option to avoid adding newlines around CDATA sections? I think at least for the second example, where formatting breaks the document, an option like that would be justified.
A third example, where it just subjectively looks bad to me after formatting:
<Payload>x <![CDATA[<]]> y</Payload>
becomes this:
<Payload>
x
<![CDATA[<]]>
y
</Payload>
After thinking a bit more about this topic, I don't see any good reasons why CDATA sections have to be formatted at all.
In my opinion they should be ignored when formatting and just treated as part of the text.
If there are cases where the formatting as in the third example is actually better, I would at least propose to skip adding any newlines when a CDATA section is the only child of an element.
The text was updated successfully, but these errors were encountered:
With the experimental formatter enabled, this section is no longer formatted/ will not add any new lines. Here is the current behavior using the experimental formatter:
I originally created redhat-developer/vscode-xml#585 but now noticed that it rather belongs here:
A third example, where it just subjectively looks bad to me after formatting:
becomes this:
After thinking a bit more about this topic, I don't see any good reasons why CDATA sections have to be formatted at all.
In my opinion they should be ignored when formatting and just treated as part of the text.
If there are cases where the formatting as in the third example is actually better, I would at least propose to skip adding any newlines when a CDATA section is the only child of an element.
The text was updated successfully, but these errors were encountered: