简体   繁体   English

读取 xml 文件并使用 c# 检索 xml 节点值

[英]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>

Take a look at XPath看看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 Output: Wonderful day

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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