asp.net.ph

Skip Navigation Links

Xml Control Syntax

ASP.NET Syntax   ASP.NET Syntax for Web Controls


Displays an XML document or the results of an XSL Transform.

Declarative Syntax

For information on the individual members of this class, see Xml in the class library.

Remarks

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.

Property Description
Document Displays the specified System.Xml.XmlDocument object.
DocumentContent Displays an XML string.
DocumentSource Displays an XML file.

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.

Syntax Example

The following example demonstrates how to use the Xml control to display an XML file using an XSL Transform file.

xml1.aspx
Run Sample | View Source
<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.

xml2.aspx
Run Sample | View Source
<%@ 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>
  C# VB

See Also

Xml Class   Xml Web Server Control



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note