简体   繁体   中英

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>

Take a look at XPath

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM