1

An XML element with a list of characters enclosed in ![CDATA[]] so they're treated as characters, not as XML markup.

<list><![CDATA[some-chars-here]]></list> 

The characters list is very long. I want to have subsets of the list, each defined in a variable (formally, in an entity reference)

<!DOCTYPE engineMetadata [
    <!ENTITY set1 "set1-chars">
    <!ENTITY set2 "set2-chars">
]>

that can be used as <list><![CDATA[&set1;&set2]]></list>. This doesn't work, if for the only reason that entity references are now treated as characters, not as XML markup.

Is there a proper way or a workaround to do that?

prgshn
  • 53
  • 4

1 Answers1

1

The workaround is to not use CDATA. Since the only purpose of CDATA is to tell the parser to treat special characters as ordinary characters rather than as markup, if you want special characters treated as markup then you shouldn't put them in CDATA.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • I want special characters treated as ordinary characters not markup. The question is whether it is possible to use a variables and have its value (not the variable reference/name itself) treated as ordinary characters. – prgshn Oct 07 '15 at 18:23
  • When you say "variable", what are you talking about? There are no variables in this example. – Michael Kay Oct 07 '15 at 21:42
  • Entity reference; set1 and set2 in this example. – prgshn Oct 07 '15 at 23:36
  • Entities aren't very flexible. Perhaps you need a different mechanism. You haven't said anything about the problem you are trying to solve. – Michael Kay Oct 08 '15 at 08:26
  • This [answer](https://stackoverflow.com/a/2784200/5832619) appears to contradict your answer – johnnyodonnell Nov 18 '22 at 23:40
  • No it doesn't. If you think so, then you have misunderstood one answer or the other. – Michael Kay Nov 21 '22 at 15:34