[jdom-interest] Question about jdom-contrib IdFactory

Laurent Bihanic laurent.bihanic at atosorigin.com
Wed May 5 08:15:42 PDT 2004


I just saw your message. Hoping it's not too late...

"ID" attributes are related to DTDs. To use the IdFactory class, your 
documents need to be associated to a DTD that defines some attributes as of 
type ID (ID attributes require each value to be unique throughout the document).

Once this is done, the XML parser notifies JDOM of the attribute type in the 
DTD. If it is of type "ID", the IdFactory adds its value to a specific 
document-wide table to enable direct element access using Document.getElementById.

If you are building your documents programmatically, you don't need a DTD, you 
can use the IdDocument and IdElement objects directly and create Attributes 
using a constructor that supports an attribute type as argument (setting the 
type to Attribute.ID_TYPE).

Hope this helps,


Martin Pöpping wrote:

> Hello,
> I´ve a question about the jdom-contrib IdFactory class.
> I want to add an ID to every element in my xml-file so I think that this 
> class could be my solution.
> My problem is now, that I cannot find any method like Element.getID() to 
> get the ID of an element.
> Well there is a method DocumentId.getElementById(String id)... but how 
> can I get this element
> if I do not know which Ids I am using?
> Thanks a lot for help,
> bye,
> Martin
> PS: The task I wam trying to do at the moment, is reading in an XML file 
> and adding
> the attributed "id" and "status" to every single element. Are there  
> maybe other classes in
> the jdom-packages which cold help me?

More information about the jdom-interest mailing list