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>

JDom 是否有能力执行以下操作:

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

或任何其他与 ID 和 IDREF 相关的设施?

4

1 回答 1

2

在这里我找到了一些东西来回答你的问题。据我了解,jDom 没有直接支持,但有一个org.jdom.contrib.ids

提供对 Documents 的支持,允许使用其 ID 属性的值查找元素

我在这里找到了库(它不是主要位置,也许其他人知道该库的存储库 URL)

于 2009-06-08T18:08:59.147 回答