You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Greg Hess <gh...@wrappedapps.com> on 2003/01/14 22:26:03 UTC

Parsing DTD's with CDATA elements

Hi All,
 
I have build a data structure that contains an element of type CDATA.
When I parse the xml data I get the error org.xml.sax.SAXParseException:
A '(' character or an element type is required in the declaration of
element type "initData". Does anyone have any insight as to why my xml
cannot be validated by Xerces. It also displays fine when tested under
IE when I remove the # in #CDATA?
 
Many thanks,
 
Greg
 
 
<?xml version="1.0" encoding="UTF-8" ?> 
  <!DOCTYPE invocation (View Source for full doctype...)> 
 <http://localhost/instancemanager/testXML##> -     <invocation>
                <method>_import</method> 
                <id>1235768_69</id> 
                <typeName>sometype</typeName> 
 <http://localhost/instancemanager/testXML##> -           <initData>
-                    <![CDATA[ 
                 <some>init</someuuu>
              ]]> 
            </initData>
  </invocation>
 
   The data is validated with the following dtd:
 
   <?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT invocation (method,id,typeName,initData)>
<!ELEMENT method (#PCDATA)>
<!ELEMENT id (#PCDATA)>
<!ELEMENT typeName (#PCDATA)>
<!ELEMENT initData (#CDATA)> 
 
 
 

RE: Parsing DTD's with CDATA elements

Posted by Greg Hess <gh...@wrappedapps.com>.
I have changed my DTD as suggested and all is well :-).

Many Thanks,

Greg


-----Original Message-----
From: Joseph Kesselman [mailto:keshlam@us.ibm.com] 
Sent: Tuesday, January 14, 2003 4:59 PM
To: xerces-j-user@xml.apache.org
Subject: Re: Parsing DTD's with CDATA elements

This looks like the standard confusion between CDATA, #PCDATA, and 
<![CDATA[]]>

<![CDATA[]]> (a "CDATA Section") is actually a kind of #PCDATA content. 
It's just a syntactic convenience, as an alternative to escaping 
individual characters. It does not have to be specially declared in the 
DTD; just say that the element can contain #PCDATA and then use 
<![CDATA[]]> in your document, and everything should work properly.

#CDATA is the datatype used for *attributes* which contain unconstrained

text.  You can't define an element as containing #CDATA, and you don't 
have to do so.


Yes, the fact that CDATA means two different things, and is so similar
to 
PCDATA, is confusing. All I can say is that it makes sense to a parser 
developer. (It doesn't make us _happy_, but it does make sense.)

______________________________________
Joe Kesselman  / IBM Research


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Parsing DTD's with CDATA elements

Posted by Joseph Kesselman <ke...@us.ibm.com>.
This looks like the standard confusion between CDATA, #PCDATA, and 
<![CDATA[]]>

<![CDATA[]]> (a "CDATA Section") is actually a kind of #PCDATA content. 
It's just a syntactic convenience, as an alternative to escaping 
individual characters. It does not have to be specially declared in the 
DTD; just say that the element can contain #PCDATA and then use 
<![CDATA[]]> in your document, and everything should work properly.

#CDATA is the datatype used for *attributes* which contain unconstrained 
text.  You can't define an element as containing #CDATA, and you don't 
have to do so.


Yes, the fact that CDATA means two different things, and is so similar to 
PCDATA, is confusing. All I can say is that it makes sense to a parser 
developer. (It doesn't make us _happy_, but it does make sense.)

______________________________________
Joe Kesselman  / IBM Research


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org