16

Can one specify XML attribute values as CDATA ? If yes - what would be the schema for the same. If not - why is this limitation not addressed in XML ?

gnlogic
  • 1,034
  • 2
  • 9
  • 14

2 Answers2

10

No you cannot do this.

There's a very fine line (and a very large debate) between what constitutes an attribute and what constitutes a child element. See here for example.

That given, the "limitation" isn't addressed in XML because it doesn't exist. You always have the ability to put this data in a child element, and in fact I would go so far as to say that if you even have to think about this, an element is the correct structure.

Edit: More reading material

Community
  • 1
  • 1
annakata
  • 74,572
  • 17
  • 113
  • 180
  • 10
    OK, but if I'm not designing anything but simply trying to uses someone else's DTD/Schema, and need to supply an attribute value that contains illegal characters, what are my options? – Mark Reed Jul 31 '14 at 00:08
1

The way you handle that is to use a child element rather than an attribute.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794