What is the element constructor in xQuery?

前端 未结 2 1085
梦毁少年i
梦毁少年i 2021-01-23 14:36

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 \

相关标签:
2条回答
  • 2021-01-23 15:08

    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.

    0 讨论(0)
  • 2021-01-23 15:09

    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>
    }
    
    0 讨论(0)
提交回复
热议问题