Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing XML Node (C#) 1

Status
Not open for further replies.

annethorne

Programmer
Apr 13, 2005
28
0
0
US
Hello,

We are building a windows desktop application using C#
that reads in an xml file, to create a user interface.
The user then enters values into the user interface.
We want to be able to save an xml file with the same
schema as the original xml file, but with the users
entered values into it.

Here is a simple example as part of input document:

<label>
<name>Needs Cleaning</name>
<type>radio</type>
<value>
<choicelist>yes</choicelist>
<choicevalue></choicevalue>
<choicelist>no</choicelist>
<choicevalue></choicevalue>
</value>
</label>

We would want the output document to contain:


<label>
<name>Needs Cleaning</name>
<type>radio</type>
<value>
<choicelist>yes</choicelist>
<choicevalue>yes</choicevalue>
<choicelist>no</choicelist>
<choicevalue></choicevalue>
</value>
</label>

or perhaps

<label>
<name>Needs Cleaning</name>
<type>text</type>
<value>
<single>yes</single>
</value>
</label>


We aren't too adept at xmlTextReaders and xmlTextWriters yet,
and have been doing some research in Google.

There was an interesting article that seemed pertinent to this, but
it dealt with C++ :


Any help would be appreciated.

Thank you!
Anne
 
Load your XML file. Locate the nodes you wanna change. Whack in the values. Save it. Job done.
Code:
XmlDocument doc = new XmlDocument();
doc.Load("myXMLFile.xml");
XmlNode choiceValue = doc.SelectSingleNode("label/value/choicevalue");
choiceValue.Value = "yes";
doc.Save("userInput.xml");

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top