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 ?
In a Document Type Definition (DTD) an attributes type can be set to be CDATA. The resulting attribute within an XML document may contain arbitrary character data. So basically the DTD CDATA type is a string type with no restrictions placed on it, it can contain any textual data (as long as its suitably escaped).
CDATA-type attribute value In Document Type Definition (DTD) files for SGML and XML, an attribute value may be designated as being of type CDATA: arbitrary character data. Within a CDATA-type attribute, character and entity reference markup is allowed and will be processed when the document is read.
CDATA sections can appear inside element content and allow < and & character literals to appear. A CDATA section begins with the character sequence <! [CDATA[ and ends with the character sequence ]]>. Between the two character sequences, an XML processor ignores all markup characters such as <, >, and &.
In a DTD, attributes are declared with an ATTLIST declaration.
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
The way you handle that is to use a child element rather than an attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With