c# - "Data at the Root Level is invalid"与 LoadXml

标签 c# xml

我有一个代码片段:

XmlDocument doc = new XmlDocument();
try
{
    doc.LoadXml(xmlPath);
}
catch (Exception ex)
{
    string exMessage = ex.Message; 
}

XML 看起来像这样

  <?xml version="1.0" encoding="UTF-8"?>
  <MimeTypes>
   <MimeType>
     <Extension>.3dm</Extension>
     <Value>x-world/x-3dmf</Value>
   </MimeType>
  </MimeTypes>

它产生这个错误:

根级别的数据无效。第 1 行,位置 1。

知道哪里出了问题吗?

最佳答案

使用 doc.Load(xmlPath)。 LoadXML 用于加载 XML 字符串。

关于c# - "Data at the Root Level is invalid"与 LoadXml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1445340/

相关文章:

c# - 为什么不调用此 C# 实例构造函数,除非存在对非静态成员的引用?

c# - 如何动态调用带有可选参数的方法?

java - 在 Unity 中使用自定义 list 文件和权限?

c# - 将在线 XML 文件中的条目写入隔离存储

xml - XSD 中的日期格式联合

c# - 使用 jquery ajax 调用 C# webmethod 省略可选参数

c# - 使用linq合并表类数据结构的有效方法

c# - 术语 "DBset can be used when the type of entity is not known at build time"是什么意思?

java - 如何读取 HTTP POST 请求返回的 XML?

jquery - 奇怪的 jQuery AJAX 行为 : XML comes back as #document and not object