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 8624239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:28:30+00:00 2026-06-12T07:28:30+00:00

To mimic an auto-increment value in XQuery Update, the following works fine, assuming <root

  • 0

To mimic an auto-increment value in XQuery Update, the following works fine, assuming <root count="0"/> when running this for the first time:

let $count := /root/@count
return (
  insert node <node id='{ $count }'/> into /root,
  replace value of node $count with $count + 1  
)

…nicely yielding:

<root count="1">
  <node id="0">
</root>

However, I’d like to define the node in my Java code, and then bind that as an org.w3c.dom.Node or Document, or even String. Like:

String expr =
     " declare variable $n external; "
   + " let $count := /root/@count; "
   + " return ( "
   + "   insert node $n into /root, "
   + "   replace value of node $count with $count + 1 "
   + " ) ";
XQConnection xqc = ...;
XQPreparedExpression xqp = xqc.prepareExpression(expr);
// org.w3c.dom.Node node is <node id='{ $count }'/>
xqp.bindNode(new QName("n"), node, null);
xqp.executeQuery();

However, this just leaves me the text { $count } in the attribute. Binding the node as an xs:string value has the same effect.

Of course, this is a nice protection against “XQuery injection”. Still then: is there any way to make XQuery Update process an enclosed expression I have in the variables themselves?

(Any other smart ideas to use auto-increment values in XQuery are very welcome too, but then see Auto increment with XQuery Update?)

  • 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-12T07:28:31+00:00Added an answer on June 12, 2026 at 7:28 am

    Speaking of injection…why not just pass the node as a string and use basex:eval()?

    String node = "<node id='{ $count }'/>";
    String expr =
       ...
       + "   insert node xquery:eval($n) into /root, "
       ...
    

    Above, xquery: refers to a BaseX module.

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

Sidebar

Related Questions

I'm trying to create a custom UserControl that will mimic auto-complete as it works
I'd like to mimic how this paging works: Notice how the current page will
How can I mimic this PHP functionality in twig? I need to increment a
I would like to mimic the auto-incrementing primary keys feature that many databases have
I am trying to mimic std::map<string, std::list<string> > in VBA (this case is very
I am trying to mimic the functionality of this curl command in Java: curl
I'm trying to mimic IP camera that use MJPEG. At this moment to receive
I am trying to mimic the following PHP code in C# <?php if (
Is there a way to mimic the way the scroll works on a text
When I publish a .NET application, it will (if enabled) auto-increment the version number,

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.