Sök…


Syntax

  1. Inuti en specifik nod:

    {path-to-parent} / name () = 'söksträng']

  2. Överallt i dokumentet:

    // * [name () = 'söksträng']

parametrar

fungera returvärde
lokal-namn () nodens namn utan prefix

Anmärkningar

local-name () -resultat inkluderar inte prefix (uppslagningsnamn () XPATH-funktion för det)

Sök efter noder med namn som ljus, enhet eller 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']

eller

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

PRODUKTION

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

Sök efter noder som har namn som innehåller ljus

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")]

eller

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

PRODUKTION

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

Sök efter noder som har namn som börjar med 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")]

eller

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

PRODUKTION

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

Sök efter noder som har namn som slutar med 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")]

eller

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

PRODUKTION

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

Sök efter noder med namnlampa (okänslig för versaler)

XML

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

XPATH

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

eller

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

PRODUKTION

<Light>sun</Light>


Modified text is an extract of the original Stack Overflow Documentation
Licensierat under CC BY-SA 3.0
Inte anslutet till Stack Overflow