w3c 文档 xpath 没有 return 节点集

w3c Document xpath does not return nodeset

你好:)我想要所有 enumeration 个节点,但集合的长度 returns 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[=22 的直接子节点=].您需要在节点 (node1//node2) 到 select node2 之间使用双斜杠 // node1 的后代:

//*[local-name()='complexType'][@name='Code.Something']//*[local-name()='enumeration']