Skip to content

Instantly share code, notes, and snippets.

@jz5

jz5/Program.cs

Last active Aug 29, 2015
Embed
What would you like to do?
static void Main(string[] args)
{
var url = "http://example.jp/xml";
var client = new WebClient() { Encoding = Encoding.UTF8 };
var xml = client.DownloadString(url);
var d = XDocument.Parse(Sanitize(xml));
}
private static string Sanitize(string xml)
{
var sb = new System.Text.StringBuilder();
foreach (var c in xml)
{
var code = (int)c;
if (code == 0x9 ||
code == 0xa ||
code == 0xd ||
(0x20 <= code && code <= 0xd7ff) ||
(0xe000 <= code && code <= 0xfffd) ||
(0x10000 <= code && code <= 0x10ffff))
{
sb.Append(c);
}
}
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment