Link to home
Start Free TrialLog in
Avatar of Jeff Fillegar
Jeff FillegarFlag for United States of America

asked on

asp.net display data from xml response in html

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!
ASKER CERTIFIED SOLUTION
Avatar of Lalit Chandra
Lalit Chandra
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial