ASP.NET Syntax ASP.NET Syntax for Web Controls
Displays an XML document or the results of an XSL Transform.
Declarative Syntax
<asp:Xml
DocumentSource = "uri"
EnableTheming = "True | False"
EnableViewState = "True | False"
ID = "string"
OnDataBinding = "DataBinding event handler"
OnDisposed = "Disposed event handler"
OnInit = "Init event handler"
OnLoad = "Load event handler"
OnPreRender = "PreRender event handler"
OnUnload = "Unload event handler"
runat = "server"
SkinID = "string"
TransformSource = "string"
Visible = "True | False"
/>
For information on the individual members of this class, see Xml in the class library.
The Xml control renders the contents of an XML document or the results of an XSL Transform.
The XML document to display is specified by setting one of three properties. These three properties represent the different types of XML documents that can be displayed. You can display a System.Xml.XmlDocument object, an XML string, or an XML file by setting the appropriate property. The following table lists the properties for specifying the XML document.
NOTE: At least one of the XML document properties must be set to display an XML document. If more than one XML document property is set, the XML document in the last property set is displayed. The documents in the other properties are ignored.
You can optionally specify an XSL Transform document that formats the XML document before it is written to the output stream by setting one of two properties. The two properties represent the different types of XSL Transform documents that can be used to format the XML document. You can format the XML document with a System.Xml.Xsl.XslTransform object or an XSL Transform file by setting the appropriate property. If no XSL Transform document is specified, the XML document is displayed using the default format. The following table lists the properties for specifying an XSL Transform document.
Property |
Description |
Transform |
Formats the XML document using the specified System.Xml.Xsl.XslTransform object. |
TransformSource |
Formats the XML document using the specified XSL Transform file. |
NOTE: The XSL Transform document is optional. You do not need to set the Transform or the TransformSource properties. If both XSL Transform document properties are set, the last property set determines which XSL Transform document is used to format the XML document. The other property is ignored.
The following example demonstrates how to use the Xml control to display an XML file using an XSL Transform file.
<html>
<body>
<h3>Xml Example</h3>
<form runat=server>
<asp:Xml id="myXml"
DocumentSource = "people.xml"
TransformSource = "people.xsl"
runat="server" />
</form>
</body>
</html>
The following example demonstrates how to create XmlDocument and XslTransform objects from an XML and XSL Transform files. The objects are then used by the Xml control to display the XML document.
<%@ Import Namespace = "System.Xml" %>
<%@ Import Namespace = "System.Xml.Xsl" %>
<html>
<script language="C#" runat="server">
void Page_Load ( Object sender, EventArgs e ) {
XmlDocument doc = new XmlDocument ( );
doc.Load ( Server.MapPath ( "people.xml" ) );
XslTransform trans = new XslTransform ( );
trans.Load ( Server.MapPath ( "people.xsl" ) );
myXml.Document = doc;
myXml.Transform = trans;
}
</script>
<body>
<h3>Xml Example</h3>
<form runat=server>
<asp:Xml id="myXml" runat="server" />
</form>
</body>
</html>
<%@ Import Namespace = "System.Xml" %>
<%@ Import Namespace = "System.Xml.Xsl" %>
<html>
<script language="VB" runat="server">
Sub Page_Load ( sender As Object, e As EventArgs )
Dim doc As XmlDocument = New XmlDocument ( )
doc.Load ( Server.MapPath ( "people.xml" ) )
Dim trans As XslTransform = new XslTransform ( )
trans.Load ( Server.MapPath ( "people.xsl" ) )
myXml.Document = doc
myXml.Transform = trans
End Sub
</script>
<body>
<h3>Xml Example</h3>
<form runat=server>
<asp:Xml id="myXml" runat="server" />
</form>
</body>
</html> |
|
C# |
VB |
Xml Class Xml Web Server Control