The SqlDataSource and ObjectDataSource controls are flat-table data source controls, and the operation is relatively straightforward, and I'm not going to elaborate on that.
I'm here to talk about the XmlDataSource used to connect XML files and the XmlDataSource data bound to a flat table control in the two hierarchical data source controls used to connect the site navigation data.
The XmlDataSource control allows other controls to bind to XML data. The XmlDataSource supports the DataFile property, which is used to specify the path to the XML data file as input (input). You can also specify the Tranformfile attribute, apply an XSLT transformation to the data, and set the XPath property to specify a subset of the data source nodes that need to be exposed.
Transformfile= "~transxml" xpath= "//user" >
Tabular data-bound controls are also possible to bind to a hierarchical data source, but they can only display the first tier of data. In the following demo, the Repeater control is bound to a temp.xml file. Because the top-level nodes exposed by the data source are nodes, repeater can use the Eval data binding syntax in its own ItemTemplate template to bind to the properties of these nodes.
Title Name: Email:
In addition to the Eval data binding syntax, ASP.net 2.0 provides an XPath based data binding syntax that can be used on any data item that implements the IXPathNavigable interface. Here are two common types of expressions:
XPath (expression, [formatstring])-computes the value of an XPath expression based on the data item, returning a single value.
XPathSelect (expression, [formatstring])-computes the value of the XPath expression based on the data item and returns the list of nodes.
Let's take a look at the advantages of using the XPath data binding method, illustrated by a demo.
An additional repeater is added to the Repeater ItemTemplate template, and the internal repeater property is bound to a reply expression that describes the XPathSelect child node of the current user node. In the internal Repeater ItemTemplate template,
XPath data-binding expressions calculate values based on these "Reply" content nodes. ASP.net 2.0 utilizes this technique to enable you to easily construct rich, layered data display methods by combining tabular data-bound controls.