问题
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?
回答1:
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()
回答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.
来源:https://stackoverflow.com/questions/24663393/basex-attributes-cannot-be-serialized