[jdom-interest] org.jdom.contrib.ids?
Alfredo Aldundi
cheesy.ch at gmx.net
Wed Apr 2 13:43:20 PST 2003
>
>> I've just downloaded jdom-contrib and tried to use the
>> org.jdom.contrib.ids contribution. However, with the supplied test
>> program TestIds it does not work. I call:
>> > java TestIds testIds.xml a
>> but TestIds reports that this id does not exist (however, it is
>> clearly in the testIds.xml file...). By the way, TestIds does not
>> find a single id in the document...
>> I tried to find out the attribute type of the name attribute. I found
>> out that the type is 0 (=UNDECLARED_ATTRIBUTE) and not 2
>> (=ID_ATTRIBUTE) as it should be. The name attribute is clearly
>> defined as type ID in the DTD. So I guess that this is not a problem
>> of org.jdom.contrib.ids (correct?). May it be that my XML parser does
>> not handle this correctly?
>
> Normally, a parser is required to parse any DTD declared in the
> document to resolve entities and, by loading the DTD, knows the type
> of each attribute.
> If your parser doesn't do, try forcing document validation in
> TestIds.java by using:
> SAXBuilder builder = new SAXBuilder(true);
>
Your suggestion did actually solve the problem with
UNDECLARED_ATTRIBUTE type, but getElementById does still not find an
element by id. I've tracked the problem to the setAttribute method in
IdElement.java (revision 1.1). On line 137 it reads:
Document doc = this.getDocument();
A diagnostic output just after this line reveals that doc is null. In
the next line the id is not added to the document!!! It is kind of
strange that if I write getDocument in TestIds.java the document is not
null (for an arbitrary element in the jdom). If I do a manual
addAttribute(new Attribute("name", "a", Attribute.ID_ATTRIBUTE)) it
works also.
Has anybody experienced similar problems? Is it caused by the
SAXParser? Why is there a difference between the SAXBuilder case and
the manual addAttribute? Or better, why is getDocument() == null in
setAttribute(Attribute) of IdElement.java when the builder is building
the jdom?
Any help is appreciated! Thanks!
Alfredo
More information about the jdom-interest
mailing list