Solved

Updating XML

Posted on 2009-05-13
1
200 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

929 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

6 Experts available now in Live!

Get 1:1 Help Now