<!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 相关的设施?

有帮助吗?

解决方案

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

为文档提供支持,允许使用其ID属性的值查找元素

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top