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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to populate forms with data from XML 1

Status
Not open for further replies.

ozane

Technical User
Feb 3, 2005
57
TR
i have a an xml file and would like to extract the elements from xml and popoulate the text boxes in the web form with those data. but couldnt solve it.
i am confused actually..
any idea?
Thanks
 
Here is simple example. There are many other ways to do this.

private void Page_Load(object sender, System.EventArgs e)
{

//Use an xmlDocument
XmlDocument doc = new XmlDocument();

//Load the XML document. You can also load from a file
doc.LoadXml(@"<root>
<category name='name'>innerCat1
<element att1='dd' att2='Sfw' att3='value' />
</category>
<category name='name2'>innerCat2
<element att1='value' att2='value' att3='value' />
</category>
</root>");
//Use XPath to select nodes
XmlNode node = doc.SelectSingleNode(@"root/category");

//Assign values to textboxes
//Value form element
TextBox1.Text = node.SelectSingleNode("element").Attributes["att1"].Value;
//Value from node inner text
TextBox2.Text = node.InnerText;

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top