I am having a problem with the following – it does not appear to load my XML file. I want to load in the file and then use XMLNodeLlist to iterate through it and store my values. The XML File is in my Visual Studio 2010 solution. Is there something I am missing in the Path?
XmlDocument xml = new XmlDocument();
public Test()
{
xml.LoadXml(@"C:\Users\testuser\Desktop\TestWebsite\TestData.xml");
...more code
XmlDocument.LoadXml(stirng xml) is not expecting a file path but an actual xml string.
You could use XmlDocument.Load() and pass it a FileStream to you your document or a file path:
Even better than that would be to use the new XDocument object which has a load method that works directly with a file path, this is the preferred way of interacting with Xml in later versions of .NET and would recommend using this approach: