Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.Net/C# - If I have a URL that dumps XML, how do I read those results in?

Posted on 2008-09-30
5
Medium Priority
?
284 Views
Last Modified: 2013-11-05
Is there an easy way to read in results of an XML file URL and output the elements as the label and values?
0
Comment
Question by:sbornstein2
[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
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
codeclay earned 2000 total points
ID: 22613634
See the sample code attached below
####################################Code Behind########################
public partial class XML : System.Web.UI.Page
{
    TextBox textBoxValue;
    Label lblValue;
    Table tbl;
    TableRow tr;
    TableCell td;
    protected void Page_Load(object sender, EventArgs e)
    {
        
 
    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        tbl = new Table();
 
        LoadXML();
    }
    private void LoadXML()
    {
        XmlDocument doc = new XmlDocument();
        doc.Load(XmlReader.Create("http://localhost/Test/Sample.xml"));
        CreateChildControlsFromXML(doc);
    }
 
    private void CreateChildControlsFromXML(XmlDocument doc)
    {
        foreach (XmlNode node in doc.ChildNodes)
        {
            if (node.NodeType == XmlNodeType.Element && node.Name == "Elements")
            {
                foreach (XmlNode node1 in node.ChildNodes) // Get the value Nodes
                {
                    tr = new TableRow();
                    td = new TableCell();
                    lblValue = new Label();
                    textBoxValue = new TextBox();
                    lblValue.Text = node1.ChildNodes[0].InnerText;
                    textBoxValue.Text = node1.ChildNodes[1].InnerText;
                    td.Controls.Add(lblValue);
                    tr.Cells.Add(td);
                    td = new TableCell();
                    td.Controls.Add(textBoxValue);
                    tr.Cells.Add(td);
                    tbl.Rows.Add(tr);
                }
            }
        }
        containerPanel.Controls.Add(tbl);
    }
}
##################################Code Behind End#####################
 
#######################ASPX########################################
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="XML.aspx.cs" Inherits="XML" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:Panel runat="server" ID="containerPanel"></asp:Panel>
    </div>
    </form>
</body>
</html>
 
#######################ASPX END########################################
 
###########################Sample XML file Used#######################
 
<?xml version="1.0" encoding="utf-8"?>
<Elements>
  <Value>
    <Label>Label1</Label>
    <Text>Text1</Text>
  </Value>
  <Value>
    <Label>Label2</Label>
    <Text>Text2</Text>
  </Value>
  <Value>
    <Label>Label3</Label>
    <Text>Text3</Text>
  </Value>
  <Value>
    <Label>Label4</Label>
    <Text>Text4</Text>
  </Value>
</Elements>

Open in new window

0
 

Author Comment

by:sbornstein2
ID: 22628740
code clay that gave me a little start.  It is having issues though.  Here is what I am trying to format by reading in the XML like a HTML file.  It is a whitepages api call that I make and it returns XML data

http://api.whitepages.com/reverse_phone/1.0/?phone=7812332311;api_key=9ec586766bf2c9b0bd5f548a50a0b3e2

I need to somehow read this in and it may change and have more nodes etc.
0
 

Author Comment

by:sbornstein2
ID: 22628787
on whitepages.com there is an XSD file but I have no idea how to use all that.  I can just get the XML response

http://developer.whitepages.com/docs
0
 
LVL 9

Expert Comment

by:codeclay
ID: 22657059
I will look into it.. Right now its a busy schedule for me . Hold on .
0
 

Author Closing Comment

by:sbornstein2
ID: 31501658
thanks sorry for the delay in award.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

722 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