Results 1 to 4 of 4
Thread: XML Reading
-
09-09-2011 #1
XML Reading
What I am reading:
How would I go about reading the child elements of ( Employee )?Code:<?xml version="1.0" encoding="utf-8"?> <Employees> <Employee> <Name>Andrew</Name> <Salary>9999</Salary> </Employee> <Employee> <Name>Joe</Name> <Salary>9998</Salary> </Employee> <Employee> <Name>Smith</Name> <Salary>9997</Salary> </Employee> </Employees>

-
09-09-2011 #2
Re: XML Reading
probably not the best way but,
Code:XmlTextReader reader = new XmlTextReader("books.xml"); while (reader.Read()) { if (reader.Name == "Name") { reader.Read(); string Name = reader.Value; } if (reader.Name == "Salary") { reader.Read(); string Salary = reader.Value; } } reader.Close();
-
09-09-2011 #3
Re: XML Reading
Code:XmlDocument doc = new XmlDocument(); doc.load(URL/PATH); try { XmlNodeList nodes = doc.SelectNodes("Employees/Employee"); foreach (XmlNode node in nodes) { string name = node.SelectSingleNode("Name").InnerText; string salary = node.SelectSingleNode("Salary").InnerText; ListView1.Items.Add(new ListViewItem(new string[] {name, salary})); } } catch (Exception ex) { }Last edited by Liam; 09-09-2011 at 10:15 AM.
-
The Following User Says Thank You to Liam For This Useful Post:
andrew74 (09-09-2011)
-
09-09-2011 #4
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)



LinkBack URL
About LinkBacks
Reply With Quote




Bookmarks