EDN Admin
Well-known member
I am trying to loop over some XML, taking a set of nodes as a group, looking at a few values for sub nodes, modifying them, and then doing the same to the next set of nodes.
Here is my XML:
<pre class="prettyprint <simplemath>
<problem>
<operator>+</operator>
<operand1>13</operand1>
<operand2>12</operand2>
<result>blank</result>
</problem>
<problem>
<operator>*</operator>
<operand1>4</operand1>
<operand2>14</operand2>
<result>blank</result>
</problem>
</simplemath>[/code]
<br/>
In my code, I get an XPathNavigator to the first problem by using a selectSingleNode("/simplemath/problem") call.
I then try to call a method to do some stuff to this XPathNavigator with a method doMath(myxpathnav).
My doMath definition:
<pre class="prettyprint private static void doMath(XPathNavigator xpn)
{
XPathNavigator oper1 = xpn.SelectSingleNode("/simplemath/problem/operand1");
XPathNavigator oper2 = xpn.SelectSingleNode("/simplemath/problem/operand2");
XPathNavigator result = xpn.SelectSingleNode("/simplemath/problem/result");
string new_result = "";
// do a add/multiple/divide/whqatever and save the result
// as a string in new_result
// EX: 12 + 13 = 25
result.SetValue(new_result);
return;
[/code]
<br/>
What I expect my end result XML to be is as follows:
<pre class="prettyprint <simplemath>
<problem>
<operator>+</operator>
<operand1>13</operand1>
<operand2>12</operand2>
<result>13 + 12 = 25</result>
</problem>
<problem>
<operator>*</operator>
<operand1>4</operand1>
<operand2>14</operand2>
<result>4 * 14 = 56</result>
</problem>
</simplemath>[/code]
And I would save this to a new file.
However, I am having issues looping around the "unknown" number of <problem> nodes. When I call myxpathnav.MoveToNext() and look in the debugger, it looks like it has moved to the next node. However, when I then go into the doMath method,
it is always pulling the values from the first <problem>, and never reaching the second or subsequent ones.
I hope this is clear.
Thanks
View the full article
Here is my XML:
<pre class="prettyprint <simplemath>
<problem>
<operator>+</operator>
<operand1>13</operand1>
<operand2>12</operand2>
<result>blank</result>
</problem>
<problem>
<operator>*</operator>
<operand1>4</operand1>
<operand2>14</operand2>
<result>blank</result>
</problem>
</simplemath>[/code]
<br/>
In my code, I get an XPathNavigator to the first problem by using a selectSingleNode("/simplemath/problem") call.
I then try to call a method to do some stuff to this XPathNavigator with a method doMath(myxpathnav).
My doMath definition:
<pre class="prettyprint private static void doMath(XPathNavigator xpn)
{
XPathNavigator oper1 = xpn.SelectSingleNode("/simplemath/problem/operand1");
XPathNavigator oper2 = xpn.SelectSingleNode("/simplemath/problem/operand2");
XPathNavigator result = xpn.SelectSingleNode("/simplemath/problem/result");
string new_result = "";
// do a add/multiple/divide/whqatever and save the result
// as a string in new_result
// EX: 12 + 13 = 25
result.SetValue(new_result);
return;
[/code]
<br/>
What I expect my end result XML to be is as follows:
<pre class="prettyprint <simplemath>
<problem>
<operator>+</operator>
<operand1>13</operand1>
<operand2>12</operand2>
<result>13 + 12 = 25</result>
</problem>
<problem>
<operator>*</operator>
<operand1>4</operand1>
<operand2>14</operand2>
<result>4 * 14 = 56</result>
</problem>
</simplemath>[/code]
And I would save this to a new file.
However, I am having issues looping around the "unknown" number of <problem> nodes. When I call myxpathnav.MoveToNext() and look in the debugger, it looks like it has moved to the next node. However, when I then go into the doMath method,
it is always pulling the values from the first <problem>, and never reaching the second or subsequent ones.
I hope this is clear.
Thanks
View the full article