INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

XML doctype does not work

XML doctype does not work

(OP)
Hi to all,
I have the following XML parsed with javascript.
I added a doctype - however the #PCDATA type of element SUMMARY does not work. (if I remove the '&' it works)
What am I doing wrong?

XML code:

CODE -->

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE catalog [
<!ELEMENT catalog (car)>
<!ELEMENT car (marc,model,summary)>
<!ELEMENT marc (#PCDATA)> 
<!ELEMENT model (#PCDATA)> 
<!ELEMENT summary (#PCDATA)> 
]>
      
<catalog>           
  <car>              
    <marc>Renault</marc>
	<model>Clio</model>
	 <motor>sample </motor>  
	<summary> sample </summary> 	     
  </car>          
  <car>             
    <marc>Audi</marc>             
    <model>A4</model>                
    <type>Break</type>                
    <motor>Diesel</motor>  
    <summary> this is a sample summary for no & </summary>       
</car>       
 </catalog> 

RE: XML doctype does not work

You can't have ampersands (&) in an open text node. You need to either escape them as entity &amp; or put the whole shebang in a CDATA block.

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: XML doctype does not work

(OP)
Hi MaketItSo,
thanks for the reply.
But I thought that this is what <!ELEMENT summary (#PCDATA)> did - so developers would not have to define a CDATA blocks in all instances of the same elements.
If not, what is the purpose of having it then?

K.

RE: XML doctype does not work

Hi K.

PCDATA means "parsed character data" while CDATA means "character data".
PCDATA simply means "I won't further specify the contents of this node, just treat it as a normal XML text node" while CDATA blocks may contain any kind of garbage whatsoever and must be written like this:

CODE

<![CDATA[&%<>]]> 
While PCData must be written like this:

CODE

&lt;some html &amp; + whatever&gt; 

See also:
http://en.wikipedia.org/wiki/PCDATA
and
http://en.wikipedia.org/wiki/CDATA

Cheers,
MakeItSo

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: XML doctype does not work

(OP)
ok I see, thanks a lot for the clarification!smile2
Would make great sense though if we could clarify CDATA at the DTD level (just once).

K.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close