0

このようなデータがありますが、

このデータを解析する方法を誰か教えてください..

  declare @tab xml


SET @tab ='<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
    xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
    xmlns:rs="urn:schemas-microsoft-com:rowset"
    xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
</s:Schema>
<rs:data>
<z:row Agents="434" c1="Adass" Keyvalue="401RE-422DS" Licensed="54" Overage="767" c5="sada@gf.com"
         c6="QCI of Des Moines"/>
    <z:row Agents="222" c1="Back setters" Keyvalue="4075QZ-3DCWD" Licensed="4533" Overage="9897"
         c5="ba@bbtechsolutions.com" c6="BBTech Solutions Inc"/>
    <z:row Agents="455" c1="gffs" Keyvalue="40343-5644Q" Licensed="212" Overage="655" c5="patrick"
         c6="new Dos"/>
         </rs:data>
</xml>'

<row>情報の選択方法c5,Keyvalue,c1,c2

前もって感謝します。

ありがとう@アレクサンダー、@グラナダ

4

2 に答える 2

2
;WITH XMLNAMESPACES ('#RowsetSchema' AS z)
SELECT  
       Tbl.Col.value('@Agents', 'INT') as Agents,  
       Tbl.Col.value('@c1', 'varchar(50)') as c1,
       Tbl.Col.value('@Keyvalue', 'varchar(50)') as Keyvalue,
       Tbl.Col.value('@Licensed', 'INT') as Licensed,
       Tbl.Col.value('@Overage', 'INT') as Overage,
       Tbl.Col.value('@c5', 'varchar(150)') as c5,
       Tbl.Col.value('@c6', 'varchar(150)') as c6
FROM   @tab.nodes('//z:row') Tbl(Col)
于 2013-06-13T13:56:03.230 に答える
1

これで始められるはずです:

declare @data xml


SET @data ='<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
    xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
    xmlns:rs="urn:schemas-microsoft-com:rowset"
    xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
    <s:ElementType name="row" content="eltOnly" rs:updatable="true">
        <s:AttributeType name="Agents" rs:number="6" rs:nullable="true" rs:maydefer="true" rs:writeunknown="true" rs:basetable="Sheet1$"
             rs:basecolumn="Agents">
            <s:datatype dt:type="float" dt:maxLength="8" rs:precision="15" rs:fixedlength="true"/>
        </s:AttributeType>
        <s:extends type="rs:rowbase"/>
    </s:ElementType>
</s:Schema>
<rs:data>
<z:row Agents="434" c1="Adass" Keyvalue="401RE-422DS" Licensed="54" Overage="767" c5="sada@gf.com"
         c6="QCI of Des Moines"/>
    <z:row Agents="222" c1="Back setters" Keyvalue="4075QZ-3DCWD" Licensed="4533" Overage="9897"
         c5="ba@bbtechsolutions.com" c6="BBTech Solutions Inc"/>
    <z:row Agents="455" c1="gffs" Keyvalue="40343-5644Q" Licensed="212" Overage="655" c5="patrick"
         c6="new Dos"/>
         </rs:data>
</xml>'



;
    WITH XMLNAMESPACES (
     '#RowsetSchema' as z , 'urn:schemas-microsoft-com:rowset' as rs
    )
SELECT T.parentEntity.value('(@c1)[1]', 'varchar(64)') AS c1Attribute,
       T.parentEntity.value('(@Keyvalue)[1]', 'varchar(64)') AS KeyvalueAttribute
FROM @data.nodes('//rs:data/z:row') AS T(parentEntity)
;

追加

属性 NAMES (および対応する値) を動的に読み取りたい場合は、次のようにしてください。

;
    WITH XMLNAMESPACES (
     '#RowsetSchema' as z , 'urn:schemas-microsoft-com:rowset' as rs
    )
       SELECT  
            CAST(x.v.query('local-name(.)') AS VARCHAR(128)) As TheAttributeName,
            v.value('.' , 'VARCHAR(128)') AS TheValue
            FROM @data.nodes('//rs:data/z:row/@*') x(v)
           ;
于 2013-06-13T13:58:31.023 に答える