我有一个 xml 文件的片段,如下所示:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="wa_xml2html.xsl"?>
<computeraudit>
<title>Computer Audit :: 11/13/2012 10:43:22 AM</title>
<category title="Loaded Modules">
<subcategory title="">
<recordset title="">
<fieldname>Name</fieldname>
<fieldname>Version</fieldname>
<fieldname>Modified</fieldname>
<fieldname>Manufacturer</fieldname>
<datarow>
<fieldvalue>XmlLite.dll</fieldvalue>
<fieldvalue>1.3.1000.0</fieldvalue>
<fieldvalue>7/13/2009 8:16:21 PM</fieldvalue>
<fieldvalue>Microsoft Corporation</fieldvalue>
</datarow>
<datarow>
<fieldvalue>zip.dll</fieldvalue>
<fieldvalue>6.0.250.6</fieldvalue>
<fieldvalue>5/25/2011 8:30:12 AM</fieldvalue>
<fieldvalue>Sun Microsystems, Inc.</fieldvalue>
</datarow>
</recordset>
</subcategory>
</category>
</computeraudit>
我正在尝试使用 C# XPath 解析它并获取每个 fieldvalue 元素值。
c# 代码如下所示:
XPathNavigator nav;
XPathDocument docNav;
XPathNodeIterator NodeIter;
String strExpression;
docNav = new XPathDocument(@"C:\TEMP\WinAudit\test.xml");
nav = docNav.CreateNavigator();
strExpression = "/computeraudit/category[@title=\"Loaded Modules\"]/subcategory/recordset/datarow";
NodeIter = nav.Select(strExpression);
while (NodeIter.MoveNext())
{
Console.WriteLine(NodeIter.Current.Value);
}
Console.ReadLine();
它为每个数据行节点返回一行,其中所有字段值元素值连接在一起。
如何为每个 fieldvalue 元素返回每个不同的值?