Search code examples
c#xmlbing-mapsxelementxmlstreamreader

Reading an XML Feed into XElement


I have an Xml Stream that I'd like to read into an XElement. I've seen samples that use XmlTextReader but I need it in an XElement.

The code that I have so far:

string url = 
 String.Format( "http://dev.virtualearth.net/REST/v1/Locations/{0}?o=xml&key={1}", HttpUtility.UrlEncode( AddressQuery ), mapkey );

HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;  

XmlTextReader reader = new XmlTextReader( url );

I'm just not sure how to get the reader into an XElement. Perhaps I'm going about it the wrong way.


Solution

  • with linq to xml you can simply do this

    var xml = XElement.Load(uri);