XMLPARSE
The XMLPARSE function parses the argument as an XML document and returns an XML value.
.-STRIP WHITESPACE--------. >>-XMLPARSE--(--DOCUMENT--+-string-expression-+--+-+---------------------+-+--)->< '-XML-host-variable-' '-PRESERVE WHITESPACE-'
The schema is SYSIBM.
- 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 character, graphic, or binary string.
string-expression must evaluate to a character string that conforms to the definition of a well-formed XML document as defined in XML 1.0.
- XML-host-variable
- An XML host variable that contains a well-formed XML document as defined in XML 1.0. XML-host-variable must not be binary XML data.
- STRIP WHITESPACE or PRESERVE WHITESPACE
- Specifies whether whitespace is to be removed or preserved. Any
DTD attributes for xml:space have no impact on whitespace handling.
- STRIP WHITESPACE
- Specifies that whitespace (space that is between element nodes
without any non-whitespace text nodes) will be stripped unless the
nearest containing element has a value of 'preserve' for the xml:space
attribute.
STRIP WHITESPACE is the default.
- PRESERVE WHITESPACE
- Specifies that all whitespace is preserved, even when the nearest containing element has a value of 'default' for the xml:space attribute.
The result of the function is XML. If string-expression can be null, the result can be null; if string-expression is null, the result is the null value.
Direct use of XMLPARSE with character string input: Applications should avoid direct use of the XMLPARSE function with character string input and should send strings that contain XML documents directly by using host variables to maintain the match between the external encoding and the encoding in the XML declaration. If XMLPARSE must be used in this situation, a BLOB type should be specified as the argument to avoid code page conversion.
INSERT INTO EMP (id, xvalue) VALUES(1001,
XMLPARSE(DOCUMENT :hv
PRESERVE WHITESPACE));
XMLPARSE
will treat the value in hv for the insert statement
as equivalent to the following value: <a xml:space='preserve'> <b> <c>c</c>b </b>
</a>
INSERT INTO EMP (id, xvalue) VALUES(1001,
XMLPARSE(DOCUMENT :hv
STRIP WHITESPACE));
XMLPARSE
will treat the value in hv for the insert statement
as equivalent to the following value: <a xml:space='preserve'>
<b xml:space='default'><c>c</c>b </b>
</a>