I have following xml data.
<?xml version="1.0" encoding="utf-8" ?>
<mail>
<id>signUpConfirmation</id>
<subject>Activation</subject>
<body>
Hi, You account is activated \nRegards
</body>
</mail>
I need to read value from <body>
tag depending on id I pass.
This is what I have tried
var xml = File.ReadAllText("C:\\Users\\DELL\\Documents\\Visual Studio 2012\\Projects\\Website\\Website\\Files\\Mails.xml");
var str = XElement.Parse(xml);
var result = from mail in str.Elements("mail")
where (string)mail.Element("id") == "signUpConfirmation"
select (string)mail.Element("body");
log.Debug("mail data:" + result.First());
I get error :
Sequence contains no elements.
Also, I want to access the value of id tag as well in the same query.