2014-02-21 90 views
0
<segmentFlightRef> 
    <referencingDetail> 
     <refQualifier>S</refQualifier> 
     <refNumber>4</refNumber> 
    </referencingDetail> 
    <referencingDetail> 
     <refQualifier>S</refQualifier> 
     <refNumber>1</refNumber> 
    </referencingDetail> 
</segmentFlightRef> 
<segmentFlightRef> 
    <referencingDetail> 
     <refQualifier>S</refQualifier> 
     <refNumber>5</refNumber> 
    </referencingDetail> 
    <referencingDetail> 
     <refQualifier>S</refQualifier> 
     <refNumber>1</refNumber> 
    </referencingDetail> 
</segmentFlightRef> 
    <segmentFlightRef> 
    <referencingDetail> 
     <refQualifier>S</refQualifier> 
     <refNumber>1</refNumber> 
    </referencingDetail> 
    <referencingDetail> 
     <refQualifier>S</refQualifier> 
     <refNumber>5</refNumber> 
    </referencingDetail> 
</segmentFlightRef> 

在上面的xml我想要「segmentFlightRef」標記的子節點「refNumber」具有值「5」和「1」。和順序必須考慮,所以我需要它的子節點值5和1 sequencially 請幫我 感謝事先只在一個節點使用xpath選擇特定的xnode

回答

0

的XPath:

//segmentFlightRef[referencingDetail[following-sibling::referencingDetail/refNumber = 1]/refNumber = 5] 
+0

thanx爲您的答案,但我編輯了我的問題。我只需要單個節點。請再次參考 –

+0

@BrijeshGandhi更新了我的答案。 – dirkk

+0

非常感謝您 –

1

的XPath

//segmentFlightRef[./referencingDetail[./refNumber[text()="5"] and ./following-sibling::referencingDetail[./refNumber[text()="1"]]]] 

說明

//segmentFlightRef[./referencingDetail[...]] 

選擇<segmentFlightRef>爲元素的子元素<referencingDetail>與標準如下:

標準我

./refNumber[text()="5"] 

有子元素<refNumber>與內部文本等於"5"

標準II

and ./following-sibling::referencingDetail[./refNumber[text()="1"]] 

,並與標準的下一個/同級節點<referencingDetail>:具有內部文本子元素<refNumber>等於"1"

+0

對於您的代碼段,有些事情是不必要的和/或令人困惑的。因爲您已經在正確的上下文中,因此不需要點構造'。/'。另外,你不必使用'text()',因爲它會被自動霧化(並且'text()'可以顯着減慢你的代碼的速度) – dirkk