簡體   English   中英

具有多個屬性的XML查詢

[英]XML Query with multiple attributes

我有以下XML:

<LoSTResponseBodyType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <LoSTResponseAdapter xmlns="urn:adapt:xml:ns:DataTypes:2.0">
       <findServiceResponse xmlns="urn:lost:params:xml:ns:lost1">
           <mapping sourceId="9999" expires="2015-08-24T14:27:58Z" lastUpdated="2015-06-17T21:36:43Z" source="mysourcename">
              <displayName xml:lang="en">mydisplayname</displayName>
              <service>myservice</service>
              <uri>myuri</uri>
              <serviceNumber>mynumber</serviceNumber>
           </mapping>
      </findServiceResponse>
    </LoSTResponseAdapter>
</LoSTResponseBodyType>

如何檢索<uri>的值,即myuri

我試過以下代碼

WITH xmlnamespaces ('urn:adapt:xml:ns:DataTypes:2.0' as datatype,
                    'urn:lost:params:xml:ns:lost1' as findtype)
SELECT EventBody.value('(/LoSTResponseBodyType/datatype:LoSTResponseAdapter/findtype:findServiceResponse/mapping/uri)[1]', 'varchar(max)') 
FROM mytable

我得到一個NULL值。

如果我刪除所有'mapping / uri',我確實將所有值連接在一起,即displayname,service,uri,serviceNumber,它看起來像這樣:mydisplaynamemyservicemyurimynumber

嘗試將findtype前綴添加到xpath中的mappinguri

這些元素也與findServiceResponse位於同一名稱空間中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM