score:2

Accepted answer
  • Use XDocument.Parse() to create a document supporting XML declaration
  • To get units, use

    XDocument.Parse("...").Root // or Element("email")
        .Elements("meta")
            .Elements("smartForm")
                .Elements("unit");
    
  • or use XPath: email/meta/smartForm/unit

  • also you can use query-style:

    var doc = XDocument.Parse("...");
    var q = from meta in doc.Root.Elements("meta")
            from smartForm in meta.Elements("smartForm")
            from unit in smartForm.Elements("unit")
            select unit;
    

score:1

The following works for me:

var xd = XDocument.Load("Test.xml");
var xv = XDocument.Parse((string)xd.Root.Element("value"));
Console.WriteLine(xv.Root.Elements().Count());

Output is 2, for ForgotPassword and ForgotUsername.

score:0

For #1:

XElement doc = XElement.Load(file);
XElement valueElement = doc.Element("value");
string value = (string)valueElement;

Related Articles