Solved

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

Posted on 2015-01-24
4
748 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 63

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 63

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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

724 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