Questions tagged [xquery]

XQuery is a functional language designed to query and manipulate XML data. It is a superset of XPath, to which it adds features such as the creation of new nodes and more powerful FLWOR expressions. Although it shares its data model with XSLT, XQuery is optimized for querying rather than transforming data, and as such it has a different design inspired by SQL.

W3C XML Query

XQuery has a rich set of features that allow many different types of operations on data and documents, including:

  • Selecting information based on specific criteria
  • Filtering out unwanted information
  • Updates
  • Searching for information within a document or set of documents
  • Joining data from multiple documents or collections of documents
  • Sorting, grouping, and aggregating data
  • Transforming and restructuring XML data into another XML vocabulary
    or structure
  • Performing arithmetic calculations on numbers and dates
  • Manipulating strings to reformat text

XQuery can be used not just to extract sections of XML documents, but also to manipulate and transform the results.

Modified from O'Reilly XQUERY ISBN-10: 0-596-00634-9 By Priscilla Walmsley.

Relationship to XSLT

XQuery has a large overlap with in terms of purpose but has a syntax and model inspired largely by . Most built in functions are shared with XSLT.

Relationship to XPath

XQuery is mostly a superset of . XQuery version 1 is based on XPath version 2. XQuery version 3 is based on XPath version 3. Version 2 was skipped in order to align the XQuery and XPath version numbers. XQuery 3.1 like XPath 3.1 supports JSON processing through the new map and array types and JSON <--> XML conversion using the xml-to-json and json-to-xml functions as well as parse-json and json-doc functions.

Implementations

  • A list of the current implementations according to the W3C XML Query group.
  • Version 9.8 and later of the Saxon processor support both XSLT 3.0 and XQuery 3.1.
  • BaseX implements all versions of the language and can be use through a CLI.

References

Online training

Books

5333 questions
10
votes
1 answer

Filter SQL queries on the XML column using XPath/XQuery

I'm having a table with one XML column. I'd like to filter out the rows where a specific attribute in the XML match a string, essentially doing a WHERE or HAVING. The table looks something like this | id | xml | And the XML something similar to…
Mats Fredriksson
  • 19,783
  • 6
  • 37
  • 57
10
votes
2 answers

What is the most efficient way to store name/value pairs in a Marklogic database

My application often needs to decorate values in the documents it serves using a lookup take to fetch human readable forms of various codes. For example PC001 would want to be returned as
Will Goring
  • 1,040
  • 1
  • 7
  • 18
10
votes
2 answers

SQL Server query xml attribute for an element value

Sorry if this is somewhere else, I have found a lot of similar examples but I have been unable to get it working with my data. 2 days later and I need an answer :( Basically have a SQL Server table with a column containing XML data. This data…
Divvet
  • 103
  • 1
  • 1
  • 4
10
votes
1 answer

Return multiple values from multiple inputs in XQuery 3.0?

I've tried a few things: for $name in ('Hanz', 'Heinz', 'Hans', 'Huns', 'Hund') where $name contains text 'Hans' using fuzzy return $name | $name (: returns error: Stopped at line 3, column 20: [XPTY0004] Union expression: node() expected,…
Wolfpack'08
  • 3,982
  • 11
  • 46
  • 78
10
votes
2 answers

Getting element names using XPath/XQuery

having the following XML sample document, I need to issue an XPath/XQuery expression to get the element names for every children of a CD element. Empire Burlesque Bob Dylan USA
Lucy
  • 471
  • 4
  • 12
  • 28
9
votes
1 answer

Update substring in XML column SQL Server 2008

I want to perform an update on all the rows in an XML column in SQL Server 2008, replacing just a substring in a certain xml node. I'm new to XML DML / XQuery and all that and I just cannot figure out how to do it. Example of XML in the column I…
Kberg
  • 161
  • 1
  • 2
  • 8
9
votes
1 answer

Merge the two xml fragments into one?

How to merge the xml content of @a and @b into @c? declare @a xml = (select 1 aaa for xml path('AAAs')); declare @b xml = (select 1 bb1, 2 bb2 for xml path('BBBs')); declare @c xml = ... @a + @b ....? I need to pass the merged xml to a stored…
ca9163d9
  • 27,283
  • 64
  • 210
  • 413
9
votes
2 answers

How to use XQuery in C#

How to use XQuery expression on XMLDocument or XDocument? Is it possible to use XQuery in C#?
ARZ
  • 2,461
  • 3
  • 34
  • 56
9
votes
3 answers

Getting filename of an XML file with XQuery

I store my entities in the eXist XML database and I use a file name (resource id) as an ID of an entity. Example: String xquery = "for $movie in collection('/db/movie')//movie " + "return $movie"; After executing this query I retrieve…
VaclavDedik
  • 1,960
  • 4
  • 20
  • 27
9
votes
2 answers

Ignore XML namespace in T-SQL

How do I remove/ignore the XML namespace in an xml file when querying the data with T-SQL? I’m loading an xml file into a variable, and it works just fine. But the xml has a namespace set, and unless I remove it, my queries come up…
Jakob Gade
  • 12,319
  • 15
  • 70
  • 118
9
votes
1 answer

xQuery on XML file with namespace

I'm using eXist-DB to store XML documents. Here's a sample XML file with the namespace info:
jwesonga
  • 4,249
  • 16
  • 56
  • 83
9
votes
2 answers

How can I use xpath querying using R's XML library?

The xml file has this snippet:
tommy chheng
  • 9,108
  • 9
  • 55
  • 72
9
votes
5 answers

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

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…
dacracot
  • 22,002
  • 26
  • 104
  • 152
9
votes
2 answers

Using XMLTABLE and xquery to extract data from xml

I have the following piece of XML:
ErikL
  • 2,031
  • 6
  • 34
  • 57
9
votes
4 answers

How to unencode escaped XML with xQuery

I have a variable in xQuery of type xs:string with the value of an encoded HTML snippet (the content of a twitter tweet). It looks like this: Headlines-Today • AP sources: <b>Obama</b> pick for Justice post withdraws : News -…
mbrevoort
  • 5,075
  • 6
  • 38
  • 48