私はXMlが本当に新しく、XML列からいくつかの値を抽出することを任されています。誰も助けることができますか? SQL Server 2008のXML(SOAP)から値を抽出する
私はこれをインターネットとここでどのように行うのか、いくつかの異なる方法を試した例の多くを読んでいます。これらは動作させることができますが、null値のみを返すので、何かが正しく行かないことを明確に示します。私が見ることのできる唯一の違いは、XMLコードではSOAPを使用していることです。以前の開発者がコードを書いたので、私はそれらを尋ねることはできません。
これらは私が試してみましたメソッドです:
SELECT
settings.value('item[1]/_value[1]', 'int') as PrinterId
FROM dbo.usersettings
where userid = 2156
----------------------------------------------------------------------------------
create table XMLPrinters (PrinterList xml)
insert XMLPrinters select settings
from dbo.UserSettings
where userid = 2156
select
r.p.value ('item[1]/_key[1]', 'nvarchar (50)') as PrinterType,
r.p.value ('item[1]/_value[1]', 'int') as PrinterId
from XMLPrinters
cross apply printerlist.nodes ('//item') r(p)
を私が言うように、私はXMLに非常に新しいですし、おそらく私が何かがあるので、符号化の背景から来ていません行方不明ですが、XMLコードはWeb上で見た他のフォーマットに適合していないようですが、これはおそらくSOAPによるものだと思います。
コード自体は2496行の長であるが、これは私がから値を抽出しようとしています最初から抜粋されています
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENC:Array SOAP-ENC:arrayType="xsd:anyType[5]">
<item xmlns:a2="http://schemas.microsoft.com/clr/ns/System.Collections" xsi:type="a2:DictionaryEntry">
<_key xsi:type="xsd:string">primaryprinter</_key>
<_value xsi:type="xsd:anyType" xsi:null="1" />
</item>
<item xmlns:a2="http://schemas.microsoft.com/clr/ns/System.Collections" xsi:type="a2:DictionaryEntry">
<_key xsi:type="xsd:string">secondaryprinter</_key>
<_value xsi:type="xsd:anyType" xsi:null="1" />
</item>
<item xmlns:a2="http://schemas.microsoft.com/clr/ns/System.Collections" si:type="a2:DictionaryEntry">
<_key xsi:type="xsd:string">i18mminstancelabel</_key>
<_value xsi:type="xsd:string">1056</_value>
</item>
は最終的に私は何をする必要があるか_valueどこ_keyを抽出することです= PrimaryPrinterこれをユーザーごとに行います。
誰かが持っている助けや考えがあれば、大いに受け入れられるでしょう!
よろしく
ジュリー
素晴らしい感謝です!私は別のフォーラムにそれを掲示し、誰かがあなたと同じで答えた、そして今これはうまくいきます!私に戻ってくれてありがとう! – JYatesDBA