[Home] [By Thread] [By Date] [Recent Entries]

  • From: David Carlisle <d.p.carlisle@g...>
  • To: Roger L Costello <costello@m...>
  • Date: Wed, 23 Mar 2022 12:05:36 +0000



On Wed, 23 Mar 2022 at 11:39, Roger L Costello <costello@m...> wrote:
Hi Folks,

I did some testing to see what characters can go into a CDATA section and a comment. Here's what I found:

Recall the CDATA syntax: <![CDATA[ ... ]]>

Question: Can the content of a CDATA section contain the ] character?

<![CDATA[foo]bar]]>

Answer: Yes

Question: Can the content of a CDATA section contain ]]?

<test><![CDATA[foo]]bar]]></test>

Answer: Yes.

Question: Can the content of a CDATA section contain more than two ] characters at the end?

<![CDATA[foo]]]]]>

Answer: Yes.

Question: Can the content of a CDATA section contain more than one [ character at the start?

<![CDATA[[[foo]]>

Answer: Yes.


The perhaps more surprising answer related to this is for the question 

Can element content contain the string ]]> without escaping one of the characters?



Recall the comment syntax: <!-- ... -->

Question: Can the content of a comment contain a dash character?

<!-- foo - bar -->

Answer: Yes.

Question: Can the content of a comment contain two dashes?

<!-- foo -- bar -->

Answer: No.

Question: Can the content of a comment end with more than two dashes?

<!-- foo----->

Answer: No.

Notice the inconsistency: A CDATA section can end with more than two ] characters but a comment cannot end with more than two dashes:
 

<![CDATA[foo]]]]]>      Okay
<!-- foo----->          Error

Also, a CDATA section can contain ]] but a comment cannot contain --

<![CDATA[foo]]bar]]>
<!-- foo -- bar -->

Why is there this inconsistency?

It's not inconsistency, it's historical legacy.  XML comment syntax is a simplified but compatible subset of SGML comment syntax which allows multiple comments within a declaration, marked with --  so

<!ENTITY -- this is a comment -- foo "bar" -- so is this -- >


so if you parsed xml with an sgml parser a -- would end the comment so in xml it's only allowed at the end.


Isn't inconsistency in a data format language bad?

A world without history would be so dull.
 

/Roger


David
 

_______________________________________________________________________

XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.

[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@l...
subscribe: xml-dev-subscribe@l...
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member