IdFactory
extends the default JDOM factory to build documents that support looking up elements using their ID attribute. Looking-up elements by ID only works if a DTD is associated to the XML document as the information defining some attributes as IDs is only available from the DTD and not from the XML document itself.
The Documents created by this factory are instances of {@link IdDocument} which provides the method{@link IdDocument#getElementById} to look up an element given thevalue of its ID attribute.
The following code snippet demonstrates how to use the IdFactory
with JDOM's SAXBuilder to create an IdDocument
.
@author Laurent BihanicSAXBuilder builder = new SAXBuilder(); builder.setFactory(new IdFactory()); IdDocument doc = (IdDocument)(builder.build(xmlDocument)); Element elt = doc.getElementById(idValue);
|
|