具有多个属性的XML查询
发布时间:2020-12-16 22:47:13 所属栏目:百科 来源:网络整理
导读:我有以下 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:xm
我有以下
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,它看起来像这样: 解决方法
尝试将findtype前缀添加到xpath中的mapping和uri.
这些元素也与findServiceResponse位于同一名称空间中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |