[英]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?我正在尝试使用 c# 在 xml 文件中获取属性(备忘录)的值,我还想在文本框中显示值(美好的一天)。有人可以帮忙吗?
<tree>
<Product comment=" C# " memo="Wonderful day" />
</tree>
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
Output:
Wonderful day
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.