Solved

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

Posted on 2015-01-24
4
683 Views
Last Modified: 2015-01-24
Hi,

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

Victor
0
Comment
Question by:vcharles
  • 2
  • 2
4 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40568178
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
 

Author Closing Comment

by:vcharles
ID: 40568198
Thank You.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40568205
Not a problem Victor, glad to help.
0
 

Author Comment

by:vcharles
ID: 40568275
Thank you.  
I will try the same approach to remove multiple data elements,
Victor
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question