Home > Articles > Web Services > XML

  • Print
  • + Share This
Like this article? We recommend

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):

  1. Find the desired record.
  2. Parse the XML markup into a DOM tree.
  3. Update the nodes in the DOM tree.
  4. Store the new XML markup into the database field.
  5. 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,_ 
Set DOM = Server.CreateObject("MSXML.DOMDocument")

Set XNode = DOM.selectSingleNode("//Color")
If XNode Is Nothing Then
 NewXMLTextElement DOM,"Color","Blue",Null
 XNode.text = "Blue"
End If

RS("XMLData") = DOM.xml

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.

  • + Share This
  • 🔖 Save To Your Account