troubleshooting Question

How to save an XMLNodeList back to an XMLDocument

Avatar of brgdotnet
brgdotnetFlag for United States of America asked on
Visual Basic.NETC#XML
1 Comment1 Solution118 ViewsLast Modified:
My question is in regards to editing an xml document in and then saving the changed document. So I am looking for help from an expert who has worked with xml documents using or C#. My particular example is in

Example :
For my XML document below I have an xml document with different soccer teams, along with information related to the team.
I just want to be able to read through the document and change values in the file an re-save it.

My approach below is that I read the document into an XMLNodeList. In my example I am changing the city name using .innerText assignment. So once my XMLNodeList object has been edited, how do I save it back to an XML document format with the same structure as the original XMLDocument?

Dim cfg As New XmlDocument()
Dim myNode As XmlNode
Dim myList As XmlNodeList

Dim myList As XmlNodeList
myList = cfg.SelectNodes("descendant::Category/Item")

for Each nd As Xml.XmlNode in myList

If nd.InnerText = "City" Then
nd.InnerText = "AllTheSame"

End If

<?xml version ="1.0" standalone ="yes"?>
<Settings xmlns:xsi="http://www.w3.or/2001/XMLSchema-instance">
<Category name="Soccer">
<Item name = "TeamName">ThunderBolts</Item>
<Item name = "City">Toronto</Item>
<Item name = "Captain">Farver</Item>
<Category name="Baseball">
<Item name = "TeamName">Mavericks</Item>
<Item name = "City">Los Angeles</Item>
<Item name = "Captain">Buckley</Item>
Miguel Oz
Senior Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2009

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros