I need to look in a XML document embedded into my VS project(using 2013) and pull out specific elements to use as strings in my application. I have tried going with an XMLReader, XmlDocument and LINQ and for some reason I can't figure out how to pull elements into my code. I haven't found MSDN to be very helpful thus far and I've been googling this for hours. I have never built an app in C# that uses external file, I could really use some guidance on how to approach this? Here is the last thing that I've tried:
XmlDocument doc = new XmlDocument();
doc.Load(@"XML FILEPATH");
// Create an XmlNamespace Manager to resolve the default namespace
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("cfg","urn:config-schema");
XmlNode writeDir;
XmlElement root = doc.DocumentElement;
writeDir = root.SelectSingleNode("descendant::cfg:write_directory",nsmgr);
Console.WriteLine(writeDir.OuterXml);
Console.ReadLine();
My XML looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<settings smlns="urn:config-schema">
<write_directory>"WRITEDIRECTORYLOCATION"</write_directory>
<read_directory>"READDIRECTORYLOCATION"</read_directory>
</settings>
I haven't had much experience with XML's so forgive me if this is sloppy. Thanks everyone!
smlnsa typo? because as written, that doesn't declare an xml namespace