Modify XML document using C#

Hi,
I am using C#  and I would like to programmatically modify an XML file and save it back to my C: drive.

I have 1000 main elements and within each of those there a child node element values that need to be altered.

Is there a really quick and effective way of doing this?

Thanks for your help.



 
IbsAsked:
Who is Participating?
 
lucky_jamesConnect With a Mentor Commented:
one more, using xmldocument, for modifying and saving the xmls:
http://support.microsoft.com/kb/301233
0
 
lucky_jamesCommented:
xml operations can be seen at:
http://www.codersource.net/csharp_xml_file_operations.html

Hope it helps.
0
 
vjc2003Connect With a Mentor Commented:
Follow these steps:
1. Load the XML Doc
2. Select the nodes you want to modify
3. Loop through the selected nodes and modify the element values
And you are done.. :)

I'm attaching Dummy code..
Dim xDom As New XmlDocument
Dim xNodes as XmlNodeList
xDom.Load(strFileName)
xNodes = xDom.SelectNodes(NAME_OF_MAIN_ELEMENT)  
For Each xNode as XmlNode in xNodes
'//get OR set element value:
strElemenValue = xNode.Attributes.GetNamedItem(NAME_OF_ELEMENT).InnerText
Next

Open in new window

0
 
IbsAuthor Commented:
Thanks! Both very useful.
0
All Courses

From novice to tech pro — start learning today.