Purpose
DELETEXML() deletes one or more nodes that match the XPath expression from the target XML document.
Syntax
DELETEXML( XMLType_instance, XPath_string [, namespace_string ])
Parameters
| Parameter | Description |
|---|---|
| XMLType_instance | The XMLType instance that represents the target XML document. |
| XPath_string | The XPath expression that indicates the one or more nodes to be deleted. You can use an absolute path (starting with a slash) or a relative path (with the initial slash omitted). If the initial slash is omitted, the context of the relative path is the root node by default. All child nodes of the nodes specified by XPath_string will also be deleted. |
| namespace_string | The namespace information for XPath_string. This parameter is optional. |
Return type
The return type is XMLType.
Examples
Call
DELETEXML()to delete the matching nodes from the target XML document, which is<bookstore>and its child nodes. The XPath expression is/bookstore/author, indicating that the<author>node under the<bookstore>node is to be deleted. The query result is renamed asresultby using theASkeyword. Finally, the result is retrieved from thedualtable.SELECT DELETEXML( XMLtype('<bookstore> <book att="old"></book> <author>carrot</author> </bookstore>'), '/bookstore/author' ) AS result FROM dual;The return result is as follows:
+-----------------------------------------------+ | RESULT | +-----------------------------------------------+ | <bookstore> <book att="old"/> </bookstore> | +-----------------------------------------------+ 1 row in setDelete all child nodes and retain the namespace of the parent node.
SELECT DELETEXML( xmltype( '<a xmlns="ns1" xmlns:f="ns2"> <f:b b1="b1" b2="b2">bbb1</f:b> <b b1="b1" b2="b2">bbb2</b> </a>' ), '/a/*', 'xmlns="ns1"' ) FROM dual;The return result is as follows:
+----------------------------------------------------------------------------------------------------------------------------------+ | DELETEXML(XMLTYPE('<AXMLNS="NS1"XMLNS:F="NS2"><F:BB1="B1"B2="B2">BBB1</F:B><BB1="B1"B2="B2">BBB2</B></A>'),'/A/*','XMLNS="NS1"') | +----------------------------------------------------------------------------------------------------------------------------------+ | <a xmlns="ns1" xmlns:f="ns2"/> | +----------------------------------------------------------------------------------------------------------------------------------+ 1 row in set