Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有级联名称空间的SQL Server Xml查询_Sql_Sql Server_Xml_Xquery - Fatal编程技术网

具有级联名称空间的SQL Server Xml查询

具有级联名称空间的SQL Server Xml查询,sql,sql-server,xml,xquery,Sql,Sql Server,Xml,Xquery,如何使用SQL Server上的SQL从下面的xml中选择pagekey的值?我尝试了使用名称空间的.nodes,但找不到正确的语法 谢谢, <?xml version='1.0' encoding='UTF-8'?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Header> <WorkContext xmlns=&q

如何使用SQL Server上的SQL从下面的xml中选择pagekey的值?我尝试了使用名称空间的.nodes,但找不到正确的语法

谢谢,

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Header>
        <WorkContext xmlns="http://oracle.com/weblogic/soap/workarea/">rO03ZWJsb2dpYy5hcHAuU0JNLVJhcG9yV1MAAADWAAAAI3dlYmxvZ2ljLndvcmthcmVhL0cmluZ1dvcmtDb250ZXh0ABIyMDIwLE4LjE0MjIuNDAAAA==</WorkContext>
    </S:Header>
    <S:Body>
        <ns0:getReportOutputResponse xmlns:ns0="http://report_xml.org">
            <return>
                <pagekey>i6161140E964FF7A072CD2E3F2BB9C0</pagekey>
                <report>&lt;?xml version="1.0"?>&lt;dataSet xmlns="http://report_xml.org/dataSet/201006">&lt;dataTable>&lt;id>C1&lt;/id>&lt;/dataTable>&lt;/dataSet></report>
            </return>
        </ns0:getReportOutputResponse>
    </S:Body>
</S:Envelope>
像这样的

DECLARE @data XML = '<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Header>
        <WorkContext xmlns="http://oracle.com/weblogic/soap/workarea/">rO03ZWJsb2dpYy5hcHAuU0JNLVJhcG9yV1MAAADWAAAAI3dlYmxvZ2ljLndvcmthcmVhL0cmluZ1dvcmtDb250ZXh0ABIyMDIwLE4LjE0MjIuNDAAAA==</WorkContext>
    </S:Header>
    <S:Body>
        <ns0:getReportOutputResponse xmlns:ns0="http://report_xml.org">
            <return>
                <pagekey>i6161140E964FF7A072CD2E3F2BB9C0</pagekey>
                <report>&lt;?xml version="1.0"?>&lt;dataSet xmlns="http://report_xml.org/dataSet/201006">&lt;dataTable>&lt;id>C1&lt;/id>&lt;/dataTable>&lt;/dataSet></report>
            </return>
        </ns0:getReportOutputResponse>
    </S:Body>
</S:Envelope>';

-- define the two relevant XML namespaces
WITH XMLNAMESPACES('http://schemas.xmlsoap.org/soap/envelope/' AS soap, 
                   'http://report_xml.org' AS RP)
SELECT
    -- get the "pagekey" element from the "body"
    XC.value('(RP:getReportOutputResponse/return/pagekey/text())[1]', 'VARCHAR(100)')
FROM 
    -- get the <s:Body> part as XML fragment
    @data.nodes('/soap:Envelope/soap:Body') AS XT(XC)

非常有魅力,谢谢:@Charlieface:是的,我知道我不需要.nodes-这只是一种预感,在某个点上可能有多个元素。谢谢你的文字提示