I am having trouble reading in the XML file with my C# program. When i try to run it I get an error saying that "An unhandled exception of type 'System.Xml.XPath.XPathException' occurred in System.Xml.dll
Additional information: Expression must evaluate to a node-set."
XML Code:
<musicstore> <album> <name>Black Album</name> <artist>Metallica</artist> <year>1991</year> <price>$10.00</price> </album> <album> <name>Exodus</name> <artist>Bob Marley</artist> <year>1979</year> <price>$5.99</price> </album> </musicstore> C# Code:
XmlDocument xDoc = new XmlDocument(); xDoc.Load("C:\\Users\\FJam\\Desktop\\Coding\\XML\\text.xml"); foreach(XmlNode node in xDoc.SelectNodes("musicstore/album/")) { MessageBox.Show(node.SelectSingleNode("artist").InnerText); }
/onmusicstore/album/