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
252
votes
19 answers

Is there a JSON equivalent of XQuery/XPath?

When searching for items in complex JSON arrays and hashes, like: [ { "id": 1, "name": "One", "objects": [ { "id": 1, "name": "Response 1", "objects": [ // etc. }] } ] Is there some kind of query language I can…
Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
151
votes
9 answers

How can I query a value in SQL Server XML column

I have following XML stored in a XML column (called Roles) in a SQL Server database. Alpha Beta Gamma I'd like to list all rows that have a specific role in them. This role passed by…
Bistro
  • 1,915
  • 2
  • 14
  • 12
77
votes
2 answers
71
votes
4 answers

Difference between XPath, XQuery and XPointer

What is the difference between XPath, XQuery and XPointer? As far as I know, XQuery is an extended version of XPath. I have some basic knowledge of XPath. Is there any feature available in XPath which is not in XQuery? Yesterday, I heard a new word,…
Shashi
  • 12,487
  • 17
  • 65
  • 111
50
votes
3 answers

Only select text directly in node, not in child nodes

How does one retrieve the text in a node without selecting the text in the children?
Editor's Description
Last updated:

Lorem ipsum dolor…
Moak
  • 12,596
  • 27
  • 111
  • 166
47
votes
4 answers

SQL: How can I get the value of an attribute in XML datatype?

I have the following xml in my database: I am using something like this now: but still have to find the attribute value. SELECT convert(xml,m.Body).query('/Email/Account') FROM Mail How can I get…
ThdK
  • 9,916
  • 23
  • 74
  • 101
44
votes
3 answers

SQL Server SELECT to JSON function

I would like to output the results of a SELECT statement as a JSON object. I would like this to be a Function and not a stored procedure! For example, the below table Users id name active 1 Bob Jones 1 2 John Smith 0 Would be…
jamesmhaley
  • 44,484
  • 11
  • 36
  • 49
43
votes
6 answers

Concatenate multiple node values in xpath

I have a XML that looks like this Hello World Hello2
krishna2642
  • 579
  • 1
  • 4
  • 10
40
votes
2 answers

How to get a particular attribute from XML element in SQL Server

I have something like the following XML in a column of a table: ... I am trying to get the valueB…
My Other Me
  • 5,007
  • 6
  • 41
  • 48
35
votes
3 answers

XML query() works, value() requires singleton found xdt:untypedAtomic

I have a typed xml document stored as text. So I use CONVERT the data type to xml by using a Common Table Expression in order to be able to use XML methods: WITH xoutput AS ( SELECT CONVERT(xml, t.requestpayload) 'requestpayload' FROM TABLE t …
OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
33
votes
2 answers

how to select attribute value of a node in XQuery?

In below XML: Charles 123 Main St. Wichita 67226 316-636-5555
Itz.Irshad
  • 1,014
  • 5
  • 23
  • 44
33
votes
2 answers

How to query xml column in tsql

I have a table, T1, with a XML column, EventXML, on SQL Server 2008. I want to query all the rows where certain node contains a particular value. Better, I'd like to retrieve the value in a different node. The table T1: T1: EventID, int …
fivelements
  • 1,487
  • 2
  • 19
  • 32
26
votes
5 answers

XQuery: Return value of an element rather the element itself

I have an XML document that contains the following ... abc ... If I evaluate return $xml//foo I get back abc Is there any way to get just abc instead?
kpozin
  • 25,691
  • 19
  • 57
  • 76
25
votes
5 answers

Simple tool to learn XQuery?

I started playing around with XQuery. On [w3schools][1] its a good tutorial. I just have some problems: I cannot test the stuff on the site. I found an online XQuery ([this link][2]) and its nice to play with it, but if I would like to use the…
Revo
  • 255
  • 1
  • 3
  • 9
25
votes
4 answers

How to retrieve parent node using XQuery?

I am using XML and XQuerie. I usually use an XPath expression relative to a parent node to retrieve its child node. But, I am not sure how to do the opposite meaning if I have a child node, how do I retrieve its parent node.
sony
  • 1,557
  • 10
  • 36
  • 50
1
2 3
99 100