Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Updating XML

Posted on 2009-05-13
1
Medium Priority
?
206 Views
Last Modified: 2012-05-06
I have several text boxes which I'm using to update an XML document (customers field, with title, initial, firstname, surname).  So anyway I'm trying to minimise code by not having several lines like this:
node.Attributes.GetNamedItem("firstname").Value = txtFirstname1.Text;
node.Attributes.GetNamedItem("firstname").Value = txtFirstname2.Text;
node.Attributes.GetNamedItem("firstname").Value = txtFirstname3.Text;
node.Attributes.GetNamedItem("firstname").Value = txtFirstname4.Text;
etc

What would be the best way to keep code small and tight, and update each attribute with the value in the text box?  I thought of using a foreach(Control... but what would I do then?  I can't really guarantee the order (as far as I know) that they would be added to a list, and would be unable to tell which customer it is.  

All help is greatly appreciated.
0
Comment
Question by:angus_young_acdc
1 Comment
 
LVL 16

Accepted Solution

by:
ToddBeaulieu earned 1500 total points
ID: 24377644
w/o creating a test project to get the exact syntax down, I'll take a stab...

If you assign a Tag to each control, setting it's value to be the name of the Xml attribute, you could enumerate all controls and if a Tag is present, set the corresponding attribute's value. I don't know off the top of my head the correct approach to getting/setting the attribute, but it might be along the lines of attempting to get it, and if found, set it. If not found, create it/set it.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

972 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