buddy123
buddy123

Reputation: 6297

Declaring multiple rules in DTD schema

I have an xml file with dtd schema. I try to add some rules on attributes and elements. so far, I managed to have two ATTLIST for different elements in the following format:

<!DOCTYPE root [
 <!ATTLIST a ..... >
 <!ATTLIST b ..... >
]>

Now I wish to do the following: assume i have:

<a ...><value>some_value_with_&&&</value></a>

of course, that value must be surrounded with <![CDATA[some_value_with_&&&]]>

Since I already have a dtd schema, I thought I can remove the CDATA (leaving it as it initially was) and then declare its a cdata type in the DTD, is that possible? I tried to add the following: <!ELEMENT value (#CDATA)> but i have two issues with it:

  1. It forces itself (I assume) on any value element, can i limit it to only a elements?

  2. I work with java. with that I get the following error: A '(' character or an element type is required in the declaration of element type "value".

Why is that?

Upvotes: 2

Views: 442

Answers (1)

mzjn
mzjn

Reputation: 50947

#CDATA is a non-existing keyword. It is not possible to declare an element to be of type #CDATA.

The CDATA keyword (without #) has two distinct uses:

  1. In attribute declarations in DTDs.
  2. In CDATA sections, which occur in XML document instances only (cannot be declared in DTDs).

To be clear: it is not possible to declare an element as a "cdata/CDATA/#CDATA" type. A CDATA section (<![CDATA[...]]>) is a convenience for XML authors. It is simply used in an XML document if needed. It is not something that is declared in a DTD.

See also this answer: https://stackoverflow.com/a/12128273/407651.

Upvotes: 2

Related Questions