Documents

Document nodes represent entire XML documents in the XQuery data model. When an input document is opened using the doc function, a document node is returned. The document node should not be confused with the outermost element node, which is its child.

Not all XML data selected or constructed by queries has a document node at its root. Some implementations will allow you to query XML fragments, such as an element or a sequence of elements that are not part of a document. When XML is stored in a relational database, it often holds elements without any containing document. It is also possible, using element constructors, to create result elements that are not part of a document.

The root function can be used to determine whether a node is part of a document. It will return the root of the hierarchy, whether it is a document node or simply a standalone element.

Document Nodes and the Data Model

A document node is the root of a node hierarchy, and therefore has no parent. The children of a document node are the comments and processing instructions that appear outside of any element, and the outermost element node. For example, the document shown in Example 21-4 would be represented by a single document node that has two children: the xml-stylesheet processing-instruction node and the businessDocument element node.

The string value of a document node is the string value of all its text node descendants, concatenated together. In Example 21-4, that would simply be 2006-10-15 ...

Get XQuery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.