OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Entity replacements within attributes for CDATA

[ Lists Home | Date Index | Thread Index ]

Cabbar Duzayak wrote:

> I have an XML which is similar to:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE TestData [<!ENTITY var1
> '<![CDATA[testvalue]]>'>]>
> <TestData>
>   <Holder>
>     <MyText
> target="http://www.yahoo.com?aa=&var1;";>Text
> Source</MyText>
>   </Holder>
> </TestData>
> 
> When I try to parse this, I am getting an exception: 
> '<' cannot appear in attribute value.
> 
> Looks like parser replaces &var1; with
> "<![CDATA[testvalue]]>", 

As expected.

and since attribute values
> can not have "<" in them, this xml can not be parsed.
> And the problem goes away if I replace the entity
> definition with:
> 
> <!DOCTYPE TestData [<!ENTITY var1 'testvalue'>]>
> 
> However, I have to use CDATA here, 

But you **cannot** use a CDATA section in an attribute value.  A CDATA 
section, legal only in element content, simply signals to the processor 
that characters otherwise considered to be markup are to be treated as 
text.  A CDATA section does not do any escaping.

An entity, however, is a substitution macro, and effectively sticks 
characters into the source.  Wrapping them with a CDATA section doe snot 
escape anything.

>cause I don't know
> what the value of "var1" can be at runtime, and it
> might contain quote characters or any other special
> characters and it will be hard to deal with various
> cases if I don't use CDATA...

Too bad, you have to escape the data before the processor sees it.

Cheers,

Tom P




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS