问题描述
我想调用XmlSerializer.Deserialize
并将其传递给XDocument
.可能需要Stream
,XmlReader
或TextReader
.
我可以在不将XDocument
实际转储到某些中间存储区(例如MemoryStream
)的情况下,从XDocument
生成以上内容之一吗?
似乎我所追求的是与XDocument
一起工作的XmlReader
的实现.不过我找不到.
您可以使用 XDocument.CreateReader()
创建一个读取XDocument
内容的XmlReader
.
等效地,以下内容也将起作用.
XmlReader GetReader(XDocument doc)
{
return doc.Root.CreateReader();
}
I would like to invoke XmlSerializer.Deserialize
passing it an XDocument
. It can take a Stream
, an XmlReader
or a TextReader
.
Can I generate one of the above from XDocument
without actually dumping the XDocument
into some intermediate store, such as a MemoryStream
?
It seems that what I'm after is an implementation of XmlReader
that works with an XDocument
. I can't find one though.
You can use XDocument.CreateReader()
to create an XmlReader
that reads the contents of the XDocument
.
Equivalently, the following will work too.
XmlReader GetReader(XDocument doc)
{
return doc.Root.CreateReader();
}
这篇关于使用XDocument作为XmlSerializer.Deserialize的源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!