简体   繁体   English

BaseX属性无法序列化

[英]BaseX attributes cannot be serialized

I have this simple XML file: 我有这个简单的XML文件:

<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: 我正在读Priscila Walmsley的一本名为XQuery的书,它说要输入命令:

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

so I type in BaseX 所以我输入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. 将返回输入文档中的四个dept属性。

What am I doing wrong? 我究竟做错了什么?

BaseX is just being strict about serialization. BaseX对序列化严格要求。 It won't complain if you force the attribute nodes into strings: 如果强制将属性节点强制转换为字符串,则不会抱怨:

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

The XQuery 3.1 Serialization specification provides the new "adaptive" serialization mode, which allows the serialization of attribute and namespace nodes. XQuery 3.1 Serialization规范提供了新的“自适应”序列化模式,该模式允许对属性和命名空间节点进行序列化。 Since Version 8.0 of BaseX, this mode is used as new default. 从BaseX 8.0版开始,此模式用作新的默认模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM