<rsp stat="ok">
<image_hash>ducex</image_hash>
<delete_hash>QXHbCECmDX</delete_hash>
<original_image>http://i.imgur.com/ducex.jpg</original_image>
<large_thumbnail>http://i.imgur.com/ducexl.jpg</large_thumbnail>
<small_thumbnail>http://i.imgur.com/ducexs.jpg</small_thumbnail>
<imgur_page>http://imgur.com/ducex</imgur_page>
<delete_page>http://imgur.com/delete/QXHbCECmDX</delete_page>
</rsp>
First off all, can someo开发者_开发技巧ne help me start of how to parse this? All i need to do is check the "stat" value. if thats okay , then I need to get the "orginal image" link. I am targetting .NET 4.0 Client Frameowkr however so does that give me access to LINQ to XML?
How would I accomplish this using C#? Any tips to start me off with? Thanks
You can use LINQ to XML. The xmlInput
variable below would contain your string.
string xmlInput = @"<rsp stat=""ok"">
<image_hash>ducex</image_hash>
<delete_hash>QXHbCECmDX</delete_hash>
<original_image>http://i.imgur.com/ducex.jpg</original_image>
<large_thumbnail>http://i.imgur.com/ducexl.jpg</large_thumbnail>
<small_thumbnail>http://i.imgur.com/ducexs.jpg</small_thumbnail>
<imgur_page>http://imgur.com/ducex</imgur_page>
<delete_page>http://imgur.com/delete/QXHbCECmDX</delete_page>
</rsp>
";
var xml = XElement.Parse(xmlInput);
if (xml.Attribute("stat").Value == "ok")
{
string originalImage = xml.Element("original_image").Value;
}
精彩评论