如何从 XMLWriter 获取流?
System.Xml.XmlWriter 的实例正在写入底层 Stream 对吗?(不管 XmlWriter 的具体实现是什么)
那么,为什么程序员没有方法可以从 XmlWriter 检索 Stream 对象呢?
我确信我错过了一些简单的事情。提前致谢。
PS:如果有人问,我真正想做的是从传递给我的 XmlWriter 实例获取流,并从中创建一个 XmlReader(如果需要,请先刷新 Writer)。
然后,我需要使用 XmlReader 作为 XslCompiledTransform.Transform 方法
编辑:标点符号
An instance of System.Xml.XmlWriter is writing to an underlying Stream right ?(regardless of what the specific implementation of the XmlWriter is)
So how come there are no methods available for a programmer to retrieve the Stream object from the XmlWriter?
I'm sure I am missing something simple. Thanks in advance.
PS: In case anyone asks, what I really want to do is get the stream from an XmlWriter instance passed to me, and create an XmlReader from it (flush the Writer first if needs be).
I then need to use the XmlReader as a parameter to XslCompiledTransform.Transform method
Edit: punctuation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不应该这样做。即使您知道
XmlWriter
下面有一些Stream
,但这是实现细节,XmlWriter
不应该将其提供给您。流也可以只读或只写,你将如何读取它?如果您知道该流既可以写入也可以读取,则应该将用于实例化
XmlWriter
的原始流传递到要读取该流的位置。否则,您应该创建一个新的流来读取 XmlWriter 写入的内容。You should not do it. Even though you know that
XmlWriter
has someStream
underneath but this is implementation detail andXmlWriter
should not give it to you. Also stream may readonly or writeonly, how will you read from it?You should pass original stream that was used to instantiate
XmlWriter
to the place where you want to read the stream if you know that stream can be both written and read. Otherwise you should create a new stream which will read the content written byXmlWriter
.