Can't get attribute values or get Error XQDY0025 in XQuery

1.1k Views Asked by At

I get nothing or "Error XQDY0025" when I use the XQuery below. However, eXide shows "Found 4 in 0.004s", please help me, I can't find the problem.

for $s in doc("customers.xml")/customers/Customer 
return $s/@Name

to query theName attributes from the XML document below:

<customers>
    <Customer Name="c2">
        <Order OrderNumber="o1">
            <Item Description="ab">i1</Item>
        </Order>
    </Customer>
    <Customer Name="c3">
        <Order OrderNumber="o2">
            <Item Description="cd">i2</Item>
            <Item Description="ef">i3</Item>
        </Order>
        <Order OrderNumber="o2">
            <Item Description="cfg">i5</Item>
        </Order>
    </Customer>
    <Customer Name="c1">
        <Order OrderNumber="o1">
            <Item Description="abc">i1</Item>
            <Item Description="def">i2</Item>
        </Order>
    </Customer>
    <Customer Name="c4">
        <Order OrderNumber="o1">
            <Item Description="abc">i1</Item>
        </Order>
        <Order OrderNumber="o2">
            <Item Description="def">i2</Item>
        </Order>
    </Customer>
</customers>
1

There are 1 best solutions below

1
On BEST ANSWER

The error code XQDY0025 (XQuery 1.0, XQuery 3.0) means you've tried to add two attributes with the same name to the same element.

There's nothing wrong with the XPath expression as such - it returns a sequence of attribute nodes, but since all those nodes have the same name you can't add more than one of them to the same element in the output.