这里我列出了一个xml。
<?xml version="1.0" encoding="utf-8" ?>
<data>
<dataitem>
qqqqqqq
</dataitem>
<templatedata>
<Year>2001</Year>
</templatedata>
<mailmergedata>
<row>
<facilityname>ABC Corporation</facilityname>
<dueamount>200.00</dueamount>
</row>
<row>
<facilityname>XYZ Corporation</facilityname>
<DueAmount>50.00</DueAmount>
</row>
</mailmergedata>
</data>
我想检索节点工具名称的值 有人请帮忙
答案 0 :(得分:1)
试试这个:
XDocument xmlFile = XDocument.Load("xml file path");
var query = from c in xmlFile.Descendants("facilityname ") select c;
然后
foreach (XElement element in query)
{
Console.WriteLine(element); // get your value here
}
参考Job Skeet的answer,这可能对您有帮助..
答案 1 :(得分:1)
您还可以使用XPathSelectElements,然后使用XPath进行导航:
xdoc.XPathSelectElements("/data/mailmergedata/row/facilityname")