The Cool asp:xml control for displaying xml data.

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.

Print | posted on Monday, April 25, 2005 7:47 AM

Comments on this post

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

Requesting Gravatar...
thanks, its cool and easy stuff i will try to implement it in my site youlay.com
Left by ram on Jan 01, 2008 9:42 PM

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

Requesting Gravatar...
thnaks for links all blog
Left by azdırıcı on Nov 30, 2008 3:51 PM

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

Requesting Gravatar...
Why can't I use an external URL that returns XML as the DocumentSource? I get an error "http://<external url>" is not a valid virtual path.
Left by Michael on Jun 03, 2009 3:04 AM

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

Requesting Gravatar...
i will try to implement it in my site youlay
Left by mario oyunları on Sep 21, 2009 10:50 AM

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

Requesting Gravatar...
Thank you. This will be very useful for my website.
Left by DiaryAtoZ.com on Jan 22, 2013 6:26 PM

Your comment:

 (will show your gravatar)