如何在XQuery中选择节点的属性值?

Itz*_*had 23 xml xquery

在下面的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>
Run Code Online (Sandbox Code Playgroud)

我需要得到客户的否定属性.在XPath中我知道它是/company/customers/customer/@cno,在XQuery中我尝试过以下表达但是对我不起作用:

for $c in /company/customers/customer
return $c/@cno
Run Code Online (Sandbox Code Playgroud)

Nav*_*wat 46

您应该使用数据来选择属性值: -

for $c in /company/customers/customer
return data($c/@cno)
Run Code Online (Sandbox Code Playgroud)


Nik*_*iya 12

您还可以使用string获取属性值:

for $c in /company/customers/customer
    return $c/@cno/string()
Run Code Online (Sandbox Code Playgroud)