從String填充XDocument

我正在作一些小事情,我想弄清楚我是否能夠從字符串加載XDocument。 XDocument.Load()彷佛將傳遞給它的字符串做爲物理XML文件的路徑。 spa

我想嘗試繞過首先必須建立物理XML文件的步驟,而後直接跳轉到填充XDocument。 code

有任何想法嗎? 文檔


#1樓

您可使用XDocument.Parse字符串


#2樓

您可使用XDocument.Parse(string)而不是Load(string)get


#3樓

嘗試Parse方法。 string


#4樓

這個怎麼樣...? it

TextReader tr = new StringReader("<Root>Content</Root>");
XDocument doc = XDocument.Load(tr);
Console.WriteLine(doc);

這是從XDNocument.Load的MSDN文檔中獲取的,在這裏找到... io

http://msdn.microsoft.com/en-us/library/bb299692.aspx bug

相關文章
相關標籤/搜索