我需要使用 XQuery 插入表达式将新元素插入 XML 文档。我saxon
用作java api。我是 XQuery 的新手,所以我不确定插入表达式的确切结构。任何人都可以帮助我吗?
我的 XML 文件如下所示:
<?xml version="1.0" encoding="ISO-8859-1"?>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>two of our famous Belgian Waffles with plenty of real maple syrup<description>
<calories>650</calories>
</food>
</breakfast_menu>
我用于执行插入的java代码是
public void insert() throws XQException{
String queryString =
//"declare variable $docName as xs:string external;" + sep +
"variable $stores := doc("+"food.xml"+")/*;"+
"insert node element food {"+
"element name { \"brnj\" },"+
"element price { \"$20\" },"+
"element description { \"whatever\" },"+
"element calories { 300 },"+
"} into $stores;";
XQPreparedExpression expr = conn.prepareExpression(queryString);
expr.bindObject(new QName("stores"), "food.xml", null);
XQResultSequence rs = expr.executeQuery();
}
我得到的错误是查询字符串的语法。请帮忙。