Home > C# > Deserializing XML twitter feeds.

Deserializing XML twitter feeds.

1. Use xsd.exe to extract an xsd file from an xml feed.
Download a private xml feed for example from “http://api.twitter.com/1/statuses/user_timeline.xml” and store it to local disk. Use xsd.exe to generate the xsd.
2. Generate the classes from the xsd file you just generated.

xsd.exe yourxsd.xsd /c

3. Add the generated classes to your C# project.
4. Time for some fetching here is a short example:

// encode the username/password
string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://api.twitter.com/1/statuses/user_timeline.xml");
// set the method to GET
request.Method = "GET";
request.ServicePoint.Expect100Continue = false;
// set the authorisation levels
request.Headers.Add("Authorization", "Basic " + user);
request.ContentType = "application/x-www-form-urlencoded";
 
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
	XmlSerializer serializer = new XmlSerializer(typeof(statuses));
	statuses s = serializer.Deserialize(response.GetResponseStream()) as statuses;
 
	listBox1.Items.Clear();
	foreach (statusesStatus status in s.status)
	{
		listBox1.Items.Add(status.text);
	}
}
Categories: C# Tags: , , , , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Time limit is exhausted. Please reload CAPTCHA.