RE: [xsl] DTD Element problem

Subject: RE: [xsl] DTD Element problem
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Thu, 6 Nov 2003 11:42:48 -0500
[ Flemming Jønsson]
> 
> I have some xml files containing source code (or SQL queries) 
> inside a particular tag.
> 
> In my DTD I wanted to define the element SQL to contain 
> #CDATA, but this is not allowed.
> 
> <!ELEMENT SQL (#CDATA)> is illegal,  <!ELEMENT SQL (#PCDATA)> 
> is legal.
> 
> In my XML files I have <![CDATA[{SQL_HERE}]> around my SQL 
> queries - which works fine, when SQL is defined as PCDATA in the DTD.
> 
> Is there another way I can define SQL to be CDATA instead of 
> PCDATA in the DTD? 
> It seems a bit redundant to define SQL as PCDATA in the DTD 
> and then explicitly define the contents of the SQL tag to be 
> CDATA in the XML file.
> 

You misunderstand what CDATA and PCDATA are, but you have ended up doing the right thing.

#PCDATA means that the element can have character content (i.e., character as opposed to element content).  That is what you want.  A CDATA section is a way to tell the processor that characters that _look_ like markup are really text, not markup.

Therefore, there is no need to "declare" a CDATA section in the DTD - even if it were allowed - because CDATA sections ARE character content.  By the time that your xml data is seen by the xslt processor, it is just characters anyway - the fact that it was originally in a CDATA section is not known by the xslt processor.

You can avoid the use of a CDATA section by escaping any of the special characters that happen to be in there, like "<", but it really does not matter one way or the other so far as later proessing is concerned.

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread