As an extension of the XQuery language, XML DML provides greater flexibility for XML data operations rather than simply querying the XML data. With XML DML, users can insert, update, and delete node contents in XML as they do with relational tables. XML DML needs to be invoked through the Modify method of the XML data type.
1. Insert
Inserts are used to insert a child node or sibling node of a node that is identified by the Expression1 as one or more nodes of the Expression2 identity. The syntax format is as follows:
insert
Expression1 (
{as first | as last} into | after | before
Expression2
)
Expression1 and Expression2
Identifies one or more nodes to insert. It can be a constant XML instance, or it can be an XQuery expression. The expression can draw a node, a text node, or a set of ordered nodes, but it cannot solve the root node. If the expression results in a value or a set of values, the values are inserted as a single text node, separated by a space between the values. If multiple nodes are specified as constants, the nodes are enclosed in parentheses and separated by commas. However, you cannot insert a heterogeneous sequence (such as a group element, attribute, or value). If Expression1 an empty sequence, the insert operation does not occur and no errors are returned.
Into
Expression1 The identified node is inserted as a child of the node identified by Expression2. If a node in Expression2 already has one or more child nodes, you must specify the desired new node add location using as a or last.
After
The Expression1-identified node is inserted directly behind it as a sibling of the node identified by Expression2, and the After keyword cannot be used to insert the property.
Before
The Expression1-identified node is inserted directly in front of the sibling node of the Expression2-identified node, and the Before keyword cannot be used for insert properties.