Ricerca…


Sintassi

  1. All'interno di un nodo specifico:

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

  2. Ovunque nel documento:

    // * [name () = 'search string']

Parametri

funzione valore di ritorno
local-name () il nome del nodo senza prefisso

Osservazioni

il risultato nome-locale () non include prefisso (funzione lookup name () XPATH per esso)

Cerca nodi con nome come Luce, Dispositivo o Sensore

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

o

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

PRODUZIONE

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

Cerca nodi con nome che contiene Luce

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

o

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

PRODUZIONE

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

Cerca nodi con nomi che iniziano con 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")]

o

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

PRODUZIONE

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

Cerca i nodi che hanno un nome che termina con 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")]

o

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

PRODUZIONE

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

Cerca nodi con luce del nome (maiuscole / minuscole)

XML

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

XPATH

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

o

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

PRODUZIONE

<Light>sun</Light>


Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow