Using MSXML3.0 with VB 6.0 - Manipulating the XML document
(Page 5 of 5 )
Updating a node value
Using the DOM API it is possible access a single node, although you need to do a node walk. In this example you will be updating the skill set of the student to a more current skill. The following code listing shows how you may change the skill, replacing the current skill. The following form was used in updating the "legacy skill" of student to a more recent skill.

When you click the button labeled "Update Student Skill," the form will be displayed as shown.

The code listing shown in the next paragraph was used to make the update shown above. The various methods and properties can be seen listed in the DoMDocument30 reference pictures shown earlier, taken from the object browser.
Private Sub Command1_Click()
Dim xdoc As DOMDocument30
Set xdoc = New DOMDocument30
xdoc.Load ("c:testWebStudents.xml")
Dim studentNode As IXMLDOMNode
Set studentNode = xdoc.documentElement.selectSingleNode("student")
Dim skillNode As IXMLDOMNode
Set skillNode = studentNode.selectSingleNode("legacySkill")
Debug.Print skillNode.nodeTypedValue
skillNode.nodeTypedValue = Text4.Text
Debug.Print skillNode.nodeTypedValue
xdoc.save "c:testWebStudents.xml"
WebBrowser1.Navigate2 ("c:testWebStudents.xml")
Text4.Text = ""
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate2 ("c:testWebStudents.xml")
End Sub
Summary
The tutorial is written for the VB programmer who wants to get his hands wet using XML in his applications. The developmental stages of the XML document are shown specifically for this user. Caution must be exercised while using the version as there are multiple versions. MSXML version 4.0 may not support some of the features of the earlier versions. It would be useful to add a web browser as shown in this tutorial to track as you develop the application.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |