Purpose
This function parses the input string and generates an XMLType data type.
Syntax
XMLPARSE
({ DOCUMENT | CONTENT } value_expr [ WELLFORMED ])
Parameters
| Field | Description |
|---|---|
| DOCUMENT | Specifies that the content to be parsed must be an XML document with a single root node. The DOCUMENT option can include a declaration header or not. |
| CONTENT | Specifies that the content to be parsed must be a valid XML fragment. The CONTENT option does not include a declaration header; otherwise, an error will occur. |
| value_expr | Specifies the string to be parsed. The result can be of the CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB character type. |
Note: If the result of value_expr is NULL, the function will also return NULL. |
|
| WELLFORMED | If this option is specified, the validity of the parsed content will not be checked. This option is optional. |
Return type
XMLType.
Examples
# Parse a valid XML fragment 'abc'
obclient> SELECT XMLPARSE(CONTENT '<a>abc</a>') FROM DUAL;
+-------------------------------+
| XMLPARSE(CONTENT'<A>ABC</A>') |
+-------------------------------+
| <a>abc</a>
|
+-------------------------------+
1 row in set
# Parse an XML document
obclient> SELECT XMLPARSE(DOCUMENT '<?xml version="1.0" encoding="UTF-8" ?><body>135 <purchaseOrder poNo="12435">
<customerName> Enterprises</customerName>
<itemNo>123456</itemNo>
</purchaseOrder></body>'
WELLFORMED) AS PRO FROM DUAL;
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| PRO |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| <?xml version="1.0" encoding="UTF-8"?>
<body>135 <purchaseOrder poNo="12435">
<customerName> Enterprises</customerName>
<itemNo>123456</itemNo>
</purchaseOrder>
</body>
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set