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.

posted @ Monday, April 25, 2005 7:47 AM

Print

Comments on this entry:

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

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

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

Left by azdırıcı at 11/30/2008 3:51 PM
Gravatar
thnaks for links all blog

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

Left by Michael at 6/3/2009 3:04 AM
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.

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

Left by mario oyunları at 9/21/2009 10:50 AM
Gravatar
i will try to implement it in my site youlay

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345