Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Created November 14, 2013 14:25
Show Gist options
  • Save csharpforevermore/7467707 to your computer and use it in GitHub Desktop.
Save csharpforevermore/7467707 to your computer and use it in GitHub Desktop.
Read the XML document element (elementName) at a given URL (url). Allows for encoding problems.
public string GetXmlElementFromUrl(string url, string elementName)
{
byte[] data;
using (var webClient = new WebClient())
data = webClient.DownloadData(url);
string str = Encoding.GetEncoding("Windows-1252").GetString(data);
XDocument xmlDoc = XDocument.Parse(str);
var donation = new Donation();
var xElementAmount = xmlDoc.Element(elementName);
if (xElementAmount != null) return xElementAmount.Value;
return string.Empty;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment