XmlDataSource databinding xML file to data-bound controls like DataView and DataList

I have pulled in few resources on couple of ways we could databind an XML file to a Data-Bound controls using XmlDataSource.

Basically the idea is to be able to bind an XML file, either a physical XML file or XML formatted String using XMLDataSource.

1) This article from MSDN talks about how to bind an external (physical) XML file to a TreeView Control. These Concepts are same for all the other data-boundable controls like DataView, DataList, etc

http://msdn2.microsoft.com/en-us/library/494y92bs(vs.90).aspx

You can see how you could simply bind the XML file, Transform it before binding, and using XPath to filter further.

One thing I think its missing is reading/binding values form an XML node attribute value.

Taking further the examples mentioned in the above article, assuming you have an XML attribute, “ID” for Person node, in the databinding columns you could read/bind it as

<asp:TreeNodeBinding DataMember=”Person” TextField=”ID” />

You are specifying the name of the attribute for “TextField” instead of the “#InnerText” that read the InnerText of the Node.

2) We could also bind an inline XML string using XmlDataSource as discussed in this article from another MSDN article

http://msdn2.microsoft.com/en-us/library/ms228250(vs.80).aspx

-Hope it helps…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: