![](/img/trans.png)
[英]XML subtrees - select specified child nodes only, but along with parent node
[英]Retrieving parent nodes of a specified empty child node
我試圖使用XPATH以XML形式返回子節點的父節點,而XML在PL / SQL過程中不包含任何內容。
到目前為止,我具有以下XMLextract,它將返回ID為10或11的子節點的包裝父級,其中p_xml_content是我的xml文檔。
xmltype(p_xml_content).extract('//return/issueEventType[id=11] /../. | //return/issueEventType[id=10] /../.')
我需要轉換此語句以返回包含一個空的completedDate節點的所有返回標記。
我按照這種思路思考,但不確定是否可行:
xmltype(p_xml_content).extract('//return[completionDate=''] /../.')
有任何想法嗎?
干杯
耶齊賓
假設“空的commentationDate節點”的意思是“沒有子節點的completionDate元素”,它將轉換為completionDate[not(node())]
因此,“所有包含空的completionDate節點的返回標簽”將轉換為
//return[completionDate[not(node())]]
因此,請嘗試:
xmltype(p_xml_content).extract('//return[completionDate[not(node())]]')
稍作修改的表達式//return[completionDate=""]
也可以使用。
帶有以下示例XML
<sample>
<return id="1">
<completionDate></completionDate>
<otherData>some data</otherData>
</return>
<return id="2">
<completionDate>2013-09-10</completionDate>
</return>
<return id="3">
<completionDate />
<otherDataAlt>more data</otherDataAlt>
</return>
<return id="4">
<completionDate>2013-09-11</completionDate>
<otherDataAlt>alt data</otherDataAlt>
</return>
<return id="5">
<completionDate></completionDate>
</return>
<return id="6">
<completionDate />
</return>
</sample>
//return[completionDate=""]
和//return[completionDate[not(node())]]
返回ID為1、3、5和6的<return>
節點。(已在http://www.xpathtester上進行了測試.com /和http://www.freeformatter.com/xpath-tester.html )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.