Hello there guys, im having little problem and help would be appreciated :)
I have few tags
<name>
<capacity>
<lectureslot>
<tutorialslot>
and so on, and i want to read each tag separatly into separate field(label), or listbox.
Here is part of my XML
<?xml version="1.0" encoding="utf-8"?>
<timetable>
<module code="3SFE504">
<name>Algorithms and Data Structures</name>
<capacity cap="5">5</capacity>
<semester sem="1">1</semester>
<prerequisite preq="none">none</prerequisite>
<lectureslot ls="0">Mon 9.00-11.00</lectureslot>
<tutorialslot ts="1">Mon 11.00-13.00</tutorialslot>
</module>
And my source code is
private void show_Click(object sender, EventArgs e)
{
//Clear all of the items out of the list box
modulelist.Items.Clear();
//String workingDir = Directory.GetCurrentDirectory();
//XmlTextReader textReader = new XmlTextReader(workingDir + @"\xmlmodulelist.xml");
//the path to the xml file
string path = "xmlmodulelist.xml";
XmlDocument CXML = new XmlDocument();
CXML.Load(@"xmlmodulelist.xml");
//Open the filestream
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//load the xml into the XmlDocument
CXML.Load(fs);
for (int i = 0; i < CXML.DocumentElement.ChildNodes.Count; i++)
{
//Add the innertext of the xml document to the listbox
//modulelist.Items.AddRange(new object[] { CXML.DocumentElement.ChildNodes[i].InnerText });
//XmlNode name = CXML.GetElementsByTagName("name")[0];
modulelist.Items.AddRange(new object[] { CXML.DocumentElement.GetElementsByTagName("name")[0]});
// modulelist.Items.AddRange(XmlNodeType.Text);
}
//Close the filestream
fs.Close();
}
And when show_click button is pressed it loads into listbox this
System.Xml.Xml.Element instead of Name Why is that ??