0

我已经实例化了 XmlDocument,然后尝试在文件 pat 中加载带有非拉丁符号的 XML 文件。在加载文件期间,我面临着

 ArgumentNullException 

带有消息:

"Value cannot be null. Parameter name: str"

堆栈跟踪是 -

at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
at System.Uri.ParseConfigFile(String file, IdnScopeFromConfig& idnStateConfig, IriParsingFromConfig& iriParsingConfig)
at System.Uri.GetConfig(UriIdnScope& idnScope, Boolean& iriParsing)
at System.Uri.InitializeUriConfig()
at System.Uri.InitializeUri(ParsingError err, UriKind uriKind, UriFormatException& e)
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlTextReaderImpl..ctor(String url, XmlNameTable nt)
at System.Xml.XmlTextReader..ctor(String url, XmlNameTable nt)
at System.Xml.XmlDocument.Load(String filename)
at .... 

我的代码有一部分:

var xmlData = new XmlDocument();
if (File.Exists(xmlPath))
{        
    xmlData.Load(xmlPath);
    ...
}

xmlPath 包含法语字母。

怎么了?如何打开非拉丁字符的 xml 文件?

4

2 回答 2

0

我找到了使用其他类进行数据加载的问题的解决方案,如下所示:

var d = File.ReadAllText(xmlPath);
xmlData.LoadXml(d);

但是问题 - “怎么了?” 还开着。

于 2012-10-05T14:08:52.457 回答
0

首先将文件路径加载到uri中:

Uri xmlUri = new Uri(xmlPath);
xmlData.Load(xmlUri.AbsolutePath);
于 2012-10-05T18:42:20.907 回答