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


 



LVL 1
wilsont006Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wilsont006Author Commented:
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?
0
Carl TawnSystems and Integration DeveloperCommented:
Try changing:

     sales_line_list = sales_node.selectNodes("//salesline");

To:

     sales_line_list = sales_node.selectNodes("salesline");


Hope this helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
J_MakCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.