Read xml file and write ids' values into related textbox in C#
I have a xml file named "numbers.xml" like this:
<?xml version="1.0" encoding="utf-8" ?>
<program>
<box id="aaa" value="78678"/>
<box id="bbb" value="37287"/>
<box id="ccc" value="783"/>
<box id="ddd" value="7867"/>
<box id="eee" value="786"/>
<box id="fff" value="23"/>
<box id="ggg" value="453"/>
<box id="hhh" value="4537"/>
</program>
I want to read this xml file and fill textboxes. But in windows forms
application txtAAA.text value must take id="aaa" value which is 78678.
Likewise txtBBB.text value must take id="bbb" value which is 37287. How
can I do this?
Edit:
I tried like this:
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(openfiledialog1.FileName);
XmlNodeList nodelist = xmldoc.DocumentElement.ChildNodes;
XmlNode xmlnode = nodelist.Item(0);
txtAAA.Text = xmlnode.Attributes["id"].InnerText;
But "aaa" is shown in textbox. It was totally failure. –
No comments:
Post a Comment