This function builds a list of attributes to be included in the XML element generated by the XMLELEMENT function. XMLATTRIBUTES is valid only within an XMLELEMENT function.
Following is the syntax diagram for XMLELEMENT and XMLATTRIBUTE:
►►─ XMLELEMENT ─ (NAME ─ identifier ──────────────────────────────────────────► ►─┬───────────────────────────────────────────────┬──────────────────────────► │ ┌─ , ─────────────┐ │ └─ ,XMLATTRIBUTES ─ ( ─▼─ xml-attribute ─┴ ─ ) ─┘ ┌─────────────────────────┐ ►─▼─┬─────────────────────┬─┴─┬───────────────────────────────┬─ ) ──────────►◄ └─ ,value-expression ─┘ └─ OPTION ─ xml-content-option ─┘
Expansion of Where xml-attribute is as follows
├── value-expression ─┬───────────────────┬────────────────────────────────────┤ └─ AS ─ identifier ─┘
Expansion of Where xml-content-option is as follows
├──┬─ EMPTY ON NULL ◄ ───┬─────────────────────────────────────────────────────┤ ├─ NULL ON NULL ──────┤ ├─ ABSENT ON NULL ────┤ ├─ NIL ON NULL ───────┤ └─ NIL ON NO CONTENT ─┘
The xml-content-option defines the XML value that is produced when the value-expression list, representing the content of the element, is either missing or evaluates entirely to NULLs. If no content is supplied, then any supplied ON NO CONTENT specification is applied. If content is supplied but every supplied item evaluates to NULL, the ON NULL option applies. In the XMLELEMENT function, EMPTY ON NULL is the default. In XMLFOREST, NULL ON NULL is the default. In all other cases, an element is generated using whatever non-NULL values were supplied.
Produces a NULL rather than an element.
Produces an element with no content (subject to change or removal).
Produces a zero-length result (subject to change or removal).
Produce elements with no content but containing attributes that read "nil=true" when serialized.
The following example produces a Customer element for each customer, with customer number and name attributes:
SELECT XMLSERIALIZE(CONTENT
XMLELEMENT(NAME "Customer",
XMLATTRIBUTES(CustNo,
SurName as LastName,
FirstName)
)
AS VARCHAR(200)) AS "CustomerList"
FROM customers;
Note: The XMLSERIALIZE function (see XMLSERIALIZE) converts the XML output of XMLELEMENT to VARCHAR in this example.
The result of the previous example follows:
CustomerList VARCHAR(200) --------------------------------------------------------------------------------- <-Customer CustNo="000001" LastName="Sturlasson" FirstName="Snorri"><-/Customer> <-Customer CustNo="000002" LastName="Skallagrimsson" FirstName="Eigil"><-/Customer> ---------------------------------------------------------------------------------
|
Copyright © 2014 CA.
All rights reserved.
|
|