2010-11-23 8 views
0

Une partie de mon xml-file:XPath récursive

<table> 
    <row id="aant"> 
     <radio id="radaant"> 
      <omschrijving>test radio</omschrijving> 
      <omschrijving>part 2</omschrijving> 
      <table> 
       <row id="testrow"> 
        <radio id="testrad"> 
         <omschrijving>test radio deeper</omschrijving> 
         <table/> 
        </radio> 
       </row> 
      </table> 
     </radio> 
    </row> 
</table> 

Je voudrais obtenir le "omschrijving" sous la radio tag avec id = "radaant". Depuis "omschrijving" est aussi plus profond chez l'enfant, je reçois toujours "test radiopart 2test radio plus profond" comme résultat, mais je veux juste "test radiopart 2".

Je suis actuellement en utilisant XPath: expr = xpath.compile ("/ table/rangée [@ id = 'Aant']/Radio [@ id = 'radaant']/omschrijving")

Comment est-ce que je peux changer ma chaîne de xpath pour obtenir seulement le "omschrijving" du noeud courant?

+0

Je ne peux pas reproduire votre problème: votre xpath sélectionne les deux éléments 'omschrijving' désirés –

Répondre

1

essayer expr = xpath.compile ("/ table/rangée [@ id = 'Aant']/Radio [@ id = 'radaant']/enfant :: omschrijving")

2

Vous parlez évidemment à propos d'un autre document XML ou d'une autre expression XPath.

Lorsqu'il est appliqué sur le document XML fourni:

<table> 
    <row id="aant"> 
    <radio id="radaant"> 
     <omschrijving>test radio</omschrijving> 
     <omschrijving>part 2</omschrijving> 
     <table> 
      <row id="testrow"> 
      <radio id="testrad"> 
       <omschrijving>test radio deeper</omschrijving> 
       <table/> 
      </radio> 
      </row> 
     </table> 
    </radio> 
    </row> 
</table> 

votre expression XPath:

/table/row[@id='aant']/radio[@id='radaant']/omschrijving 

sélectionne exactement les nœuds recherchés:

<omschrijving>test radio</omschrijving> 
<omschrijving>part 2</omschrijving> 
+0

J'étais en effet mal, mais je l'ai réparé maintenant. Ici, j'ai tapé [@ id = 'radaant'] mais dans mon code je ne l'ai pas rempli. Merci pour l'aide – Frederik