Karthik
Karthik

Reputation: 318

Read an xml file and retrieve xml node Value using c#

I'm trying to get the value of attribute(memo) in an xml file using c#,also i want to display the value(wonderful day) in a textbox .Can anyone help?

<tree>
  <Product comment=" C# "  memo="Wonderful day" /> 
 </tree>

Upvotes: 0

Views: 1535

Answers (2)

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56162

var xml=@"<tree>
<Product comment="" C# ""  memo=""Wonderful day"" /> 
</tree>";

var doc = XDocument.Parse(xml);

var memo = doc.Document.Descendants("Product").Single().Attribute("memo").Value;

Output: Wonderful day

Upvotes: 1

m.edmondson
m.edmondson

Reputation: 30862

Take a look at XPath

Upvotes: 2

Related Questions