<config>
<timeDifferenceFields>
<TimeDifference>
<StartTimeField>txt_SoReinigungUhrzeitvonZ1</StartTimeField>
<EndTimeField>txt_SoReinigungUhrzeitbisZ1</EndTimeField>
<OutputTimeField>txt_SoReinigungZ1</OutputTimeField>
</TimeDifference>
<TimeDifference>
<StartTimeField>txt_SoReinigungUhrzeitvonZ2</StartTimeField>
<EndTimeField>txt_SoReinigungUhrzeitbisZ2</EndTimeField>
<OutputTimeField>txt_SoReinigungZ2</OutputTimeField>
</TimeDifference>
<TimeDifference>
<StartTimeField>txt_SoReinigungUhrzeitvonZ3</StartTimeField>
<EndTimeField>txt_SoReinigungUhrzeitbisZ3</EndTimeField>
<OutputTimeField>txt_SoReinigungZ3</OutputTimeField>
</TimeDifference>
</timeDifferenceFields>
</config>
您好,
有人可以帮我完成这个简单的任务,我不明白......
我想迭代上面的XML-File中的TimeDifference-Fields。对于每个TimeDifference节点,我想调用具有给定XML值的方法。
这样就会遇到NPE ......有人可以帮忙吗
XmlDocument configDoc = new XmlDocument();
configDoc.Load(configXml);
XmlNode timeFields = configDoc.SelectSingleNode("/config/timeDifferenceFields/TimeDifference");
foreach (XmlNode timeNode in timeFields)
{
String OutputTimeField = timeNode.SelectSingleNode("OutputTimeField").InnerXml;
String StartTimeField = timeNode.SelectSingleNode("StartTimeField").InnerXml;
String EndTimeField = timeNode.SelectSingleNode("EndTimeField").InnerXml;
addTimeDiffElement(inputDoc, OutputTimeField, StartTimeField, EndTimeField);
}
答案 0 :(得分:1)
SelectSingleNode
返回(顾名思义)不超过一个节点。请尝试使用XmlNodeList timeFields = configDoc.SelectNodes("/config/timeDifferenceFields/TimeDifference")
。