Created
November 14, 2013 14:25
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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