Partilhar via


XML Web Server Control Overview

You can use the Xml Web server control to display the contents of an XML document without formatting or by using XSL transformations.

This topic contains:

  • Scenarios

  • Background

  • Code Examples

  • Class Reference

Scenarios

An Xml Web server control reads XML and writes it into an ASP.NET Web page at the location of the control. If an XSL transformation (XSLT) is applied to the XML, the resulting transformed output will be rendered in the page.

Back to top

Background

You can use the XML Web server control to write an XML document, or the results of an XSLT transformation, into an ASP.ENT Web page. The XML output appears in the Web page at the location of the control.

Note

To use XML data as the source for other controls, such as the Repeater, DataList, or GridView controls, you can use the XmlDataSource control. For details, see XmlDataSource Web Server Control Overview.

The XML and the XSLT information can be in external documents, or you can include the XML inline. There are two ways to reference external documents using property settings in the XML Web server control. You can provide a path to the XML document in the control tag, or you can programmatically load the XML and XSLT documents as objects and then pass them to the control. If you prefer to include the XML inline, write it between the opening and closing tags of the control.

The XML document to display is specified by setting one of properties listed in the following table. These three properties represent the different types of XML documents that can be displayed. You can display a System.Xml.XmlDocument, an XML string, or an XML file by setting the appropriate property.

Property

Description

Document

Sets the XML document by using a System.Xml.XmlDocument object.

DocumentContent

Sets the XML document by using a string.

Note

This property is typically set declaratively by placing text between the opening and closing <asp:Xml> tags of the Xml control.

DocumentSource

Sets the XML document by using a file.

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 referenced in the last property set is displayed. The documents in the other properties are ignored.

You can optionally set properties to specify an XSL Transformation (XSLT) style sheet that formats the XML document before it is written to the output stream. The properties represent the different types of XSL transformation style sheets that can be used to format the an document. You can format the XML document with a System.Xml.Xsl.XslCompiledTransform object or with an XSL transformation style sheet file by setting the appropriate property. If no XSL transformation style sheet is specified, the XML document is displayed by using the default format.

Back to top

Code Examples

Walkthrough: Displaying an XML Document in a Web Forms Page Using Transformations

How to: Add XML Web Server Controls to a Web Forms Page

How to: Load XML Data in the XML Web Server Control

How to: Transform XML Data in the XML Web Server Control

Class Reference

The following table lists the classes that relate to the XML control.

Member

Description

XML

The main class for the control.

Back to top

See Also

Concepts

XmlDataSource Web Server Control Overview