检索指定空子节点的父节点

时间:2013-08-21 17:55:24

标签: xml xpath plsql oracle11g

我正在尝试使用XPATH返回XML中包含PL / SQL过程中没有内容的子节点的父节点。

到目前为止,我有以下XMLextract,它将返回id为10或11的子节点的包装父级,其中p_xml_content是我的xml文档。

   xmltype(p_xml_content).extract('//return/issueEventType[id=11] /../. | //return/issueEventType[id=10] /../.')

我需要转换此语句以返回包含空的completionDate节点的所有返回标记。

我想到了这一点,但不确定这是否会奏效:

   xmltype(p_xml_content).extract('//return[completionDate=''] /../.')

有什么想法吗?

干杯

Jezzipin

1 个答案:

答案 0 :(得分:1)

假设“empty completionDate node”表示“没有子节点的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上测试)