Solved

asp.net display data from xml response in html

Posted on 2012-03-28
1
540 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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