Solved

Updating XML

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

18 Experts available now in Live!

Get 1:1 Help Now