DTD content to represent<![CDATA[..]]>

R

raga

Hi

When I have an element as
<book title ="xyz" author = "abc" >
<desc>
<![CDATA[Good book]]>
</desc>
</book

how exactly the DTD should look like.?

for the element desc which is child of book, I've tried

<!ELEMENT desc (#CDATA)>

my parser fails saying invalid element declaration.when i say

<!ELEMENT desc (CDATA)> i get one more error saying document structure
doesnt match the DTD?

could any one suggest the approriate dtd content for the same.

Thanks
 
B

Bjoern Hoehrmann

* raga wrote in comp.text.xml:
When I have an element as
<book title ="xyz" author = "abc" >
<desc>
<![CDATA[Good book]]>
</desc>
</book

how exactly the DTD should look like.?

It is neither good practise nor possible to encode a requirement to use
CDATA sections for some element in the DTD. You have to use #PCDATA and
let users decide whether to use CDATA sections.
 
R

raga

* raga wrote in comp.text.xml:
When I have an element as
<book title ="xyz" author = "abc" >
<desc>
<![CDATA[Good book]]>
</desc>
</book
how exactly the DTD should look like.?

It is neither good practise nor possible to encode a requirement to use
CDATA sections for some element in the DTD. You have to use #PCDATA and
let users decide whether to use CDATA sections.

Thanks for the reply.


at the same time,in the DTD for this element (desc) i was also
wondering why it wont allow me to use (#CDATA) and says invalid
element declaration
and when i use (CDATA) it says Document structure doenst match DTD.
and what exactly is the difference?

thanks again for your earlier reply.
 
R

Richard Tobin

raga said:
at the same time,in the DTD for this element (desc) i was also
wondering why it wont allow me to use (#CDATA) and says invalid
element declaration

Because XML doesn't have a way of declaring CDATA elements.
and when i use (CDATA) it says Document structure doenst match DTD.

That specifies an element whose name happens to be "CDATA".

-- Richard
 
J

Joe Kesselman

raga said:
wondering why it wont allow me to use (#CDATA) and says invalid
element declaration

#CDATA is not permitted for elements in XML; only #PCDATA. You may be
confusing XML DTDs and the SGML DTDs; XML originated as a simplification
of SGML, and SGML has many features XML does not share.
 
J

Joe Kesselman

raga said:
Hi

When I have an element as
<book title ="xyz" author = "abc" >
<desc>
<![CDATA[Good book]]>
</desc>
</book

how exactly the DTD should look like.?

That's #PCDATA. The fact that this user has chosen to use a <![CDATA[]]>
section rather than escaping individual characters -- neither of which
is necessary in this example! -- is strictly a syntactic detail, not
semantic, and as far as XML is concerned the two approaches are
completely equivalent. Most XML applications don't even attempt to
distinguish the two.

Declare the element as having text content. Then, if the instance
document's text contains characters XML has trouble with, do something
appropriate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,248
Latest member
MagdalenaB

Latest Threads

Top