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 a single-rooted XML document. DOCUMENT can include a declaration header or not. |
| CONTENT | Specifies that the content to be parsed must be a valid XML fragment. CONTENT must not include a declaration header; otherwise, an error will be returned. |
| value_expr | Specifies the string to be parsed. The result can be of the CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB character type. |
Note: If value_expr evaluates to NULL, the function will also return NULL. |
|
| WELLFORMED | If specified, the validity of the parsed content will not be checked. This is an optional parameter. |
Return type
XMLType data type.
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