System.Web.UI.WebControls.XmlDataSource Class

Represents an XML data source to data-bound controls.

See Also: XmlDataSource Members

Syntax

[System.Web.UI.PersistChildren(false)]
[System.Web.UI.ParseChildren(true)]
[System.ComponentModel.DefaultEvent("Transforming")]
[System.ComponentModel.DefaultProperty("DataFile")]
[System.ComponentModel.Designer("System.Web.UI.Design.WebControls.XmlDataSourceDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
public class XmlDataSource : System.Web.UI.HierarchicalDataSourceControl, System.ComponentModel.IListSource, System.Web.UI.IDataSource

Remarks

In this topic:

Introduction

The System.Web.UI.WebControls.XmlDataSource control is a data source control that presents XML data to data-bound controls. The System.Web.UI.WebControls.XmlDataSource control can be used by data-bound controls to display both hierarchical and tabular data. The System.Web.UI.WebControls.XmlDataSource control is typically used to display hierarchical XML data in read-only scenarios. Because the System.Web.UI.WebControls.XmlDataSource control extends the System.Web.UI.HierarchicalDataSourceControl class, it works with hierarchical data. The System.Web.UI.WebControls.XmlDataSource control also implements the System.Web.UI.IDataSource interface and works with tabular, or list-style, data.

Note:

For security purposes, none of the System.Web.UI.WebControls.XmlDataSource control properties are stored in view state. Since it is technically possible to decode the contents of view state on the client, storing sensitive information about the data structure or its contents could expose you to an information disclosure threat. Note that if you need to store information such as XmlDataSource.XPath property in view state, you can enable encryption to protect the contents by setting System.Web.UI.Page.ViewStateEncryptionMode on the @ Page directive.

Page developers use the System.Web.UI.WebControls.XmlDataSource control to display XML data using data-bound controls.

Sources of XML Data

The System.Web.UI.WebControls.XmlDataSource typically loads XML data from an XML file, which is specified by the XmlDataSource.DataFile property. XML data can also be stored directly by the data source control in string form using the XmlDataSource.Data property. If you want to transform the XML data before it is displayed by a data-bound control, you can provide an Extensible Stylesheet Language (XSL) style sheet for the transformation. As with the XML data, you typically load the style sheet from a file, indicated by the XmlDataSource.TransformFile property, but you can also store it in string form directly using the XmlDataSource.Transform property.

Updating XML Data

The System.Web.UI.WebControls.XmlDataSource control is commonly used in read-only data scenarios where a data-bound control displays XML data. However, you can also use the System.Web.UI.WebControls.XmlDataSource control to edit XML data. To edit the XML data, call the XmlDataSource.GetXmlDocument method to retrieve an System.Xml.XmlDataDocument object that is an in-memory representation of the XML data. You can use the object model exposed by the System.Xml.XmlDataDocument and System.Xml.XmlNode objects it contains or use an XPath filtering expression to manipulate data in the document. When you have made changes to the in-memory representation of the XML data, you can save it to disk by calling the XmlDataSource.Save method.

There are some restrictions to the editing capabilities of the System.Web.UI.WebControls.XmlDataSource control:

Specifying an XSL Transformation

A common operation performed with XML data is transforming it from one XML data set into another. The System.Web.UI.WebControls.XmlDataSource control supports XML transformations with the XmlDataSource.Transform and XmlDataSource.TransformFile properties, which specify an XSL style sheet to apply to XML data before it is passed to a data-bound control, and the XmlDataSource.TransformArgumentList property, which enables you to supply dynamic XSLT style sheet arguments to be used by an XSL style sheet during the transformation. If you specify an XPath filtering expression using the XmlDataSource.XPath property, it is applied after the transformation takes place.

Note:

The System.Web.UI.WebControls.XmlDataSource class uses the deprecated System.Xml.Xsl.XslTransform class to perform XSL transformations. If you want to use style sheet features that were introduced after the System.Xml.Xsl.XslTransform class was deprecated, apply the transforms manually by using the System.Xml.Xsl.XslCompiledTransform class.

Filtering using an XPath Expression

By default, the System.Web.UI.WebControls.XmlDataSource control loads all the XML data in the XML file identified by the XmlDataSource.DataFile property or found inline in the XmlDataSource.Data property, but you can filter the data using an XPath expression. The XmlDataSource.XPath property supports an XPath-syntax filter that is applied after XML data is loaded and transformed.

Caching

For performance purposes, caching is enabled for the System.Web.UI.WebControls.XmlDataSource control by default. Opening and reading an XML file on the server every time a page requested can reduce the performance of your application. Caching lets you reduce the processing load on your server at the expense of memory on the Web server; in most cases this is a good trade-off. The System.Web.UI.WebControls.XmlDataSource automatically caches data when the XmlDataSource.EnableCaching property is set to true, and the XmlDataSource.CacheDuration property is set to the number of seconds that the cache stores data before the cache is invalidated. You can use the XmlDataSource.CacheExpirationPolicy to further fine-tune the caching behavior of the data source control.

Additional Features

The following table lists additional features that are supported by the System.Web.UI.WebControls.XmlDataSource control.

Sorting

Not supported by the System.Web.UI.WebControls.XmlDataSource control.

Filtering

The XmlDataSource.XPath property can be used to filter the XML data using an appropriate XPath expression.

Paging

Not supported by the System.Web.UI.WebControls.XmlDataSource control.

Updating

Supported by manipulating the System.Xml.XmlDataDocument directly and then calling the XmlDataSource.Save method.

Deleting

Supported by manipulating the System.Xml.XmlDataDocument directly and then calling the XmlDataSource.Save method.

Inserting

Supported by manipulating the System.Xml.XmlDataDocument directly and then calling the XmlDataSource.Save method.

Caching

Enabled by default, with the XmlDataSource.CacheDuration property set to 0 (infinite) and the XmlDataSource.CacheExpirationPolicy property set to System.Web.UI.DataSourceCacheExpiry.Absolute.

Data View Object

Because the System.Web.UI.WebControls.XmlDataSource control supports data-bound controls that display hierarchical data as well as controls that display tabular data, the data source control supports multiple types of data source view objects on its underlying XML data. The System.Web.UI.WebControls.XmlDataSource control retrieves a single named System.Web.UI.WebControls.XmlDataSourceView object when used with a data-bound control that displays tabular data. The System.Web.UI.IDataSource.GetViewNames method identifies this single named view. When used with a data-bound control that displays hierarchical data, the System.Web.UI.WebControls.XmlDataSource control retrieves an System.Web.UI.WebControls.XmlHierarchicalDataSourceView for any unique hierarchical path passed to the XmlDataSource.GetHierarchicalView(string) method.

Declarative Syntax

Example

<asp:XmlDataSource
    CacheDuration="string|

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0