如何使用Oracle Xquery从XML中选择特定值 [英] How to select specific values from XML using Oracle Xquery

查看:74
本文介绍了如何使用Oracle Xquery从XML中选择特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要从中获取一些值的XML的示例:

Here is an example of the XML I'm trying to get some values from:

<ows:Operation name="DescribeFeatureType">
    <ows:Parameter name="outputFormat">
        <ows:Value>text/xml; subtype=gml/3.1.1</ows:Value>
    </ows:Parameter>
</ows:Operation>
<ows:Operation name="GetFeature">
    <ows:Parameter name="resultType">
        <ows:Value>results</ows:Value>
        <ows:Value>hits</ows:Value>
    </ows:Parameter>
    <ows:Parameter name="outputFormat">
        <ows:Value>text/xml; subtype=gml/3.1.1</ows:Value>
        <ows:Value>GML2</ows:Value>
        <ows:Value>GML2-GZIP</ows:Value>
        <ows:Value>SHAPE-ZIP</ows:Value>
        <ows:Value>csv</ows:Value>
        <ows:Value>gml3</ows:Value>
        <ows:Value>gml32</ows:Value>
        <ows:Value>json</ows:Value>
        <ows:Value>text/xml; subtype=gml/2.1.2</ows:Value>
        <ows:Value>text/xml; subtype=gml/3.2</ows:Value>
    </ows:Parameter>
</ows:Operation>

我想使用Oracle 10GR2中的XMLTABLE访问操作"GetFeature"的"outputFormat"参数值.

I want to access the "outputFormat" parameter values for operation "GetFeature" using XMLTABLE in Oracle 10GR2.

我尝试了各种方法,但是它们要么没有给我结果,要么全部给我.这是一个返回所有值的示例.

I've tried various things but they either gave me no results or all. Here is an example that returns all values.

select t.*
        from xmltable(xmlnamespaces(default 'http://www.opengis.net/wfs'
                                   ,'http://www.opengis.net/gml' as "gml"
                                    ,'http://www.opengis.net/wfs' as "wfs"
                                    ,'http://www.opengis.net/ows' as "ows"
                                    ,'http://www.w3.org/1999/xlink' as "xlink"
                                    ,'http://www.w3.org/2001/XMLSchema-instance' as "xsi"
                                    ,'http://www.opengis.net/ogc' as "ogc")
                      ,'for $d in //ows:Operation/ows:Parameter/ows:Value
                        where //ows:Operation/@name = "GetFeature"
                        and //ows:Parameter/@name="outputFormat"
                        return $d' passing p_xml columns value varchar2(100) path '/') as t

非常感谢您的帮助.

推荐答案

找到了答案:

select t.*
        from xmltable(xmlnamespaces(default 'http://www.opengis.net/wfs'
                                   ,'http://www.opengis.net/gml' as "gml"
                                    ,'http://www.opengis.net/wfs' as "wfs"
                                    ,'http://www.opengis.net/ows' as "ows"
                                    ,'http://www.w3.org/1999/xlink' as "xlink"
                                    ,'http://www.w3.org/2001/XMLSchema-instance' as "xsi"
                                    ,'http://www.opengis.net/ogc' as "ogc")
                      ,'for $d in //ows:Operation/ows:Parameter/ows:Value
                        where $d/../../@name = "GetFeature"
                        and $d/../@name="outputFormat"
                        return $d' passing p_xml columns value varchar2(100) path '/') as t;

使用.. xpath表达式访问父节点.

using .. xpath expression to access the parent nodes.

这篇关于如何使用Oracle Xquery从XML中选择特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆