Processing of XML data in. NET 2.0

Source: Internet
Author: User
Tags bind eval expression connect net xpath

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.