Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > entities in attribute values

Reply
Thread Tools

entities in attribute values

 
 
luca
Guest
Posts: n/a
 
      01-12-2009
Hi, I just figured that XML is touchy about using entities in attribute
value even for super-simple XML files with no DTD:

<elem name="entity_euro" value="&euro;"/>

Caused by: org.xml.sax.SAXParseException: The entity "euro" was
referenced, but
not declared.
at
org.apache.xerces.parsers.AbstractSAXParser.parse( AbstractSAXParser.java:1189)


is there a standard way to escape entities in XML?

Thanks
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      01-12-2009
luca wrote:
> Hi, I just figured that XML is touchy about using entities in attribute
> value even for super-simple XML files with no DTD:
>
> <elem name="entity_euro" value="&euro;"/>
>
> Caused by: org.xml.sax.SAXParseException: The entity "euro" was
> referenced, but
> not declared.
> at
> org.apache.xerces.parsers.AbstractSAXParser.parse( AbstractSAXParser.java:1189)
>
>
>
> is there a standard way to escape entities in XML?


You need a DTD that declares the entity named 'euro'.
Or you need to use a numeric character reference e.g.


And that has nothing to do with whether you use the entity reference in
an attribute or in an element, that does not matter. You need to declare
any entity you want to reference, with the exception of 'lt', 'gt',
'quot', 'apos', 'amp'.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
luca
Guest
Posts: n/a
 
      01-12-2009
Martin Honnen wrote:
>
> You need a DTD that declares the entity named 'euro'.
> Or you need to use a numeric character reference e.g.
> €
>
> And that has nothing to do with whether you use the entity reference in
> an attribute or in an element, that does not matter. You need to declare
> any entity you want to reference, with the exception of 'lt', 'gt',
> 'quot', 'apos', 'amp'.


so, here is my problem. I use this XML file simply to hold configuration info.
One of the strings I need to store in the config file is "&euro;" which,
unfortunately, happens to be an XML entity and have special meaning for XML and
XML parsers.

I tried:

<elem name="entity_euro" value="<![CDATA[&euro;]]>"/>

but it does not work.

I can work this around outside of XML by using a different expression and having
Java re-build the entity string:

<elem name="entity_euro" value="amp_euro;"/>

before I do it, though, I would like to hear whether there is a better (and more
elegant!) way, because my heart cries when I see XML suck so bad.

Luca
 
Reply With Quote
 
luca
Guest
Posts: n/a
 
      01-12-2009
luca wrote:
> Hi, I just figured that XML is touchy about using entities in attribute
> value even for super-simple XML files with no DTD:
>
> <elem name="entity_euro" value="&euro;"/>
>
> Caused by: org.xml.sax.SAXParseException: The entity "euro" was
> referenced, but
> not declared.
> at
> org.apache.xerces.parsers.AbstractSAXParser.parse( AbstractSAXParser.java:1189)
>
>
>
> is there a standard way to escape entities in XML?



This did the trick:

<elem name="entity_euro" value="&amp;euro;"/>

Thanks

Luca
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JNDI: Delete only one attribute when there are several different values for the same attribute bsporb@gmail.com Java 3 05-02-2007 05:41 AM
picking value of one attribute based on a child elements attribute? XPath? vjethava@gmail.com XML 2 03-06-2006 05:19 AM
XSLT: Making attribute to parent attribute Bostonasian XML 1 09-18-2005 07:30 AM
Questions about sending 'transaction attribute behavior across entities. R Paley VHDL 2 11-20-2004 02:37 PM
HTML::Entities::encode() returning wrong(?) entities Jim Higson Perl Misc 3 07-25-2004 09:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57