Display XML Data in ASPX

  • Thread starter Thread starter Michelle
  • Start date Start date
M

Michelle

Hi, I want to display some pretty basic xml data in
a .NET user control that I would like to build for my
site.

I am getting the XML from a URL that has been provided to
me (i.e. http://domain.com/somelink.asp). If I type the
URL into my browser, the xml doc below is displayed. How
can I incorporate the XML into the user control so that I
can display the company name on my web page?

The XML doc looks like this:
<companies>
<company ID="1" Name="ABC Company"/>
<company ID="2" Name="XYZ Company"/>
<companies>

Thanks for your help.
 
Probably the easy way is to load into DataSet using ReadXml method and bind
the DataSet to the user control.
 
Michelle,

Try using the System.Web.UI.WebControls.Xml control. Drop the control onto
your web form or user control and set the "DocumentSource" to the url of your
xml data. Then set the "TransformSource" property to the url of an XSLT file.
When you run your page the Xml control will perform a transformation and
display your xml data. I've written a simple XSLT sample here that you can
test with:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/companies/company">
<table border="1">
<tr>
<td>
<xsl:value-of select="@name" />
</td>
</tr>
</table>
</xsl:template>

</xsl:stylesheet>

The XSLT transform above will produce an HTML table that displays the
company name on separate rows as shown below:

ABC Company
XYZ Company

HTH,
Jorge
 
Thanks Jorge, That's what I started working with. The
problem is it seems like the xml web control only allows
document sources relative to the website itself. I am
trying to access http://somesite/getcompanies.asp to
return my xml doc. I get an error:

"Invalid Map Path... A virtual path is expected"

I can't believe I am not able to retrieve an xml document
from another site. Is that true?

-----Original Message-----
Michelle,

Try using the System.Web.UI.WebControls.Xml control. Drop the control onto
your web form or user control and set
the "DocumentSource" to the url of your
 
Back
Top