In below XML:
<company>
<customers>
<customer cno="2222">
<cname>Charles</cname>
<street>123 Main St.</street>
<city>Wichita</city>
<zip>67226</zip>
<phone>316-636-5555</phone>
</customer>
<customer cno="1000">
<cname>Bismita</cname>
<street>Ashford Dunwoody</street>
<city>Wichita</city>
<zip>67226-1555</zip>
<phone>000-000-0000</phone>
</customer>
</customers>
</company>
I need to get the customer's no which is an attribute. In XPath I know it is /company/customers/customer/@cno
, in XQuery I've tried below expression but didn't work for me:
for $c in /company/customers/customer
return $c/@cno
You should use data to pick attribute value:-
for $c in /company/customers/customer
return data($c/@cno)
You can also use string
to get attribute value:
for $c in /company/customers/customer
return $c/@cno/string()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.