的test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>French Toast aaa</name>
<price>$5.95</price>
<description>Our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
test.xqy:
for $x in doc('test.xml')//*
return update insert attribute id {'abcd'} into $x
对于每个XML标记,我添加一个新属性。 xqy文件非常简单。我得到了:
[XPST0003] Unexpected end of query: 'insert attribut...'.
任何帮助?
答案 0 :(得分:0)
你在这里有两个问题:
update
声明和node
关键字。特定于BaseX的update
statement is only meant to be used with the copy
/modify
construct;你在这里不需要它。然后,用于插入任何类型节点的运算符始终为insert node $node [positional clause] into $target
,并带有可选的[positional clause]
。您当然也可以使用像$node
这样的节点构造函数而不是节点变量attribute id {'abcd'}
。
正确的查询是:
for $x in doc('test.xml')//*
return insert node attribute id {'abcd'} into $x