Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Xquery Example in XML

Xquery Example in XML

XQuery Example in XML


Sample XML Document

<library>  <book category="fiction">    <title>The Hobbit</title>    <author>J.R.R. Tolkien</author>  </book>  <book category="history">    <title>Sapiens</title>    <author>Yuval Noah Harari</author>  </book></library>

Example 1: Retrieve all book titles

for $b in /library/bookreturn $b/title

Result:

<title>The Hobbit</title><title>Sapiens</title>

Example 2: Retrieve titles of books in the fiction category

for $b in /library/bookwhere $b/@category = "fiction"return $b/title

Result:

<title>The Hobbit</title>

Example 3: Create new XML output with title and author

for $b in /library/bookreturn  <bookInfo>    <title>{ $b/title/text() }</title>    <author>{ $b/author/text() }</author>  </bookInfo>

Result:

<bookInfo>  <title>The Hobbit</title>  <author>J.R.R. Tolkien</author></bookInfo><bookInfo>  <title>Sapiens</title>  <author>Yuval Noah Harari</author></bookInfo>

Summary

  • XQuery uses for, where, and return clauses.

  • It allows you to filter and reshape XML data.

  • You can generate new XML structures as output.


Want me to help you build more complex XQuery examples?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql