Did you ever want to Serialize/Deserialize a complex XML, like Youtube's API XML Response or Flickr's Feed XML Response. Lets start with Flickr's XML Response and see how to Deserialize it.
You can view the full details on XML over here: http://www.flickr.com/services/feeds/docs/photos_public/

To download/View sample XML head over to this link http://api.flickr.com/services/feeds/photos_public.gne?tags=water

Lets start disecting the XML First thing to identify are the Namespaces Used in the Feed, Namesaces
The namespace used here is:

  • xmlns="http://www.w3.org/2005/Atom"

Other name spaces are used within subelements of the XML, like below:
Other Namespaces
The root node that we have to read is feed and then subsiquently move to the child nodes.Noe to start the correcponding class for this XML, add a new class file to your project as we will be needing many different classes to map to diff objects withing the same XML, its adviceable to add a namespace and then add corresponding classes to the same namespace for easier readability and association to one XML becomes easier.
I am calling the project "FlickPics" and adding a namespace "Classes" under FlickPics, here is a code snippet of the same, also added the XMLRoot Attribute, Remember to use System.Xml.Serialization namespace.
Adding Namespace
adding up of the root element maps the class to that particular element under XML (like here we are mapping "feed" to "FlickrFeed" class),it is very important to give the corresponding namespace of that element, else an error is thrown while deserializing the XML.

Next, lets examine the elements under the feed now, Adding Namespace
In the image above you can see that Feed has various elements underneath, we can translate what all we need in our class, like i did mapping of Title element with Variable string here:
Element Mapping
one interesting thing to note down is that the root feed contains multiple entry elements, most of the information that we need to read is under this element, to translate this element to correspoint element in our class, create a new class with the name you want and declare an array of that under the "FlickrFeed" class we created, its shown by the code snippet below:
Adding Namespace
Entries Class
Entries Class
In the Entries Class i only translated what was required, you can always map the other elements by adding corresponding variables in your class.Now as there are 2 link elements under each entry element we have to take link as an array of class Link, below snippet shows the Link class created for mapping of different link elements,also note that each link element has different attributes to map.

Multiple Link Elements
Multiple Links
Link Class
Link Class
Author Class and Author XML Element Below is code snippet for the Author Element and Author Class
Author Element
Author Class
Once the class is created now comes the Deserialization Part, this is very simple and self explanatory(complete code is also available from the link at the bottom of this article).
Flickr search class
Now the whole XML is deserialized to the FlickrFeed class and can be used as you want,just traverse through the FlickrFeed object and retrive all the vaues needed.

Click here to download the source for this article , If you have any query related to the above article please click here to email.