-1

Am new to xml. My question is: If the lines inside a CDATA are ignored by an XML parser, does it mean the lines are not executable and if so, is it just the same as a comment?

shadowBot
  • 109
  • 1
  • 6

2 Answers2

0

If the lines inside a CDATA are ignored by an XML parser,

They aren't.

CDATA sections are passed through as text. Characters with special meaning in XML (such as < and &) are treated as literal characters ("less than", "ampersand") instead of their XML meaning ("Start of tag", "Start of character reference").

(The exception is the end of cdata marker, which is treated as having special meaning)

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
0

Nothing in an XML file is "executable", so CDATA is no different from anything else.

There are conventions about how to use things like comments, processing-instructions, and CDATA sections in XML, but they are only conventions. The convention with comments is that they are intended for human readers but should be ignored by software, but they can be abused to contain anything you like. The convention with CDATA is that it's a way of representing text without having to escape special characters such as "&" and "<". But CDATA is widely abused to hold things other than text, for example XML markup. As with anything else in XML, it's ultimately a notation that you can use as you wish; on your own head be it.

Michael Kay
  • 138,236
  • 10
  • 76
  • 143