Using Annotated XSD Schemas for Creating XML Views tutorial
Using sql:is-constant for creating constant elements

## Preliminaries

The sql:is-constant annotation can be used to specify a constant element, an element in the XSD schema that does not map to any database table or column. sql:is-constant takes a Boolean value (false, true), 0 and 1 (0 = false, 1 = true). The is-constant annotation can be specified on an element that does not have any attributes. If this annotation is specified on an element with the value true (or 1), that element is not mapped to the database but still appears in the XML document. The sql:is-constant annotation can be added to a <complexType> element.

## Example. Specifying sql:is-constant to add a container element

In this annotated XSD schema, 'CustomerOrders' is defined as a constant element by specifying the sql:is-constant attribute with the value of 1. Therefore, 'CustomerOrders' element is not mapped to any database table or column. This constant element consists of the 'Order' subelements. Although 'CustomerOrders' element does not map to any database table or column, it still appears in the resulting XML as a container element containing the 'Order' subelements.

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
    <xsd:annotation>
      <xsd:appinfo>
        <sql:relationship name="CustOrders"
            parent="Demo.demo.Customers"
            parent-key="CustomerID"
            child="Demo.demo.Orders"
            child-key="CustomerID" />
      </xsd:appinfo>
    </xsd:annotation>

      <xsd:element name="Customer" sql:relation="Demo.demo.Customers" >
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="CustomerOrders" sql:is-constant="1" >
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="Order" sql:relation="Demo.demo.Orders"
                               sql:relationship="CustOrders"
                               maxOccurs="unbounded" >
                    <xsd:complexType>
                       <xsd:attribute name="OrderID" type="xsd:integer" />
                       <xsd:attribute name="CustomerID" type="xsd:string" />
                    </xsd:complexType>
                  </xsd:element>
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
          </xsd:sequence>
              <xsd:attribute name="CustomerID" type="xsd:string" />
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>

Let the schema is written to the file 'CustOr_constant.xsd', then after loading this file by `xml_load_mapping_schema_decl` function, the first example will produce a result for the XPath query:

    XPATH [__view 'CustOr_constant'] /*[@CustomerID="QUEEN"]

the second example will produce a result for the XQuery query:

    select xquery_eval('<doc>{for $r in xmlview("CustOr_constant")/*[@CustomerID="QUEEN"] return $r}</doc>', xtree_doc('<q/>'))