Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

selectNodes problem (alwasy first element)

Posted on 2004-11-12
3
Medium Priority
?
599 Views
Last Modified: 2008-02-01
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


 



0
Comment
Question by:wilsont006
3 Comments
 
LVL 1

Author Comment

by:wilsont006
ID: 12563881
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
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 12564065
Try changing:

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

To:

     sales_line_list = sales_node.selectNodes("salesline");


Hope this helps.
0
 
LVL 7

Expert Comment

by:J_Mak
ID: 12565155
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question