需要帮助使用XMLTable提取数据

时间:2013-04-03 08:47:56

标签: xml oracle

我们正在尝试获取ns2:令牌数据。下面的SQL无效。

SELECT xml.* FROM xxce_test xx,
                       XMLTable(XMLNamespaces(DEFAULT 'http://www.xcec.com/AgileCard/xsd/12'),'/soapenv:Envelope/soapenv:Body/ns3:CardRefTokenAddRs/ns2:TokenizedData/'
                            passing xx.xml_data
                                columns
                                    merchantId VARCHAR2(125)  PATH 'ns2:Token'
                                    ) xml

xxce_test表数据(2列):

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <ns3:CardRefTokenAddRs xmlns="http://www.xcec.com/AgileCard/xsd/12" xmlns:ns2="http://www.xcec.com/AgileCard/xsd/12" xmlns:ns3="http://www.xcec.com/AgileCard/wsdl/TokenizeCardsSvc-v1.0">
        <Status>
            <StatusCode>0</StatusCode>
            <Severity>INFO</Severity>
            <StatusDesc>Success</StatusDesc>
        </Status>

        <RqUID>unique id</RqUID>
        <ResponseContext>
            <Language>EN-US</Language>
            <ServerDt>2013-04-01T12:04:12.523-04:00</ServerDt>
        </ResponseContext>
        <ns2:TokenizedData>
            <ns2:TokenCorrelationId>1</ns2:TokenCorrelationId>
            <ns2:Token>1234567890</ns2:Token>
            <ns2:LuhnValidated>NotValidated</ns2:LuhnValidated>
            </ns2:TokenizedData>
        </ns3:CardRefTokenAddRs>
    </soapenv:Body>
</soapenv:Envelope>

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <ns3:CardRefTokenAddRs xmlns="http://www.xcec.com/AgileCard/xsd/12" xmlns:ns2="http://www.xcec.com/AgileCard/xsd/12" xmlns:ns3="http://www.xcec.com/AgileCard/wsdl/TokenizeCardsSvc-v1.0">
            <Status>
                <StatusCode>0</StatusCode>
                <Severity>INFO</Severity>
                <StatusDesc>Success</StatusDesc>
                </Status>
            <RqUID>unique id</RqUID>
            <ResponseContext>
                <Language>EN-US</Language>
                <ServerDt>2013-04-01T12:03:22.307-04:00</ServerDt>
            </ResponseContext>
            <ns2:TokenizedData>
                <ns2:TokenCorrelationId>1</ns2:TokenCorrelationId>
                <ns2:Token>0987654321</ns2:Token>
                <ns2:LuhnValidated>NotValidated</ns2:LuhnValidated>
            </ns2:TokenizedData>
        </ns3:CardRefTokenAddRs>
    </soapenv:Body>
</soapenv:Envelope>

1 个答案:

答案 0 :(得分:1)

您的XPath是错误的,并且您没有声明所有名称空间。

select /*+ cursor_sharing_exact */
 xml.*
  from xxce_test xx,
       xmltable(
         xmlnamespaces(default 'http://www.xcec.com/AgileCard/xsd/12',
                       'http://schemas.xmlsoap.org/soap/envelope/' as "soapenv",
                       'http://www.xcec.com/AgileCard/xsd/12' as "ns2",
                       'http://www.xcec.com/AgileCard/wsdl/TokenizeCardsSvc-v1.0' as "ns3"),
                '/soapenv:Envelope/soapenv:Body/ns3:CardRefTokenAddRs/ns2:TokenizedData'
                passing xx.xml_data 
                columns 
                  merchantid varchar2(125) path 'ns2:Token') xml

小提琴示例:http://sqlfiddle.com/#!4/b512f/1