Solved

asp.net display data from xml response in html

Posted on 2012-03-28
1
539 Views
Last Modified: 2012-04-30
Hello Experts,

Lets say this is my XML response where the user requested two stock quotes from a rest based service (http://www.google.com/ig/api?stock=hd&stock=aapl):

<?xml version="1.0" ?>-
<xml_api_reply version="1">
  <finance module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
    <symbol data="AAPL" />
    <company data="Apple Inc." />
    <exchange data="Nasdaq" />
    <last data="617.62" />
    <high data="621.45" />
    <low data="610.31" />
  </finance>
  <finance module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
    <symbol data="HD" />
    <company data="The Home Depot, Inc." />
    <exchange data="NYSE" />
    <last data="49.91" />
    <high data="50.25" />
    <low data="49.60" />
  </finance>
</xml_api_reply>

code behind:

    // Create a new XmlDocument  
    XmlDocument doc = new XmlDocument();
    // Load data  
    doc.Load(xmldoc);
   
     // Get list of finance nodes  
     XmlNodeList nodes = doc.SelectNodes("*");  //what goes here to get list of finance nodes???
     //loop thru finance nodes and get all attributes and "data" values
     
        foreach (XmlNode node in nodes)
        {
           
            XmlAttributeCollection xmlAttrCollection = node.Attributes;
            foreach (XmlAttribute xmlAttrCol in xmlAttrCollection)
            {
                         
                //how do I build the html dynamically so that the code gets all the attribute names and data values except for the attributes in the finance element?
               //response could contain alot more attributes so can't hard code the attribute names
            }
        }

how can i programmatically build this html (or similar; taking suggestions on markup) so that if user inputs 1 stk symbol or 10 the code would build the html accordingly.

Sample html:
        <td>Company: HD     </div>    
        <div>Exchange: NYSE </div>        
        <div>High:    50.25     </div>        
        <div>Low:     49.60    </div>        
        <div>Last:      49.91   </div>

Thanks again!
0
Comment
Question by:j420exe1
1 Comment
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 500 total points
ID: 37779374
You can use jquery for this.
Take a idea from the link below
http://stackoverflow.com/questions/3957932/whats-the-best-way-to-parse-xml-response-in-ajax

Hope this will give you the idea.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now