开发者

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

开发者 https://www.devze.com 2023-03-02 17:52 出处:网络
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 e

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.


Remove the attribute from the Attributes collection of the node in question:

oNode.Attributes.removeNamedItem "generated"


To remove an attribute from an node:

oNode.removeAttribute("generated");

To save the changes:

oDoc.save("changed.xml")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号