繁体   English   中英

如何通过xQuery从XML中同名多个元素检索元素的值?

[英]How To retrieve value of an element from same name multiple elements in XML through xQuery?

我在sql server中有和xml这样的字段

<propertyDetail>
  <importID>1735532</importID>
  <pincode />
  <landmarks />
  <features>
    <feature>Society  Name: sec-87 srs peral  floor faridabad</feature>
    <feature>Transaction: Resale Property</feature>
    <feature>Possession: Dec,2011</feature>
    <feature>*Ownership: Freehold*</feature>
    <feature>Age of Property: Under Construction</feature>
  </features>
</propertyDetail>

我想通过xQuery检索具有“ Ownership:Freehold ”值的功能,并且功能序列可能会有所不同。

欢迎任何建议。

您可以在过滤器表达式中检查该功能是否存在,即:

//propertyDetail[features/feature[. eq "*Ownership: Freehold*"]]

其中@x是你的xml

select @x.query('//feature[. = "*Ownership: Freehold*"]')

如果你想找到以所有权开头的任何东西

select @x.query('//feature[substring(.,1,9)="Ownership"]')

(但理想情况下,如果可以,您应该改进XML结构)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM