Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 900
  • Last Modified:

Help with renaming data element in xml file using VB.NET

Hi,

How do you rename a data element in an xml file using Vb.NET?

Victor
0
vcharles
Asked:
vcharles
  • 2
  • 2
1 Solution
 
Fernando SotoCommented:
Hi Victor;

Try this.

'' Load the XML document
Dim xdoc = XDocument.Load("Path to the document")
'' The new Node name to replace the one in the document
Dim nodeToRename As String = "TotalWeight"

'' Get a list of all the nodes to be renamed
Dim nodes = (From x In xdoc.Descendants(nodeToRename) _
             Select x).ToList()

'' Change the node name
For Each node As XElement In nodes
    node.Name = "New Node Name Here"
Next

xdoc.Save("Path to save the document to")

Open in new window

0
 
vcharlesAuthor Commented:
Thank You.
0
 
Fernando SotoCommented:
Not a problem Victor, glad to help.
0
 
vcharlesAuthor Commented:
Thank you.  
I will try the same approach to remove multiple data elements,
Victor
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now