<%@ Page %>

Using XML Web Control


Now a days use of XML is increasing quickly. Many times data that you want to display can be stored in XML files rather than statically putting it in HTML pages. Such XML data can be transformed to HTML by applying XSL style sheet to it. In traditional ASP, we used XSL Transform objects to achieve that. ASP.NET makes displaying XML documents in browser much easy via a special web control called XML control.

Creating XML Document

For our example we will create following XML document. Just type in some data matching following following structure in any text editor and save the file as mybooks.xml
<?xml version="1.0" encoding="utf-8" ?>
<title>Title 1</title>
<publisher>Publisher 1</publisher>

Creating XSL Style Sheet

Now, let us create an XSL style sheet that transforms above data as HTML table.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
<xsl:template match="/">
<table border="1">
<xsl:for-each select="books/book">
<td><xsl:value-of select="title">
<td><xsl:value-of select="publisher">
Here we simply transform source XML to HTML.

Applying XSL to XML and outputting the results

Finally we will use ASP.NET XML web control that does this task. Following properties of the XML control are important:
  • DocumentSource : That specifies the XML document path
  • TransformSource : That specifies XSLT style sheet path
In order to use this control simply add following markup in your web form.
<asp:Xml id="Xml1" runat="server"
Now, run the web form and you should get books data displayed in HTML table. Note that XML web control also allows you to use XML strings or even XML dom documents as source.


In this article we saw how to quickly use ASP.NET XML web control to display XML documents in ASP.NET pages.

Bipin Joshi is an independent software consultant, trainer, author, and meditation teacher. He has been programming, meditating, and teaching for 25+ years. He conducts instructor-led online training courses in ASP.NET family of technologies for individuals and small groups. He is a published author and has authored or co-authored books for Apress and Wrox press. Having embraced the Yoga way of life he also teaches Ajapa Yoga to interested individuals. To know more about him click here.

Get connected : Facebook  Twitter  LinkedIn  YouTube

Posted On : 24 May 2002

Tags : ASP.NET Server Controls XML