Home > front end >  w3c Document xpath does not return nodeset
w3c Document xpath does not return nodeset

Time:03-26

Hello :) I want to have all enumeration nodes but length of the collection returns 0. In future I would need List of enumeration.value attributes, so for example currently it would one-element list with WOW inside. But the problem is that I cannot pick enumeration nodes at all.

The xml part:

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

This has length 1:

((NodeList) xPath.evaluate("//*[local-name()='complexType'][@name='Code.Something']",
        doc, XPathConstants.NODESET)).getLength(); 

This has length 0 - why ?:

 ((NodeList) xPath.evaluate("//*[local-name()='complexType'][@name='Code.Something']/*[local-name()='enumeration']",
        doc, XPathConstants.NODESET)).getLength(); 

CodePudding user response:

Single slash between nodes (node1/node2) means that you want to select node2 that is the direct child of node1. You need to use double slash // between nodes (node1//node2) to select node2 that is descendant of node1:

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