XMLPARSE

The XMLPARSE function parses the arguments as an XML document and returns an XML value.

Read syntax diagramSkip visual syntax diagramXMLPARSE (DOCUMENTstring-expressionSTRIP WHITESPACEPRESERVE WHITESPACE)
DOCUMENT
Specifies that the character string expression to be parsed must evaluate to a well-formed XML document that conforms to XML 1.0.
string-expression
An expression that returns a value that is a built-in character, Unicode graphic, or binary string. If a parameter marker is used, it must be explicitly cast to one of the supported data types.
STRIP WHITESPACE or PRESERVE WHITESPACE
Specifies whether or not whitespace in the input argument is to be preserved. If neither is specified, STRIP WHITESPACE is the default.
STRIP WHITESPACE
Specifies that whitespace characters will be stripped unless the nearest containing element has the attribute xml:space='preserve'. The whitespace characters in the CDATA section are also affected by this option.
PRESERVE WHITESPACE
Specifies that all whitespace is to be preserved, even when the nearest containing element has the attribute xml:space='default'.

The result of the function is XML. If the result of string-expression can be null, the result can be null; if the result of string-expression is null, the result is the null value. The CCSID of the result is determined from string-expression. If string-expression has a CCSID of 65535, the value from the SQL_XML_DATA_CCSID QAQQINI option is used.

The input string may contain an XML declaration that identifies the encoding of the characters in the XML document. The encoding in the XML declaration must match the encoding of the string-expression.

Examples

Example 1: Insert an XML document into the EMP table and preserve the whitespace in the original XML document.

  INSERT INTO EMP (ID, XVALUE) VALUES(1001,
     XMLPARSE(DOCUMENT '<a xml:space=''preserve''> <b> <c>c</c>b </b> </a>'
              PRESERVE WHITESPACE))
XMLPARSE will treat the value for the insert statement as equivalent to the following value:
<a xml:space='preserve'> <b> <c>c</c>b </b> </a>

Example 2: Insert an XML document into the EMP table and strip the whitespace in the original XML document.

  INSERT INTO EMP (ID, XVALUE) VALUES(1001,
     XMLPARSE(DOCUMENT 
               '<a xml:space=''preserve''> <b xml:space=''default''> <c>c</c>b </b> </a>'
              STRIP WHITESPACE))
XMLPARSE will treat the value for the insert statement as equivalent to the following value:
<a xml:space='preserve'> 
<b xml:space='default'><c>c</c>b </b> 
</a>