Does XQuery (or XPath) have equivalents to Update, Insert, and Delete as well as Select?
Asked Answered
C

5

9

I know how to find what I need from XML using XPath. The syntax takes a little getting used to, but it is quite powerful. I'm interested in learning XQuery also, but the SQL like syntax seems awkward. Even so, if it can provide not just a select equivalent, but also update, insert, and delete as SQL does, I will forgive all awkwardness.

So, does XQuery have equivalents to Update, Insert, and Delete as well as Select?

Does XPath have these equivalents that I have overlooked?

Charmion answered 21/11, 2008 at 16:0 Comment(0)
T
14

No. None of XPath or XQuery has SQL-like update/insert/delete functionality.

You need to look for an implementation of the "XQuery 1.0 Update Facility".

At this moment (Nov. 2008), three such are known:

  1. SaxonSA XSLT and XQuery Processor — by Michael Kay; Supported since version 9.1, but only in the commercial version.
  2. MonetDB/XQuery - An open source XQuery processor on top of the MonetDB relational database system.
  3. XQilla - An open source (ASL2.0) XQuery processing library with support for the latest XQuery Update features. XQilla is written in C++ and includes a command line executable shell to execute queries against XML content stored on a local filesystem. This library is actively developed and part of a supported Oracle product, Berkeley DB XML.
Thrum answered 22/11, 2008 at 20:28 Comment(1)
@CharlesDuffy: Sure, but in 2008 I believe BaseX still wasn't around.Thrum
J
7

Take a look at the XQuery Update Facility, check out the XQuery Use Cases or check out the XML Query working group page.

Jewelljewelle answered 21/11, 2008 at 16:11 Comment(0)
S
5

In SQL Server 2005/8 the extension of XQuery is called XML DML, and supports data modification using the replace value of statement.

Selfsufficient answered 13/12, 2008 at 21:5 Comment(0)
S
4

XPath is a language for addressing parts of an XML document. So it cannot have any DML statement. It is select statement by definition.

Seigneur answered 21/11, 2008 at 16:14 Comment(1)
That's true for XPath. XQuery, however, does have a formally standardized extension which allows updates.Cryoscopy
M
0

You can do update operation with BaseX with :

$ cat xquery.txt 
declare namespace w = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
copy $input := doc("/dev/stdin")
modify delete node $input//w:rPr
return $input
$ cat file3.xml 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
    <w:lvl w:ilvl="0">
      <w:rPr>
          TO REMOVE
      </w:rPr>
      <w:rPx>
        <w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/>
      </w:rPx>
    </w:lvl>
</root>
$ basex xquery.txt < file3.xml 
<root xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:lvl w:ilvl="0">
    <w:rPx>
      <w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/>
    </w:rPx>
  </w:lvl>
Momentous answered 24/4, 2023 at 15:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.