An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

The Cool asp:xml control for displaying xml data.

Monday, April 25, 2005 7:47 AM
How many of us are aware that we can use the <asp:xml> server control to just specify the xml file and the xslt or other stylesheet file and then without a single line of code, .net does the transformation for rendering in an aspx page?

For the benefit of those who are not aware, the following is the code for accomplishing the same:-

<asp:Xml id="Xml1" runat="server" DocumentSource="file path to xml file" TransformSource="file path to xslt file">

Put the above code in the aspx page as you would normally declare other server controls like button, label etc., and it will load the document, apply the stylesheet and render it for you, in the aspx page. All done without a single line of additional code.

You can assign the DocumentSource and TransformSource from the codebehind as well like other server controls.

If you are using a DataSet and want to assign the xml from the dataset, well you can use the DocumentContent property of the <asp:xml> control to specify the xml format as follows:-

Xml1.DocumentContent = DataSet1.GetXml();

where Xml1 is the id of the <asp:xml> control.

Cheers.

Feedback

# re: The Cool asp:xml control for displaying xml data.

thanks, its cool and easy stuff i will try to implement it in my site youlay.com 1/1/2008 9:42 PM | ram

Post a comment





 

Please add 4 and 7 and type the answer here: