Link to home
Start Free TrialLog in
Avatar of wilsont006
wilsont006

asked on

selectNodes problem (alwasy first element)

I have a xml file looks like the following
<sales>
     <salesOrder>
            <order_no>0000011</order_no>
             <ship_no>00000059</ship_no>
              <salesline>
                              <item>apple</item>
                             <qty>10</qty>
                              <date>10/10</date>
               </salesline>
                <salesline>
                              <item>orangle</item>
                             <qty>2</qty>
                              <date>10/2</date>
               </salesline>
       </salesOrder>

   <salesOrder>
            <order_no>0000012</order_no>
             <ship_no>00000060</ship_no>
              <salesline>
                              <item>water</item>
                             <qty>10</qty>
                              <date>10/12</date>
               </salesline>
                <salesline>
                              <item>air</item>
                             <qty>2</qty>
                              <date>10/22</date>
               </salesline>
                 <salesline>
                              <item>coke</item>
                             <qty>2</qty>
                              <date>10/22</date>
               </salesline>
       </salesOrder>      
</sales>

for(int i=0;i<saleorder_list.length();i++)
{
      sales_node = salesorder_list.item(i);
       sales_line_list = sales_node.selectNodes("//salesline");
              for(int j =0;j<sales_line_list.length();j++)
                            sales_line_node = sales_line_list.item(j)
}

In that case the sales_line_nodes will always return the first salesline of the whole xml (apple) but not according to item(i)
is there anyway to do that?  for example when i = 2 the sales_line_list only contains water,air , and code those 3 salesline? thx alot


 



Avatar of wilsont006
wilsont006

ASKER

i understand that the selectNodes / selectSingleNodes will return the first element of the whole tree
but i can't use item(index) , i must use a string "\\salesline" , is there any other way to do so?
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this:

for(int i=0;i<saleorder_list.length();i++)
{
      sales_node = salesorder_list.item(i);
       sales_line_list = sales_node.selectNodes("child::*[i+1]/salesline");
              for(int j =0;j<sales_line_list.length();j++)
                            sales_line_node = sales_line_list.item(j)
}

Have not tested this but it should be close to what you want. Otherwise, it will be something in that nature. Cheers.