Question

<!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>

Est-ce que JDom a la capacité de faire quelque chose comme:

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
*/

Ou d'un autre établissement d'ID et IDREF ??

Était-ce utile?

La solution

J'ai trouvé quelque chose à répondre à votre question. Pour autant que je comprends, JDom ne dispose pas d'un soutien direct, mais il y a le paquet org.jdom.contrib.ids que

  

Fournit un soutien pour les documents   permettant la recherche des éléments à l'aide de la   valeur de leur attribut ID

Je trouve la bibliothèque (ce n'est pas l'emplacement principal, peut-être quelqu'un d'autre connaît l'URL du dépôt pour cette bibliothèque)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top