I\'m reading a book about xQuery and it is full of expression like element constructor... and my question is:
What is the element constructor and is \
I'm surprised that a book should use the term without explaining it, but your next port of call should be the W3C XQuery specification,
https://www.w3.org/TR/xquery-31/#id-constructors
Unlike many language specifications, the XQuery specs are designed to be quite readable by ordinary users, provided you can follow BNF, and they have lots of examples.
An element constructor creates an element. There are several ways that you can do that in XQuery.
The curly braces {}
mark the beginning and end of an enclosed expression in XQuery. Since you can use literal XML and computed expressions, the curly braces denote when you are leaving the static context and entering the dynamic constructs. Similar to how you would use <%@ page ... %>
for JSP directives.
With a direct element constructor, you use XML syntax to create a static XML structure.
For instance:
<book isbn="isbn-0060229357">
<title>Harold and the Purple Crayon</title>
</book>
With a computed element constructor, an element node and content and can generate dynamic XML structure from expressions for the element name and it's content.
For example:
element book {
attribute { "isbn" } { "isbn-0060229357" },
<title>Harold and the Purple Crayon</title>
}
You can also use an expression to compute the element name:
element { fn:concat("bo", "ok") } {
attribute { "isbn" } { "isbn-0060229357" },
<title>Harold and the Purple Crayon</title>
}