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

本文关键字:xml 检索 节点 文件 读取 使用 | 更新日期: 2023-09-27 18:02:16

我试图在使用c#的xml文件中获得属性(备忘录)的值,我也想在文本框中显示值(美好的一天)。有人可以帮助吗?

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

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

看看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;

输出:Wonderful day