簡體   English   中英

XPath遞歸

[英]XPath recursive

我的xml文件的一部分:

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

我想從帶有id =“ radaant”的單選標簽下獲取“ omschrijving”。 因為“ omschrijving”在孩子中也更深,所以我總是得到“ test radiopart 2test radio deeper”的結果,但是我只想“ test radiopart 2”。

我當前正在使用xpath:expr = xpath.compile(“ / table / row [@ id ='aant'] / radio [@ id ='radaant'] / omschrijving”)

如何更改xpath字符串以僅從當前節點獲取“ omschrijving”?

您顯然在談論另一個XML文檔或另一個XPath表達式

當應用於提供的XML文檔時

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

您的XPath表達式

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

精確選擇所需的節點

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

嘗試expr = xpath.compile(“ / table / row [@ id ='aant'] / radio [@ id ='radaant'] / child :: omschrijving”)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM