开发者

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

开发者 https://www.devze.com 2023-03-20 07:43 出处:网络
I\'m trying to get the value of attribute(memo) in an xml file using c#,also i want t开发者_Python百科o display the value(wonderful day) in a textbox .Can anyone help?

I'm trying to get the value of attribute(memo) in an xml file using c#,also i want t开发者_Python百科o 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号