[jdom-interest] Entity value lookup based on name?
Jason Long
jason at supernovasoftware.com
Wed Feb 26 05:59:01 PST 2003
Maybe what I am trying to do is weird. My problem is that I am getting data
from a legacy system that has no unique identifier for items in an
inventory. Their uniqueness is determined by a combination of 8 fields.
The client generates this data and upload it where I use jdom to group like
items, calculate totals,... Some of the fields are abbreviations that need
to be expanded for display. When I process the file I am adding these
fields as an entityref. By defining a dtd so that the expansion is done
when read by the xml processor. This lets the client add new entities when
their system changes, but modifying the dtd. This is causing me more
problems, because when I process an updated inventory I am trying to perform
lookup based on data which I have at hand, but this data has all of the
abbreviations in it, and the old file gets all the entities expanded on
parsing. I fixed this with the following function:
public Element convertTextToEntity(Element elt) {
try {
String text = elt.getTextTrim();
elt.setText(null);
elt.addContent(new EntityRef(text));
} catch (Exception e) {e.printStackTrace();};
return elt;
}
I run this over the document after it has been processed and get the results
I am looking for, but I keep thinking I should be doing this a different
way. All this funtion does is add the entities after the fact. I would
appreciate any advice.
Jason Long - CEO and Chief Software Engineer
Supernova Software - supernovasoftware.com
BS Physics, MS Chemical Engineering
-----Original Message-----
From: Robert (Jamie) Munro [mailto:rjmunro at arjam.net]
Sent: Wednesday, February 26, 2003 7:29 AM
To: Jason Long
Subject: RE: [jdom-interest] Entity value lookup based on name?
> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Jason Long
> Sent: 26 February 2003 08:16
> To: JDOM
> Subject: [jdom-interest] Entity value lookup based on name?
>
>
> Given a document with an external dtd, is there a way to look up the value
> based on the entity name? At the time of processing I am
> comparing two text
> node values. When read by jdom entities are expanded. At this
> point I only
> know the name of the entity, but not its value. Is there a list
> of entities
> stored somewhere in the jdom document that I can access by name?
As Elliot said, no, there isn't. Once the Document is in JDOM, all entities
have been normalised and completely forgotten about.
It sounds like you are attempting something weird. An entity IS a piece of
text. It's just that instead of being represented by certain characters,
it's being represented by others. The fact that it came from an entity, or
could be instead stored as an entity makes no difference. XML specs state
that you should not notice or care about the difference. Sometimes, it is
necessary to encode characters as an entity (<&> and when the character
doesn't exist in the current char set).
Robert Munro
More information about the jdom-interest
mailing list