Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] entity in attribute value

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Luca Passani <passani AT eunet.no>
  • To: 'xom-interest' <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] entity in attribute value
  • Date: Wed, 14 Jan 2009 01:22:36 +0100


I think we agree. The problem was my misunderstanding/ignorance of how parser works. For some reason which I never quite understood, XML keeps surprising me after all these years. Not referring to this case specifically, but every time I think I have understood the XML basics, something weird will come up and show me that I had not understood properly. Not really the "simple" standard it was supposed to be, but I don't want to digress, since it was my error.

Thanks

Luca

Benson Margulies wrote:
Luca,
Nothing in the XML standard has changed since 2002. The XML standard always
stated very clearly how entities work. The fact that XML parsers have become
progressively more capable of implementing the standard is another story.

The rule is really simple. If you want to put a string into XML, you have to
escape & and < as &amp; and &lt; In PCDATA, you can use CDATA. In attribute
values, it's the &-entities, period.

Plain old XML doesn't know what &euro; is unless you tell it so with an
entity definition. If your data has &euro; in it (perhaps it's HTML you are
carting around in XML) then, sure enough, &amp;euro; is what you would write
in the xml file. And out of a parser API will come "&euro;".



On 1/13/09 6:49 PM, "Luca Passani" <passani AT eunet.no> wrote:

Michael Kay wrote:
You can write it as &amp;euro; if you really want to. But why on earth would
you want to use something that looks just like an entity reference but isn't
one?
because, in this framework (WURFL), an XML file is the core of a simple
DB to store strings. Usually those strings are not entities, but
yesterday I happened to need to store a string which looked identical to
an XML entity.

Every technology sucks if you misuse it.
what should I have done in 2002 when I started the project? decide that
XML was not good for me because maybe one day this XML file may have to
contain a string which could be confused with an XML entity?


I've got a brand new digital camera
and it's no good at hammering nails. Perhaps the problem is with the user,
not with the technology?
WURFL is a very successful project in its field. Thousands of developers
around the planet have been able to download it and use it out of the
box without much trouble. Anyway, the problem is solved. I now know how
to escape those "things". I always knew that &amp; escapes &, but for
some reason I was assuming that the XML parser would return "&amp;euro;"
as "&amp;euro;" (and not as "&euro;" which is what I want).
Please observe that declaring the entity is not possible, because the
WURFL model is such that a developer can throw any kind of property
inside WURFL without changing anything else, and legitimately expect to
find it at a later stage.

Thank you for your interest in the problem.

Luca








Archive powered by MHonArc 2.6.24.

Top of Page