Zoeken…


Syntaxis

  1. Binnen een specifiek knooppunt:

    {path-to-parent} / name () = 'zoekreeks']

  2. Overal in het document:

    // * [name () = 'zoekreeks']

parameters

functie winstwaarde
local-name () de naam van het knooppunt zonder voorvoegsel

Opmerkingen

local-name () resultaat bevat geen prefix (lookup name () XPATH-functie ervoor)

Zoek naar knooppunten met de naam Licht, Apparaat of Sensor

XML

<Galaxy>
    <Light>sun</Light>
    <Device>satellite</Device>
    <Sensor>human</Sensor>
    <Name>Milky Way</Name>
</Galaxy>

XPATH

/Galaxy/*[local-name()='Light' or local-name()='Device' or local-name()='Sensor']

of

//*[local-name()='Light' or local-name()='Device' or local-name()='Sensor']

OUTPUT

<Light>sun</Light>
<Device>satellite</Device>
<Sensor>human</Sensor>

Zoek naar knooppunten met de naam Light

XML

<Data>
    <BioLight>
        <name>Firefly</name>
        <model>Insect</model>
    </BioLight>
    <ArtificialLight>
        <name>Fire</name>
        <model>Natural element</model>
        <source>flint</source>
    </ArtificialLight>
    <SolarLight>
        <name>Sun</name>
        <model>Star</model>
        <source>helium</source>
    </SolarLight>
</Data>

XPATH

/Data/*[contains(local-name(),"Light")]

of

//*[contains(local-name(),"Light")]

OUTPUT

<BioLight>
  <name>Firefly</name>
  <model>Insect</model>
</BioLight>
<ArtificialLight>
  <name>Fire</name>
  <model>Natural element</model>
  <source>flint</source>
</ArtificialLight>
<SolarLight>
  <name>Sun</name>
  <model>Star</model>
  <source>helium</source>
</SolarLight>

Zoek naar knooppunten met een naam die begint met Star

XML

<College>
    <FootBall>
        <Members>20</Members>
        <Coach>Archie Theron</Coach>
        <Name>Wild cats</Name>
        <StarFootballer>David Perry</StarFootballer>
    </FootBall>
    <Academics>
        <Members>100</Members>
        <Teacher>Tim Jose</Teacher>
        <Class>VII</Class>
        <StarPerformer>Lindsay Rowen</StarPerformer>
    </Academics>
</College>

XPATH

/College/*/*[starts-with(local-name(),"Star")]

of

//*[starts-with(local-name(),"Star")]

OUTPUT

<StarFootballer>David Perry</StarFootballer>
<StarPerformer>Lindsay Rowen</StarPerformer>

Zoek naar knooppunten met een naam die eindigt op Ball

XML

<College>
    <FootBall>
        <Members>20</Members>
        <Coach>Archie Theron</Coach>
        <Name>Wild cats</Name>
        <StarPlayer>David Perry</StarPlayer>
    </FootBall>
    <VolleyBall>
        <Members>24</Members>
        <Coach>Tim Jose</Coach>
        <Name>Avengers</Name>
        <StarPlayer>Lindsay Rowen</StarPlayer>
    </VolleyBall>
    <FoosBall>
        <Members>22</Members>
        <Coach>Rahul Mehra</Coach>
        <Name>Playerz</Name>
        <StarPlayer>Amanda Ren</StarPlayer>
    </FoosBall>
</College>

XPATH

/College/*[ends-with(local-name(),"Ball")]

of

//*[ends-with(local-name(),"Ball")]

OUTPUT

<FootBall>
  <Members>20</Members>
  <Coach>Archie Theron</Coach>
  <Name>Wild cats</Name>
  <StarPlayer>David Perry</StarPlayer>
</FootBall>
<VolleyBall>
  <Members>24</Members>
  <Coach>Tim Jose</Coach>
  <Name>Avengers</Name>
  <StarPlayer>Lindsay Rowen</StarPlayer>
</VolleyBall>
<FoosBall>
  <Members>22</Members>
  <Coach>Rahul Mehra</Coach>
  <Name>Playerz</Name>
  <StarPlayer>Amanda Ren</StarPlayer>
</FoosBall>

Zoeken naar knooppunten met naamlicht (niet hoofdlettergevoelig)

XML

<Galaxy>
    <Light>sun</Light>
    <Device>satellite</Device>
    <Sensor>human</Sensor>
    <Name>Milky Way</Name>
</Galaxy>

XPATH

/Galaxy/*[lower-case(local-name())="light"]

of

//*[lower-case(local-name())="light"]

OUTPUT

<Light>sun</Light>


Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow