JDOM 对 ID 和 IDREF 有支持吗?

发布于 2024-07-23 17:48:46 字数 830 浏览 1 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒江雪… 2024-07-30 17:48:46

在这里我找到了一些可以回答您问题的内容。 据我了解,jDom 没有直接支持,但有 org.jdom.contrib.ids 包

提供对文档的支持
允许使用查找元素
它们的 ID 属性的值

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

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文