Purpose
XMLPARSE() parses the input string and generates XMLType data.
Syntax
XMLPARSE
({ DOCUMENT | CONTENT } value_expr [ WELLFORMED ])
Parameters
| Parameter | Description |
|---|---|
| DOCUMENT | Specifies that the input string must be a singly rooted XML document. DOCUMENT can be specified with or without a declaration header. |
| CONTENT | Specifies that the input string must be a valid XML fragment. CONTENT must be specified without a declaration header. Otherwise, an error is reported. |
| value_expr | The input string to be parsed. The data type of the string can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB. |
Note: If the value_expr expression evaluates to NULL, the function returns NULL. |
|
| WELLFORMED | Optional. If WELLFORMED is specified, the database does not perform validity checks to ensure that the input string is well-formed. |
Return type
The return type is XMLType.
Examples
# Parse the 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