简体   繁体   English

为什么 XmlDocument.Load(String) 似乎想要读写访问?

[英]Why does XmlDocument.Load(String) seem to want read-write access?

According to MSDN the .NET XmlDocument.Load(String) method requires write access to the underlying file.根据 MSDN,.NET XmlDocument.Load(String)方法需要对底层文件进行访问。 The exceptions list says例外清单说

UnauthorizedAccessException :  filename specified a file that is read-only....

My question boils down to我的问题归结为

  • Is it even true that read-write access is needed, or is this just a documentation error?是否真的需要读写访问权限,或者这只是一个文档错误?
  • Does it mean that the file is kept open during the lifetime of the object?这是否意味着文件在对象的生命周期内保持打开状态?
  • Does it mean that modifications to the the XmlDocument and its sub-nodes can result in live modifications to the file on disk?这是否意味着对 XmlDocument 及其子节点的修改会导致对磁盘上的文件进行实时修改? Even without an explicit save.即使没有明确的保存。

Is it even true that read-write access is needed是否真的需要读写访问权限

  • Looks like documentation bug.看起来像文档错误。 When loading, XmlDocument creates XmlReader , which, AFAIK, doesn't throws such exceptions.加载时, XmlDocument会创建XmlReader ,AFAIK 不会引发此类异常。

Does it mean that the file is kept open during the lifetime of the object这是否意味着文件在对象的生命周期内保持打开状态

  • No, file becomes closed after reading.不,文件在阅读后关闭。

Does it mean that modifications to the the XmlDocument and its sub-nodes can result in live modifications to the file on disk这是否意味着对 XmlDocument 及其子节点的修改会导致对磁盘上的文件进行实时修改?

  • No, because the file is closed.不,因为文件已关闭。

with async attribute set to False as in XDoc.async = False , the read-only xml does not get loaded into DOM objectXDoc.async = False async属性设置为False ,只读 xml 不会加载到 DOM 对象中

async Property 异步属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM