Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BaseX attributes cannot be serialized

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?

like image 644
MrIcyBalls Avatar asked Jan 27 '26 17:01

MrIcyBalls


2 Answers

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()
like image 147
wst Avatar answered Jan 30 '26 12:01

wst


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.

like image 41
Christian Grün Avatar answered Jan 30 '26 13:01

Christian Grün



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!