I also recommend that you use proper XML parsing for this. However, note that the XML you gave isn't well-formed for use as an XML document because it has multiple root nodes. That's easily fixed, though.
If you use XML parsing, you'll easily be able to get at all the other data too, without any fiddly parsing.
This is so easy to do, and so much more robust than rolling-your-own XML parsing code that really should use it if you can:
Here's an one-line example which assumes your XML is in the string variable called xml:
string locality = XElement.Load(new StringReader("<Root>"+xml+"<Root>")).XPathSelectElement("Address/Locality").Value.Trim();
And here's a proper example:
using System;
using System.IO;
using System.Xml.Linq;
using System.Xml.XPath;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Fix original XML, which has multiple root nodes!
// We fix it just by enclosing it in a root level element called "Root":
string xml = "<Root>" + originalXml() + "</Root>";
// Read the XML as an XML element.
var xElement = XElement.Load(new StringReader(xml));
// Easily access 'Locality' or any other node by name:
string locality = xElement.XPathSelectElement("Address/Locality").Value.Trim();
Console.WriteLine("Locality = " + locality);
}
// Note: This XML isn't well-formed, because it has multiple root nodes.
private static string originalXml()
{
return
@"<Name>
High Street, Lincoln, LN5 7
</Name>
<Point>
<Latitude>
53.226592540740967
</Latitude>
<Longitude>
-0.54169893264770508
</Longitude>
</Point>
<BoundingBox>
<SouthLatitude>
53.22272982317029
</SouthLatitude>
<WestLongitude>
-0.55030130347707928
</WestLongitude>
<NorthLatitude>
53.230455258311643
</NorthLatitude>
<EastLongitude>
-0.53309656181833087
</EastLongitude>
</BoundingBox>
<EntityType>
Address
</EntityType>
<Address>
<AddressLine>
High Street
</AddressLine>
<AdminDistrict>
England
</AdminDistrict>
<AdminDistrict2>
Lincs
</AdminDistrict2>
<CountryRegion>
United Kingdom
</CountryRegion>
<FormattedAddress>
High Street, Lincoln, LN5 7
</FormattedAddress>
<Locality>
Lincoln
</Locality>
<PostalCode>
LN5 7
</PostalCode>
</Address>";
}
}
}