Skip to content

Instantly share code, notes, and snippets.

@jz5
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jz5/65f3f5342dcf73a63292 to your computer and use it in GitHub Desktop.
Save jz5/65f3f5342dcf73a63292 to your computer and use it in GitHub Desktop.
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