2010-11-23 25 views
0

Ein Teil meiner xml-Datei:XPath rekursive

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

Ich mag das "omschrijving", um unter dem Tag Radio mit id = "radaant". Da "omschrijving" auch tiefer im Kind ist, bekomme ich immer "test radiopart 2test radio timer" als Ergebnis, aber ich will nur "test radiopart 2".

Ich bin derzeit mit XPath: ausdr = xpath.compile ("/ Tabelle/Zeile [@ id = 'aant']/Radio [@ id = 'radaant']/omschrijving")

Wie Kann ich meine X-Pfad-Zeichenfolge ändern, um nur das "omschrijving" vom aktuellen Knoten zu erhalten?

+0

Ich kann Ihr Problem nicht reproduzieren: Ihr xpath wählt die gewünschten zwei 'omschrijving' Elemente –

Antwort

1

Versuch ausdr = xpath.compile ("/ Tabelle/Zeile [@ id = 'aant']/Radio [@ id = 'radaant']/child :: omschrijving")

2

Sie offensichtlich sprechen über ein anderes XML-Dokument oder einen anderen XPath-Ausdruck.

Wenn auf der mitgelieferten XML-Dokument angewendet:

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

Ihre XPath-Ausdruck:

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

wählt genau die gewünschten Knoten:

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

Ich war in der Tat falsch, aber ich habe es jetzt behoben. Hier habe ich [@ id = 'radaant'] getippt, aber in meinem Code habe ich es nicht ausgefüllt. Danke für die Hilfe – Frederik