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?

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
dacracot
  • 22,002
  • 26
  • 104
  • 152

5 Answers5

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.
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
7

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

Parker
  • 7,244
  • 12
  • 70
  • 92
5

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

devio
  • 36,858
  • 7
  • 80
  • 143
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.

Michael Baranov
  • 789
  • 1
  • 7
  • 17
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>
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223