I need to insert a new element into an XML document using XQuery insert expression. I am using saxon
as a java api. I am new to XQuery so I am not sure about the exact structure of the insert expression. Can anyone help me in this please.
My XML file looks like the following:
<?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>
and the java code I have for executing the insertion is
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();
}
the error I get is in the syntax of the query string. Please help.