This is the response I’ll be getting:
<?xml version="1.0" encoding="utf-8"?>
<rsp stat="ok">
<image_hash>cxmHM</image_hash>
<delete_hash>NNy6VNpiAA</delete_hash>
<original_image>http://imgur.com/cxmHM.png</original_image>
<large_thumbnail>http://imgur.com/cxmHMl.png</large_thumbnail>
<small_thumbnail>http://imgur.com/cxmHMl.png</small_thumbnail>
<imgur_page>http://imgur.com/cxmHM</imgur_page>
<delete_page>http://imgur.com/delete/NNy6VNpiAA</delete_page>
</rsp>
How can I extract the value of each tag?
XDocument response = new XDocument(w.UploadValues("http://imgur.com/api/upload.xml", values));
string originalImage = 'do the extraction here';
string imgurPage = 'the same';
UploadedImage image = new UploadedImage();
Fortunately it’s pretty simple:
That’s assuming your
XDocumentconstructor call is correct… without knowing whatw.UploadValuesdoes, that’s hard to say.LINQ to XML makes querying very easy – let us know if you have anything more complicated.
Note that I’ve used a cast to string instead of taking the
Valueproperty or anything like that. That means if the<original_image>element is missing,originalImagewill be null rather than an exception being thrown. You may prefer the exception, depending on your exact situation.