Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Created May 8, 2012 09:55
Show Gist options
  • Save pinzolo/2633943 to your computer and use it in GitHub Desktop.
Save pinzolo/2633943 to your computer and use it in GitHub Desktop.
XML文字列からXDocumentに読み込む
using System;
using System.IO;
using System.Text;
using System.Xml.Linq;
// 先頭に改行が入ると Load 時に例外発生
String xml = @"<foo>
<bar>hoge</bar>
<baz>fuga</baz>
</foo>";
using (var stream = new MemoryStream(Encoding.Unicode.GetBytes(xml)))
{
var doc = Xdocument.Load(stream);
// do something ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment