Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2015-01-24
4
Medium Priority
?
854 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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

598 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