Database Reference
In-Depth Information
XMLType datatype simply replaces the entire document. The easiest
method of changing XML document content is using the UPDATEXML
function.
UPDATEXML(XMLType object, search path, expression [, search
path, expression ], 'replace string') . The UPDATEXML function can
be used to change pattern-matched parts of XML documents.
There are some important things to remember about the UPDA-
TEXML function:
UPDATEXML can be used to update single tags, tag attributes, and
even entire subtrees.
Deleting XML document content is essentially the same as updating.
If a value is to be removed, simply find it and set it to NULL using
UPDATEXML.
Remember that the UPDATEXML function can only find and
update what already exists in the XML structure. If some values are
null valued when initially creating an XML document from relational
tables, those values will not exist in the XML document at all, not
even as tags. The only method of using UPDATEXML in this situa-
tion is to edit an entire parent tag.
Let's change Mozart's name and city as shown in Figures 17.15, 17.16,
and 17.17. The result is shown in Figure 17.18.
SET LONG 2000 WRAP ON LINESIZE 5000;
UPDATE XML SET XML =
UPDATEXML(XML, '/Artist/City/text()', 'Wien')
WHERE ID = 12;
UPDATE XML SET XML =
UPDATEXML(XML, '/Artist/@Name', 'Wolfgang Amadeus Mozart')
WHERE ID = 12;
SELECT X.XML.EXTRACT('/*') FROM XML X WHERE X.ID = 12;
 
Search WWH ::




Custom Search