Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to update XML file in

Posted on 2004-10-18
Medium Priority
Last Modified: 2010-04-17
How to update xml file through ASP.NET. For Example I have a XML File with the following details

- <Suppliers>
- <Provider>
  <Address1>Sathasivam Nagar</Address1>
  <Address1>Shivaji Nagar</Address1>
- <Provider>
  <Address1>BDA Layour</Address1>
  <ZIP>560 017</ZIP>

I want to update this xml file corresponding to the userid tag. for example i want to update the address1 and addreess2 tag for userID 12345.

suggest me how to do this, give me some sample example that would reach my requirement

Question by:mohan21_kumar
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

Expert Comment

ID: 12337228
use the System.Xml.XmlDocument class..
you can use LoadXml() method to load the xml string into the object..
then use SelectNodes() method to get all nodes that match the given criteria..
as an example:

XmlDocument xml = new XmlDocument();
XmlNodeList lst = xml.xml.SelectNodes("/*/Provider[UserID='12345']");
foreach(XmlNode node in lst)
  node.SelectSingleNode("Address1").InnerText = "1st Address";

you may need to to learn about xpath
LVL 21

Accepted Solution

MogalManic earned 75 total points
ID: 12337328
There are two design patterns that I have used.

  1) Have a Template.XML document that defines the generic XML format and do code like this:
        XmlDocument tempXML= new XmlDocument();
        XmlDocument outXML = new XmlDocument();
        XmlNode tempNode= outXML.xml.SelectSingleNode("/Suppliers/Provider");

  2) Write an XSLT stylesheet that adds/deletes/updates nodes of an XML document
        XmlDocument XML= new XmlDocument();
        XmlDocument style = new XmlDocument();
        /*Pass parameters to stylesheet (I'm not sure on the actual syntax for*/
        style.setParameter('action', 'addNode')
        style.setParameter('userID', ???);
        style.setParameter('Name, ???);
        style.setParameter('Address1', ???);


Expert Comment

ID: 12340799
Why not use a dataset. I believe you can load the document into the dataset and work with it from there.


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

715 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