Solved

asp.net display data from xml response in html

Posted on 2012-03-28
1
544 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

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!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

617 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