xpath                
            Obtener nodos en relación con el nodo actual
        
        
            
    Buscar..
Sintaxis
-  Todos los ancestros de un nodo. 
- / ruta al nodo / ancestor :: node ()
 
 -  Un ancestro específico de un nodo. 
- / ruta al nodo / ancestor :: ancestor_name
 
 -  Padre de un nodo 
- / ruta al nodo / padre :: nodo ()
 
 -  Siguiendo a los hermanos de un nodo 
- / ruta al nodo / following-sibling :: node ()
 
 -  Un hermano específico que sigue un nodo. 
- / ruta al nodo / following-sibling :: sibling_name
 
 -  Hermanos anteriores de un nodo 
- / ruta al nodo / preced-sibling :: node ()
 
 -  Un hermano específico que precede a un nodo. 
- / ruta al nodo / preced-sibling :: sibling_name
 
 -  Todos los nodos hijos inmediatos de un nodo. 
- / ruta al nodo / child :: node ()
 
 -  Un nodo secundario inmediato específico de un nodo 
- / ruta al nodo / child :: chid_name
 
 -  Todos los descendientes de un nodo. 
- / ruta al nodo / descendant :: node ()
 
 -  Todos los descendientes específicos de un nodo. 
- / ruta al nodo / descendant :: descendant_name
 
 
Parámetros
| Eje | selecciona | 
|---|---|
| antepasado | todos los nodos ancestros | 
| padre | nodo padre | 
| siguiente hermano | hermanos siguiendo el nodo | 
| hermano precedente | hermanos que preceden al nodo | 
| niño | niños inmediatos | 
| descendiente | Todo el descendiente independientemente del nivel de anidación. | 
Observaciones
Estos ejes se pueden utilizar en combinación con otras funciones para satisfacer nuestras necesidades.
Encontrar mis ancestros
XML
<GrandFather name="Bardock" gender="male" spouse="Gine">
    <Dad name="Goku" gender="male" spouse="Chi Chi">
        <Me name="Gohan" gender="male"/>
        <brother name="Goten" gender="male"/>
    </Dad>
</GrandFather>
 XPATH
//Me/ancestor::node()
 SALIDA
<GrandFather name="Bardock" gender="male" spouse="Gine">
  <Dad name="Goku" gender="male" spouse="Chi Chi">
    <Me name="Gohan" gender="male" />
    <brother name="Goten" gender="male" />
  </Dad>
</GrandFather>
<Dad name="Goku" gender="male" spouse="Chi Chi">
  <Me name="Gohan" gender="male" />
  <brother name="Goten" gender="male" />
</Dad>
        Encontrar a mi padre
XML
<GrandFather name="Bardock" gender="male" spouse="Gine">
    <Dad name="Goku" gender="male" spouse="Chi Chi">
        <Me name="Gohan" gender="male"/>
        <brother name="Goten" gender="male"/>
    </Dad>
</GrandFather>
 XPATH
//Me/ancestor::Dad
 o
//Me/parent::node()
 SALIDA
<Dad name="Goku" gender="male" spouse="Chi Chi">
  <Me name="Gohan" gender="male" />
  <brother name="Goten" gender="male" />
</Dad>
        Encuentra a mi abuelo
XML
<GrandFather name="Bardock" gender="male" spouse="Gine">
  <Dad name="Goku" gender="male" spouse="Chi Chi">
    <Me name="Gohan" gender="male" />
    <brother name="Goten" gender="male" />
  </Dad>
</GrandFather>
 XPATH
//Me/ancestor::GrandFather
 o
//Me/parent::node()/parent::node()
 SALIDA
<GrandFather name="Bardock" gender="male" spouse="Gine">
  <Dad name="Goku" gender="male" spouse="Chi Chi">
    <Me name="Gohan" gender="male" />
    <brother name="Goten" gender="male" />
  </Dad>
</GrandFather>
        Encontrar a mi hermano
XML
<GrandFather name="Bardock" gender="male" spouse="Gine">
  <Dad name="Goku" gender="male" spouse="Chi Chi">
    <brother name="Goten" gender="male" />
    <Me name="Gohan" gender="male" />
    <brother name="Goten" gender="male" />
  </Dad>
</GrandFather>
 XPATH
//Me/following-sibling::brother
 SALIDA
<brother name="Goten" gender="male" />
        Consigue todos los avatares antes de Parashurama.
XML
<Dashavatar>
    <Avatar name="Matsya"/>
    <Avatar name="Kurma"/>
    <Avatar name="Varaha"/>
    <Avatar name="Narasimha"/>
    <Avatar name="Vamana"/>
    <Avatar name="Balabhadra"/>
    <Avatar name="Parashurama"/>
    <Avatar name="Rama"/>
    <Avatar name="Krishna"/>
    <Avatar name="Kalki"/>
</Dashavatar>
 XPATH
//Avatar[@name='Parashurama']/preceding-sibling::node()
 SALIDA
<Avatar name="Matsya"/>
<Avatar name="Kurma"/>
<Avatar name="Varaha"/>
<Avatar name="Narasimha"/>
<Avatar name="Vamana"/>
<Avatar name="Balabhadra"/>
        Consigue todos los avatares después de Parashurama.
XML
<Dashavatar>
    <Avatar name="Matsya"/>
    <Avatar name="Kurma"/>
    <Avatar name="Varaha"/>
    <Avatar name="Narasimha"/>
    <Avatar name="Vamana"/>
    <Avatar name="Balabhadra"/>
    <Avatar name="Parashurama"/>
    <Avatar name="Rama"/>
    <Avatar name="Krishna"/>
    <Avatar name="Kalki"/>
</Dashavatar>
 XPATH
//Avatar[@name='Parashurama']/following-sibling::node()
 SALIDA
<Avatar name="Rama" />
<Avatar name="Krishna" />
<Avatar name="Kalki" />
        Consigue todos los avatares excepto el actual (Parusharama)
XML
<Dashavatar>
    <Avatar name="Matsya"/>
    <Avatar name="Kurma"/>
    <Avatar name="Varaha"/>
    <Avatar name="Narasimha"/>
    <Avatar name="Vamana"/>
    <Avatar name="Balabhadra"/>
    <Avatar name="Parashurama"/>
    <Avatar name="Rama"/>
    <Avatar name="Krishna"/>
    <Avatar name="Kalki"/>
</Dashavatar>
 XPATH
//Avatar[@name='Parashurama']/following-sibling::Avatar | //Avatar[@name='Parashurama']/preceding-sibling::Avatar
 SALIDA
<Avatar name="Matsya" />
<Avatar name="Kurma" />
<Avatar name="Varaha" />
<Avatar name="Narasimha" />
<Avatar name="Vamana" />
<Avatar name="Balabhadra" />
<Avatar name="Rama" />
<Avatar name="Krishna" />
<Avatar name="Kalki" />
        Consigue todos los detalles (nodos hijos) de la casa.
XML
<House>
    <Rooms>10</Rooms>
    <People>4</People>
    <TVs>4</TVs>
    <Floors>2</Floors>
</House>
 XPATH
/House/child::node()
 SALIDA
<Rooms>10</Rooms>
<People>4</People>
<TVs>4</TVs>
<Floors>2</Floors>
        Obtener todas las habitaciones (niños inmediatos nombradas habitación) en casa
XML
<House>
    <numRooms>4</numRooms>
    <Room name="living"/>
    <Room name="master bedroom"/>
    <Room name="kids' bedroom"/>
    <Room name="kitchen"/>
</House>
 XPATH
/House/child::Room
 o
/House/*[local-name()='Room']
 SALIDA
<Room name="living" />
<Room name="master bedroom" />
<Room name="kids' bedroom" />
<Room name="kitchen" />
        Obtener todas las habitaciones (independientemente de la posición) en casa
XML
<House>
    <numRooms>4</numRooms>
    <Floor number="1">
        <Room name="living"/>
        <Room name="kitchen"/>
    </Floor>
    <Floor number="2">
        <Room name="master bedroom"/>
        <Room name="kids' bedroom"/>    
    </Floor>
</House>
 XPATH
/House/descendant::Room
 SALIDA
<Room name="living" />
<Room name="kitchen" />
<Room name="master bedroom" />
<Room name="kids' bedroom" />
    
    
    
    
    Modified text is an extract of the original Stack Overflow Documentation
        Licenciado bajo CC BY-SA 3.0
        No afiliado a Stack Overflow