tags:

views:

110

answers:

1
<!DOCTYPE inventory [
<!ELEMENT book (title,author)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ATTLIST book year CDATA #IMPLIED>
<!ATTLIST book myId ID #REQUIRED>
<!ATTLIST book myIdRef IDREF #IMPLIED>
]>
<inventory>
    <book year="2000" myId="1">
        <title>Snow Crash</title>
        <author>Neal Stephenson</author>
    </book>
    <book myId="3" myIdRef="1"/>
</inventory>

Does JDom has ability to do something like:

Element root = doc.getRootElement();
List children = root.getChildren();
for(Object node:children){
  Element book = (Element) node;
  System.out.println(book.getAttributeValue("year")); 
}

/*
  So print:
    2000 
    2000
*/

Or any other facility related to ID and IDREF??

A: 

Here I found something to answer your question. As far as I understand, jDom does not have a direct support but there's the org.jdom.contrib.ids package that

Provides support for Documents allowing looking up elements using the value of their ID attribute

I found the library here (it's not the main location, maybe somebody else knows the repository URL for that library)

Andreas_D