<%@ 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" ?>
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" ?>
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.