Windows Develop Bookmark and Share   
 index > Windows Forms General > Loading a Xml file to two different multiline textboxes
 

Loading a Xml file to two different multiline textboxes

Hi all,

I have the following problem:
I want to readout an XML file of wich the structure is as follows:
<?xml version="1.0"?>
<Questions>
<Question id="1">
<q>1+1</q>
<a>2</a>
</Question>
</Questions>
The purpose is that all the texts of all the q elements must be written in a textfield and all the a elements must be written in an other textfield. I have tried many non succesfull ways, so I hope you can help me.

Preceding thanks for your help,
Bas de Kwant



Bas de Kwant  Monday, December 22, 2008 12:20 PM
You can use an XmlDocument to read the xml and extract the infos. Here's a way to do it :

XmlDocument oDoc = new XmlDocument();

oDoc.Load(Application.StartupPath + "\\test.xml");
XmlNodeList listnodes = oDoc.SelectNodes(@"//Question");

foreach (XmlNode node in listnodes)
{
this.textBox1.Text += node["q"].InnerText + Environment.NewLine;
this.textBox2.Text += node["a"].InnerText + Environment.NewLine;
}
  • Marked As Answer byBas de Kwant Monday, December 22, 2008 1:53 PM
  •  
nikho  Monday, December 22, 2008 1:44 PM
You can use an XmlDocument to read the xml and extract the infos. Here's a way to do it :

XmlDocument oDoc = new XmlDocument();

oDoc.Load(Application.StartupPath + "\\test.xml");
XmlNodeList listnodes = oDoc.SelectNodes(@"//Question");

foreach (XmlNode node in listnodes)
{
this.textBox1.Text += node["q"].InnerText + Environment.NewLine;
this.textBox2.Text += node["a"].InnerText + Environment.NewLine;
}
  • Marked As Answer byBas de Kwant Monday, December 22, 2008 1:53 PM
  •  
nikho  Monday, December 22, 2008 1:44 PM
Thank you very much!
Your solution works!
Bas de Kwant  Monday, December 22, 2008 1:54 PM

You can use google to search for other answers

Custom Search

More Threads

• Winforms - error logging
• How can I copy and paste custom objects in VS 2003 or VS2005? Is it possible?
• Reading and writing in application.config file.
• Controls Based on Control Class Can't be Transparent?
• OpenType font as embedded resource
• Disable Key press in Windows form
• uggh! why is this tab-control code not working!!
• Links in a FormsApp and controlling the browser
• connection to as400 question
• refrsh in c#