XQuery Functions Reference

beginner
12 min

XQuery Functions Reference

Welcome to our comprehensive guide on XQuery Functions! This tutorial is designed to help you navigate the powerful world of XML data manipulation using XQuery. Whether you're a beginner or an intermediate learner, we've got you covered! Let's dive right in. 🎯

Understanding XQuery Functions

XQuery functions are a crucial part of working with XML data. They allow you to perform various operations such as filtering, sorting, and transforming data. Let's explore some of the most common XQuery functions. 📝

Basic Functions

  1. doc(): This function is used to load an XML document.
xml
doc("example.xml")
  1. root(): Returns the root element of the current node.
xml
root()

Filtering Functions

  1. collection(): This function is used to return a sequence of items from a collection.
xml
collection("example.xml")/book[author="John Doe"]
  1. count(): Returns the number of items in a sequence.
xml
count(collection("example.xml")/book)

Sorting Functions

  1. order by: Allows you to sort a sequence in ascending or descending order.
xml
collection("example.xml")/book order by @id descending

Modifying Functions

  1. insert: Inserts a new node into the XML document.
xml
insert node <book id="5"> <title>New Book</title> <author>Jane Smith</author> </book> as last into collection("example.xml")/books
  1. delete: Removes a node or a set of nodes from the XML document.
xml
delete collection("example.xml")/book[title="Old Book"]
Quick Quiz
Question 1 of 1

Which XQuery function is used to load an XML document?

Stay tuned for more XQuery functions and examples in our next lesson! 📝