Search code examples
xmlvb6msxml

What is the easiest way of removing the attribute of a node of an xml file in vb?


I'm familiar with using the MSXML2 library for reading xml files. But is there an easy way of editing a particular node. Say I have the following line of code that selects a dataroot element that has the attribute generated:

Dim oDoc as MSXML2.DOMDocument
Dim oNode as MSXML2.IXMLDOMNode    

Set oDoc = ... //open xml file here//
Set oNode = oDoc.selectSingleNode("/root/dataroot/[@generated]")

I want to be able to remove the generated attribute from the selected node and save the change back to the original file.


Solution

  • To remove an attribute from an node:

    oNode.removeAttribute("generated");
    

    To save the changes:

    oDoc.save("changed.xml")