Solved

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

Posted on 2015-01-24
4
635 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now