简体   繁体   中英

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. 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? 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.

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

  • 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 object

async Property

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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