[英]How To retrieve value of an element from same name multiple elements in XML through xQuery?
I have and xml field like this in sql server 我在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>
I want to retrieve the feature which has value " Ownership: Freehold " through xQuery and sequence of features may vary. 我想通过xQuery检索具有“ Ownership:Freehold ”值的功能,并且功能序列可能会有所不同。
Welcome any suggestion. 欢迎任何建议。
您可以在过滤器表达式中检查该功能是否存在,即:
//propertyDetail[features/feature[. eq "*Ownership: Freehold*"]]
Where @x
is your xml 其中@x
是你的xml
select @x.query('//feature[. = "*Ownership: Freehold*"]')
If you want to find anything that starts with Ownership then 如果你想找到以所有权开头的任何东西
select @x.query('//feature[substring(.,1,9)="Ownership"]')
(but ideally you should improve your XML structure, if you can) (但理想情况下,如果可以,您应该改进XML结构)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.