Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8213105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:59:55+00:00 2026-06-07T10:59:55+00:00

I need to insert a new element into an XML document using XQuery insert

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:59:56+00:00Added an answer on June 7, 2026 at 10:59 am

    BaseX XQJ API supports XQuery Update Facility 1.0 and 3.0, which allows you to update documents in the BaseX database.

    You can also update in-database documents via the MarkLogic XQJ API, Sedna XQJ API and eXist XQJ APIs although not via XQuery Update Facility, as these implementations do not support XQUF (yet).

    Finally and possibly most importantly for your question, you may find Ryan Grimm’s “in-mem-update” library module very useful [1]. I certainly have, countless times in the past.

    You can

    • Use the library module with ANY XQuery processor + XQJ
    • Perform updates to an in-memory XML document (no need to write to disk).
    • Perform “multiple” update operations against a document in one single XQuery
    • Post updated in-memory documents can be returned in an XQResultSequence (great for you).

    Also, just to make something clear here, the XQJ 1.0 Specification doesn’t disallow vendors from supporting XQuery Update Facility.

    An excerpt from the Specification:

    “18.6 Support for Updates and Transactions

    Although update functionality is not part of [XQuery], XQJ expects that some
    implementations will include some proprietary extensions to handle update functionality.”

    [1] https://github.com/marklogic/commons/blob/master/memupdate/in-mem-update.xqy

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a way to insert new articles straight into my MediaWiki database without
I need to insert records into a new table from an existing table. I
Im new to MySql, and I need to insert into table 10000 random 2-digit
I need to insert Chinese characters inside Oracle Data base using Java (hibernate 3.0
I need to insert a DOM which is a complete SVG document into an
I am attempting to insert a parsed XML element into the middle of a
I'm trying to update the Insert action while inserting a new element into an
I need to clear the <div> and insert new content I get from the
Hi need insert data in table if the record is not already exits Ex:
Need to insert selected text on the page into textarea. There must be some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.