![](/img/trans.png)
[英]Java w3c dom getElementsByTagName does not return any node
[英]w3c Document xpath does not return nodeset
你好:) 我想要所有enumeration
节点,但集合的长度返回 0。将来我需要enumeration.value
属性列表,因此例如目前它将包含 WOW 的单元素列表。 但问题是我根本无法选择enumeration
节点。
xml部分:
<xs:complexType name="Code.Something">
<xs:complexContent>
<xs:restriction base="xxx:Code">
<xs:sequence>
<xs:element name="code" form="unqualified">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="WOW">
<xs:annotation>
<xs:appinfo>
<Test>ABC</Test>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
这有长度 1:
((NodeList) xPath.evaluate("//*[local-name()='complexType'][@name='Code.Something']",
doc, XPathConstants.NODESET)).getLength();
这有长度 0 - 为什么?:
((NodeList) xPath.evaluate("//*[local-name()='complexType'][@name='Code.Something']/*[local-name()='enumeration']",
doc, XPathConstants.NODESET)).getLength();
节点之间的单斜杠 ( node1/node2
) 表示您想要 select node2
,它是node1
的直接子节点。 您需要在节点 ( node1//node2
) 到 select node2
之间使用双斜杠//
,它是node1
的后代:
//*[local-name()='complexType'][@name='Code.Something']//*[local-name()='enumeration']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.