【发布时间】:2016-01-13 15:53:23
【问题描述】:
我编写了一个 c# 代码,它显示存储在 arraylist 中的值。
static void Main()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"C:\\shreyas\\NX_Temp\\NX_Temp\\000048_A\\CompareReport3D.xml");
XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("*");
List<XmlNode> returnedmatchNode=TraverseXml(nodeList);
for (int iIndex = 0; iIndex < returnedmatchNode.Count; iIndex++)
{
Console.WriteLine("values" +returnedmatchNode[iIndex].Value);
}
}
public static List<XmlNode> TraverseXml(XmlNodeList nodeList, int counter = 1)
{
List<XmlNode> matchNode = new List<XmlNode>();
foreach (XmlNode node1 in nodeList)
{
if (node1.Attributes != null && node1.Attributes["match"] != null)
{
matchNode.Add(node1.Attributes["match"]);
}
TraverseXml(node1.ChildNodes, counter);
}
Console.ReadLine();
return matchNode;
}
xml代码:
<?xml version="1.0" encoding="utf-8"?>
<xd:xmldiff version="1.0" srcDocHash="11928043053884448382" options="IgnoreChildOrder IgnoreNamespaces IgnoreWhitespace IgnoreXmlDecl " fragments="no" xmlns:xd="http://schemas.microsoft.com/xmltools/2002/xmldiff">
<xd:node match="2">
<xd:node match="2">
<xd:node match="19">
<xd:node match="2">
<xd:add>Y</xd:add>
</xd:node>
</xd:node>
<xd:add match="/2/2/11" opid="2" />
<xd:change match="18" name="OWNINGSITE">
<xd:node match="2">
<xd:remove match="1" />
</xd:node>
</xd:change>
<xd:add match="/2/2/2-9" opid="1" />
<xd:change match="17" name="STATUS">
<xd:node match="2">
<xd:remove match="1" />
</xd:node>
</xd:change>
<xd:remove match="14-16" />
<xd:remove match="13" subtree="no">
<xd:remove match="1-2" />
</xd:remove>
<xd:remove match="11" opid="2" />
<xd:remove match="10" />
<xd:remove match="2-9" opid="1" />
<xd:remove match="1" />
</xd:node>
<xd:node match="5">
<xd:node match="3">
<xd:node match="11">
<xd:change match="1">0,1,0,1,0,0,0,0,1</xd:change>
</xd:node>
</xd:node>
</xd:node>
</xd:node>
<xd:descriptor opid="1" type="move" />
<xd:descriptor opid="2" type="move" />
</xd:xmldiff>
我正在尝试显示返回的matchNode 的值。但它没有显示任何价值。我无法找出我的代码中的错误。
【问题讨论】:
-
在 Visual Studio 调试器中运行您的程序,设置断点,单步执行代码,检查变量并查看失败的地方
-
欢迎来到 StackOverflow!请提供minimal reproducible example,以便人们可以在他们自己的 PC 上实际重现您的问题。
-
您是否在调用
TraverseXml后验证了returnedmatchNode包含一个或多个值? -
您确定它不只是在等待您按回车每个节点一次 以通过所有这些读取行吗?还是 XML 真的很小
-
我确实检查了返回的matchNode 值。它没有给出任何价值