Constructors
Constructors create XML structures within a query. XQuery provides constructors for creating element nodes, attribute nodes, document nodes, text nodes, processing instruction nodes, and comment nodes. XQuery provides two kinds of constructors: direct constructors and computed constructors.
Direct
constructors use an XML-like notation to create XML structures
within a query. XQuery provides direct constructors for creating element
nodes (which might include attribute nodes, text nodes, and nested
element nodes), processing instruction nodes, and comment nodes. For
example, the following constructor creates a
book element
that contains an attribute and some nested elements: <book isbn="isbn-0060229357">
<title>Harold and the Purple Crayon</title>
<author>
<first>Crockett</first>
<last>Johnson</last>
</author>
</book>Computed constructors use
a notation that is based on enclosed expressions to create XML structures
within a query. A computed constructor begins with a keyword that
identifies the type of node to be created and is followed by the name
of the node, if applicable, and an enclosed expression that computes
the content of the node. XQuery provides computed constructors for
creating element nodes, attribute nodes, document nodes, text nodes,
processing-instruction nodes, and comment nodes. For example, the
following query contains computed constructors that generate the same
result as the direct constructor described in the previous example:
element book {
attribute isbn {"isbn-0060229357" },
element title { "Harold and the Purple Crayon"},
element author {
element first { "Crockett" },
element last {"Johnson" }
}
}