Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML doctype does not work 1

Status
Not open for further replies.

katpal

Instructor
Jun 30, 2012
3
CY
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>
 
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.
 
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.
 
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:
[b]<![CDATA[[/b]&%<>[b]]]>[/b]
While PCData must be written like this:
Code:
&lt;some html &amp; + whatever&gt;

See also:
and

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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top