【问题标题】:How to get data from XML with XMLNAMESPACES如何使用 XMLNAMESPACES 从 XML 中获取数据
【发布时间】:2016-05-31 10:01:02
【问题描述】:

我有一个这样的 XML 文件

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header/>
    <env:Body>
        <ns0:getDateIdentificareResponse xmlns:ns0="/asdf/asdf/types/">
            <ns1:result xmlns:ns0="/asdf/asdf/" xmlns:ns1="/asdf/asdf/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns0:CustomerSDO">
                <ns0:Cif>1</ns0:Cif>
                <ns0:Cui>2</ns0:Cui>
                <ns0:CategorieClient>mm</ns0:CategorieClient>
                <ns0:NrInregistrare>xxxx</ns0:NrInregistrare>
                <ns0:CodCaen>dsaads</ns0:CodCaen>
                <ns0:Telefon xsi:nil="true"/>
                <ns0:AdresaSediu>
                    <ns0:Cif>2</ns0:Cif>
                    <ns0:Tara>2</ns0:Tara>
                    <ns0:Judet>3</ns0:Judet>
                    <ns0:Localitate>4</ns0:Localitate>
                    <ns0:CodPostal xsi:nil="true"/>
                    <ns0:Sector xsi:nil="true"/>
                    <ns0:Strada>5</ns0:Strada>
                    <ns0:Numar>6</ns0:Numar>
                    <ns0:Bloc xsi:nil="true"/>
                    <ns0:Scara xsi:nil="true"/>
                    <ns0:Etaj xsi:nil="true"/>
                    <ns0:Apartament xsi:nil="true"/>
                    <ns0:BulkAddress>sddsa</ns0:BulkAddress>
                </ns0:AdresaSediu>
                <ns0:AdresaCorespondenta>
                    <ns0:Cif>2</ns0:Cif>
                    <ns0:Tara>2</ns0:Tara>
                    <ns0:Judet>3</ns0:Judet>
                    <ns0:Localitate>4</ns0:Localitate>
                    <ns0:CodPostal xsi:nil="true"/>
                    <ns0:Sector xsi:nil="true"/>
                    <ns0:Strada>5</ns0:Strada>
                    <ns0:Numar>6</ns0:Numar>
                    <ns0:Bloc xsi:nil="true"/>
                    <ns0:Scara xsi:nil="true"/>
                    <ns0:Etaj xsi:nil="true"/>
                    <ns0:Apartament xsi:nil="true"/>
                    <ns0:BulkAddress>sddsa</ns0:BulkAddress>
                </ns0:AdresaCorespondenta>
                <ns0:BeneficiariReali>
                    <ns0:CifClient>Valuue</ns0:CifClient>
                    <ns0:CifBeneficiar>Valuue</ns0:CifBeneficiar>                   
                </ns0:BeneficiariReali>
                <ns0:BeneficiariReali>
                    <ns0:CifClient>Valuue</ns0:CifClient>
                    <ns0:CifBeneficiar>Valuue</ns0:CifBeneficiar>

                </ns0:BeneficiariReali>
                <ns0:Conturi>
                    <ns0:CifClient>Valuue</ns0:CifClient>
                    <ns0:CifBeneficiar>Valuue</ns0:CifBeneficiar>
                </ns0:Conturi>
                <ns0:Imputerniciti>
                    <ns0:CifClient>Valuue</ns0:CifClient>
                    <ns0:CifBeneficiar>Valuue</ns0:CifBeneficiar>
                </ns0:Imputerniciti>
            </ns1:result>
        </ns0:getDateIdentificareResponse>
    </env:Body>
</env:Envelope>

而且我找不到在 SQL 中导入数据的方法。我知道根据

应该相当容易

How can I query a value in a XML column in SQL Server 2008

https://dba.stackexchange.com/questions/117005/import-xml-files-into-sql-server-2012

但我错过了一些东西。运行第二个问题解决方案不会得到我的任何东西。对于第一个问题,我不知道该写什么作为 XMLNAMESPACES 的参数。

谁能帮助我?谢谢

【问题讨论】:

    标签: sql-server xml tsql xquery xml-namespaces


    【解决方案1】:

    尝试使用*

    SELECT t.c.value('(*:Cif/text())[1]', 'INT')
    FROM @x.nodes('*:Envelope/*:Body/*:getDateIdentificareResponse/*:result') t(c)
    

    【讨论】:

    猜你喜欢
    • 2018-01-02
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 2022-01-14
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    相关资源
    最近更新 更多