Im receiving an XML RSS feed. One of the tags look like this:
<georss:point>55.0794503724671 -3.31266344234773</georss:point>
I need a simple way to extract these two lat and long values into seperate values [as part of my other XML reading foreach loop..].
EDIT:
I am now trying:
private void OnOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
var document = XDocument.Load(e.Result);
if (document.Root == null)
return;
var georss = XNamespace.Get("http://www.georss.org/georss");
var events = from ev in document.Descendants("item")
//how c开发者_开发技巧an I define the below for the Value.split?
//var points = from point in parentElement.Elements(geoRssNs + "point")
let values = ev.Value.Split(' ')
select new
{
Latitude = double.Parse(values[0], CultureInfo.InvariantCulture),
Longitude = double.Parse(values[1], CultureInfo.InvariantCulture),
Title = (ev.Element("title").Value),
Description = (ev.Element("description").Value),
PubDate = (ev.Element("pubDate").Value),
};
//Add pushpin here
} }
It strikes me that this isn't really XML - it's just normal string handling. For example, it could be something like this:
XNamespace geoRssNs = "http://whatever/url/it/is";
var points = from point in parentElement.Elements(geoRssNs + "point")
let values = point.Value.Split(' ')
select new
{
Latitude = double.Parse(values[0], CultureInfo.InvariantCulture),
Longitude = double.Parse(values[1], CultureInfo.InvariantCulture)
};
how about something like this
XDocument.Load(e.Result)
.Descendants("item")
.Descendants("georss:point")
.Select(v => v.Value.Split(' '))
.Select(ll => new GeoCoordinate{Longitude = ll[0], Latitude = ll[1]})
.Select(g => new Pushpin{
Location = g,
Background = (Brush)MediaTypeNames
.Application
.Current
.Resources["PhoneAccentBrush"]})
.ToList()
.ForEach(p => QuakeLayer.AddChild(p, p.Location));
精彩评论