1
我需要從SQL Server 2008中的XML中獲取一些信息,但我甚至無法從中獲得基本屬性。我嘗試過的所有樣品都失敗了。表名是Item
,xml列名是Data
。在sql中查詢XML值
簡體XML看起來是這樣的:
<AnchoredXml xmlns="urn:schema:Microsoft.Rtc.Management.ScopeFramework.2008" SchemaWriteVersion="2">
<Key ScopeClass="Global">
<SchemaId Namespace="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008" ElementName="Topology" />
<AuthorityId Class="Host" InstanceId="00000000-0000-0000-0000-000000000000" />
</Key>
<Dictionary Count="1">
<Item>
<Key />
<Value Signature="a3502dd0-8c16-4023-9eea-30ea1c7a3a2b">
<Topology xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008">
<Services>
<Service RoleVersion="1" ServiceVersion="6" Type="Microsoft.Rtc.Management.Deploy.Internal.ServiceRoles.FileStoreService">
<ServiceId SiteId="1" RoleName="FileStore" Instance="1" />
<DependsOn />
<InstalledOn>
<ClusterId SiteId="1" Number="1" />
</InstalledOn>
<Ports xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.ServiceRoles.2008" />
<FileStoreService xmlns="urn:schema:Microsoft.Rtc.Management.Deploy.ServiceRoles.2008" ShareName="lyncShare" />
</Service>
</Services>
</Topology>
</Value>
</Item>
</Dictionary>
</AnchoredXml>
我需要閱讀AnchoredXml /按鍵/ SchemaId/@命名空間信息來選擇合適的XML(有更多行)。上面的示例xml是正確的。之後我需要找到合適的服務
Type="Microsoft.Rtc.Management.Deploy.Internal.ServiceRoles.FileStoreService"
其中是我需要的FileStoreService/@ ShareName。
我試過打印命名空間attributte爲開始,但沒有示例代碼工作。 試了幾次:
SELECT c.p.value('(@Namespace)[1]', 'varchar(50)') as 'Nmspace'
FROM Item
CROSS APPLY Data.nodes('/AnchoredXml/Key/SchemaId') c(p)
返回空結果集
SELECT Data.value('(/AnchoredXml/Key/SchemaId/@Namespace)[1]', 'varchar(50)')
FROM Item
返回NULL所有行
SELECT
It.Data.exist('/AnchoredXml/Key/SchemaId[@Namespace="Microsoft.Rtc.Management.Deploy.Topology.2008"]')
FROM [xds].[dbo].[Item] AS It
返回0的所有行也沒有引號( 「」)
至少得到屬性測試的工作示例代碼可能就足夠了我會找出其餘的。 你能幫我找到我的疑問中的錯誤或者可能確定一些其他問題嗎? 謝謝
這確實是我的問題的原因!謝謝。只需要添加一個過濾器即可。 WHERE Data.exist('(/ AnchoredXml/Key/SchemaId [@ Namespace =「urn:schema:Microsoft.Rtc.Management.Deploy.Topology.2008」])')= 1 – Geralt 2014-11-25 12:28:12