c# Regex on XML string handler

Posted by Dan Sewell on Stack Overflow See other posts from Stack Overflow or by Dan Sewell
Published on 2010-12-31T10:47:49Z Indexed on 2010/12/31 10:53 UTC
Read the original article Hit count: 314

Filed under:
|
|
|

Hi guys. Trying to fiddle around with regex here, my first attempt. Im trying to extract some figures out of content from an XML tag. The content looks like this:

www.blahblah.se/maps.aspx?isAlert=true&lat=51.958855252721&lon=-0.517657021473527

I need to extract the lat and long numerical vales out of each link. They will always be the same amount of characters, and the lon may or may not have a "-" sign.

I thought about doing something like this below: (The string in question is in the "link" tag):

             var document = XDocument.Load(e.Result);
             if (document.Root == null)
             return;

            var events = from ev in document.Descendants("item1")
                     select new
                     {
                         Title = (ev.Element("title").Value),
                         Latitude = Regex.xxxxxxx(ev.Element("link").Value, @"lat=(?<Lat>[+-]?\d*\.\d*)", String.Empty),
                         Longitude = Convert.ToDouble(ev.Element("link").Value),

                     };

        foreach (var ev in events)
        {
 do stuff
  }

Many thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml