gpt4 book ai didi

java - 使用java从XML中查找重复的实体标签

转载 作者:数据小太阳 更新时间:2023-10-29 02:35:21 25 4
gpt4 key购买 nike

在 XML 文件中声明了一些实体

对于表达式:

<?xml version="1.0" encoding="utf-8"?>
<!--Arbortext, Inc., 1988-2004, v.4002-->
<!DOCTYPE test PUBLIC "-//Atul//DTD ATM - TEST//EN//-"
"test.dtd" [
<!ENTITY ent1 SYSTEM "Graphic/test1.txt" NDATA ccitt4>
<!ENTITY ent1 SYSTEM "Graphic/test1.txt" NDATA ccitt4>
<!ENTITY ent2 SYSTEM "Graphic/test2.txt" NDATA ccitt4>
<!ENTITY ent3 SYSTEM "Graphic/test4.txt" NDATA ccitt4>
]>
<test id="01" >
</test>

我必须发现 ent1 被声明了不止一次。

目前我们正在使用 getEntities 方法

  NamedNodeMap entities = lJDocumentXML.getDoctype().getEntities();

http://docs.oracle.com/javase/7/docs/api/org/w3c/dom/DocumentType.html#getEntities()

它不返回重复的实体(它只返回 ent1、ent2 和 ent3)和外部实体(如果在引用的 dtd 中有的话)

有没有办法得到所有的四个实体?

谢谢 阿图尔

最佳答案

接口(interface)定义的“DocumentType”丢弃属性“entities”和“notations”(参见 W3C DOM 规范。W3C SPEC - REC-DOM-Level-3-Core)

A NamedNodeMap containing the general entities, both external and internal, declared in the DTD. Parameter entities are not contained. Duplicates are discarded. For example in:

<!DOCTYPE ex SYSTEM "ex.dtd" [
<!ENTITY foo "foo">
<!ENTITY bar "bar">
<!ENTITY bar "bar2">
<!ENTITY % baz "baz">
]>
<ex/>

the interface provides access to foo and the first declaration of bar but not the second declaration of bar or baz. Every node in this map also implements the Entity interface. The DOM Level 2 does not support editing entities, therefore entities cannot be altered in any way.

我认为您需要使用另一种方法来解析/检查此信息...例如您可以使用正则表达式。

关于java - 使用java从XML中查找重复的实体标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22863534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com