Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get Data From XML?

Posted on 2009-05-19
1
Medium Priority
?
187 Views
Last Modified: 2012-05-07
I have an XML document which has a list of transactions of costs for different items, so it will be listed like this:
                  <product id="1" description="XYZ">
                        <costs>
                              <cost start="01/02/2009" cost="8.67000"/>
                              <cost start="01/03/2009" cost="6.80000"/>
                        </costs>
                  </product>
                  <product id="2" description="ABC">
                        <costs>
                              <cost start="01/02/2009" cost="8.67000"/>
                        </costs>
                  </product>

In my code I'm iterating through the XML getting each of the cost attributes, unfortunately my code doesn't differentiate between product 1 and 2, so adds all 6 attributes for cost to the one list.  

Is there anyway I can avoid grouping all of them together?  And take out X amount of costs from product 1, and X from product 2?  I can't go off the product ID as that will be different each time, and may not even be present.  All help is greatly appreciated.
0
Comment
Question by:angus_young_acdc
1 Comment
 
LVL 9

Accepted Solution

by:
tetorvik earned 2000 total points
ID: 24420105
with XPath you can first retrieve the list of products and then calculate the total cost/product in inner loop. Here is the sample:
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("XMLFile1.xml"));
 
foreach (XmlNode product in doc.SelectNodes("//product"))
{
    XmlNodeList costNodes = product.SelectNodes("costs/cost");
    //then loop throught the costNodes to retrieve total cost per product
    //foreach(XmlNode cost in costNodes) etc. 
}

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
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

772 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