Silverlight provides a rich toolset to work with XML data with the different options suited for different tasks. This page
covers the most common ways to work with XML data. For simplicity, all of the examples below use Atom XML data fetched from
http://api.flickr.com/services/feeds/photos_public.gne. However, when working with Atom and RSS feeds it is usually easier to
use the Silverlight feed classes. See Using RSS and Atom Feeds below.
XmlReader class provides fast read- and forward-only access to data and is well suited for iterating over
an XML document. It can read data from a stream or it can be passed a URI to a file that is located within the application's XAP.
The following example shows how to take an existing stream and output the content of the text nodes in the document.
For well-known data structures, such as business objects, it is often necessary to read external data and import
it into internal strongly typed objects. The
XmlSerializer class lets you easily deserialize XML into managed objects.
The downside of using
XmlSerializer is the requirement
to reference the external System.Xml.Serialization.dll assembly which will increase your XAP size by approximately 150kB.
The following example shows how to take an existing stream and deserialize the data into strongly-typed objects. The abbreviated data classes are shown after the method.
Link to XML provides an easier read/write interface than the traditional XML Document Object Model. Integration with LINQ allows you to write queries and modify the contents of the document. The downside of using XLINQ is the requirement to reference the external System.Xml.Linq.dll assembly which will increase your XAP size by approximately 56kB.
The following example shows how to take an existing stream, sort the results based on an element, and output selected data.
Silverlight provides support for RSS and Atom feeds in the
which makes it very easy to work with these common data structures.
The downside of using the feed support is the requirement to reference the external
System.ServiceModel.Syndication.dll assembly which will increase your XAP size by approximately 53kB.
The following example shows how to take an existing stream and output the entry titles using feed support.
Related information on the web is listed below.