3

I have this simple XML file:

<catalog>
  <product dept="WMN">
    <number>557</number>
    <name language="en">Fleece Pullover</name>
    <colorChoices>navy black</colorChoices>
  </product>
  <product dept="ACC">
    <number>563</number>
    <name language="en">Floppy Sun Hat</name>
  </product>
  <product dept="ACC">
    <number>443</number>
    <name language="en">Deluxe Travel Bag</name>
  </product>
  <product dept="MEN">
    <number>784</number>
    <name language="en">Cotton Dress Shirt</name>
    <colorChoices>white gray</colorChoices>
    <desc>Our<i>favorite</i>shirt!</desc>
  </product>
</catalog>

I am reading a book called XQuery by Priscila Walmsley and it says to type the command:

doc("catalog.xml")/*/product/@dept

so I type in BaseX

xquery doc("catalog.xml")/*/product/@dept

and I am getting this error:

Error:
[SENR0001] Attributes cannot be serialized:attribute dept { "WMN" }.

Despite that the book that says:

will return the four dept attributes in the input document.

What am I doing wrong?

dirkk
  • 6,160
  • 5
  • 33
  • 51
MrIcyBalls
  • 83
  • 1
  • 9
  • This may just be a limitation of your test environment. For example, try forcing it to serialize as a string: `xquery doc("catalog.xml")/*/product/@dept/string()` – wst Jul 09 '14 at 20:49
  • great @wst good catch! If you care to put it in an answer it will be good for other users `xquery doc("catalog.xml")/*/product/string(@dept)` – MrIcyBalls Jul 09 '14 at 21:00

2 Answers2

7

BaseX is just being strict about serialization. It won't complain if you force the attribute nodes into strings:

xquery doc("catalog.xml")/*/product/@dept/string()
wst
  • 11,681
  • 1
  • 24
  • 39
2

The XQuery 3.1 Serialization specification provides the new "adaptive" serialization mode, which allows the serialization of attribute and namespace nodes. Since Version 8.0 of BaseX, this mode is used as new default.

Christian Grün
  • 6,012
  • 18
  • 34