BaseX attributes cannot be serialized

こ雲淡風輕ζ 提交于 2019-12-02 06:14:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!