I have a string I have parsed from a RSS feed
thumbnail url='http://photos3.media.pix.ie/11/C5/11C5B77C92204ADBBD0CF5FDF4BA351B-0000314357- 0002211156-00240L-00000000000000000000000000000000.jpg' height='240' width='226'
I need to remove just the URL detail from the string to form the basis of a image on a Windows Ph开发者_如何学Pythonone 7 application.
What would you suggest as the best way of doing this
The code from the phone is here
FeedItems.ItemsSource = from imageFeed in xmlImageEntries.Descendants("item")
select new PixIEPanoramaTest.Data.FeedItem
{
ThumbSource = imageFeed.Element("thumbnail").Value,
};
Feeditems is just a bound list box. The thumbsource variable just needs the URL from the string.
Any thoughts greatly appreciated ,
Rob
You can just access the attribute value for the url attribute:
ThumbSource = imageFeed.Element("thumbnail").Attribute("url").Value,
It would probably worth using some kind of extensions method to return string.Empty
if the attribute is missing, though.
There are libraries available to help parse RSS feeds - e.g.
- working with rss + c#
- on codeplex http://rssr7.codeplex.com/releases/view/43832
If you want to do a quick "hacky" parse of the string yourself, then you could use RegularExpressions - e.g. a Regex something like thumbnail url='(?<imageurl>http.*?)' height='240' width='226'
would pull out your url as the imageurl
group
Match match = Regex.Match(input, @"thumbnail url='(?<imageurl>http.*?)' height='240' width='226'");
if (match.Success)
{
string url = match.Groups[1].Value;
}
精彩评论