Solved

asp.net display data from xml response in html

Posted on 2012-03-28
1
536 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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

12 Experts available now in Live!

Get 1:1 Help Now