using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Net;
namespace Erdt
{
/// <summary>
/// Aby se hnidopichove neposrali ze se nekontroluje platnost parametru
/// </summary>
class Program
{
static void Main(string[] args)
{
var sURL = "http://maps.google.cz/maps/geo?q=Na%20Bezdekove+1738&gl=cs&hl=cs&output=xml";
var xml = new XmlDocument();
WebClient client = new WebClient();
byte[] b = client.DownloadData(sURL);
var str = new System.Text.UTF8Encoding().GetString(b);
xml.LoadXml(str);
var accuracy = Get(xml.DocumentElement, "Accuracy", "Response", "Placemark", "AddressDetails");
var north = Get(xml.DocumentElement, "north", "Response", "Placemark", "ExtendedData", "LatLonBox");
var fake = Get(xml.DocumentElement, "Response", "Error", "ExtendedData", "LatLonBox");
Console.WriteLine("north = {0} with accuracy {1}", north, accuracy);
}
static string Get(XmlElement elem, string attrib, params string[] key)
{
foreach (var k in key)
{
elem = elem[k];
if (elem == null) return "???";
}
var attr = elem.Attributes[attrib];
return attr == null ? "!!!" : attr.Value;
}
}
}