I'm trying to extract value of url which is basically url of an image in enclosure tag something like this:
<enclosure url="http://s3-us-west-1.amazonaws.com/s3cazinnet/2016/06/OZRK_KRAJINA_2016_5525.JPG?mtime=1465158486" length="" type="image/jpeg">
I don't want to bother you with whole classes so I will post just parts of code. And this is the part of code where I'm trying to get value of url:
if (xmlNode[i].SelectSingleNode("enclosure:url", xmlNameSpaceManager) != null)
{
var Url = xmlNode[i].Attributes["url"].Value;
feedItem.Image = Url;
}
Than I want to load that images in listview using UrlImageViewHelper by Koush here is the part of code from my FeedItemListAdapter class:
var imageView = view.FindViewById<ImageView> (Resource.Id.ListviewImage);
Koush.UrlImageViewHelper.SetUrlDrawable (imageView, feedItem.Image);
I don't get any error but images are not displyed in listview.
You should probably go and read about some basic XPath syntax, as your expression doesn't make a lot of sense - it is searching for an element with the name url
that has a namespace in the namespace manager identified by the prefix example
. Does that sound right?
Assuming your element is the root element and it doesn't have a namespace (it's not as to whether you've only given us a snippet), then the expression should be enclosure/@url
.
Once you've done that, you need to keep a reference to the result of your search for that attribute. At the moment you're just throwing it away and then trying to get the url
attribute on some arbitrary node in your list.
So, something like:
var url = xmlNode[i].SelectSingleNode("enclosure/@url", xmlNameSpaceManager);
feedItem.Image = url.Value;
This all said, LINQ to XML is a far nicer API than the old XmlDocument
API, and LINQ to XML is far nicer to use for querying XML than XPath. If you can, I would look into that.