如何停止XPathDocument关闭流?

用户名

调用XPathDocument(Stream)构造函数时,流将自动关闭。如何保持流打开?

用户名

StreamStringTextReader过载使用内部的System.Xml.XmlTextReaderImpl类。此类设置closeInputtrue

如果要避免这种情况,则需要使用XmlReader重载。它使用未修改的情况下XmlReaderSettings,对于其中的默认值CloseInputfalse不要忘记将其设置Position0之后。

var reader = XmlReader.Create(stream);
var document = new XPathDocument(reader);
stream.Position = 0;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章