1
<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>

Hi,

can someone help me with this easy task, I dont get it...

I want to iterate over the TimeDifference-Fields in the above XML-File. For each TimeDifference Node I want to call a method with the given XML-Values.

With this it runs into a NPE ... can someone help please

     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);
        }
1

1 Answer 1

1

SelectSingleNode returns (as the name suggests) not more than one node. Try XmlNodeList timeFields = configDoc.SelectNodes("/config/timeDifferenceFields/TimeDifference") instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.