- Creating the Database Structure
- Inserting the Data?
- Retrieving the Data?
- Querying the Database?
- Updating the Records?
- Summary?
Updating the Records
The database update process is straightforward if you do the updates in the SQL client (on the workstation or in the server-side script):
- Find the desired record.
- Parse the XML markup into a DOM tree.
- Update the nodes in the DOM tree.
- Store the new XML markup into the database field.
- Update the database record.
For example, to set the color of the product #7 to blue, use the code shown in Listing 13.
Listing 13 Set the color of product #7 to blue
Set RS = Server.CreateObject("ADODB.Recordset") RS.Open "Select * From Products Where ProductID = 7",db,_ adOpenKeyset,adLockOptimistic Set DOM = Server.CreateObject("MSXML.DOMDocument") DOM.loadXML(RS("XMLData").Value) Set XNode = DOM.selectSingleNode("//Color") If XNode Is Nothing Then NewXMLTextElement DOM,"Color","Blue",Null Else XNode.text = "Blue" End If RS("XMLData") = DOM.xml RS.Update
Yet again, both MySQL and SQL Server offer functions that can help you update XML data in stored procedures executed on the server.
You could use the UpdateXML function in MySQL to replace an XML fragment with a new value and the modify method of the XML data type in SQL server 2005 to perform modifications (insertions, deletions or replacements) to the XML markup.