Solved

Updating XML

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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