在根级别的数据无效级别、数据

由网友(℡昔年、作别旧梦。)分享简介:我有以下XML文档:当我试图通过C#来访问它:When I try to access it through c#:XmlDocu...

我有以下XML文档:

<?xml version="1.0" encoding="UTF-8"?>
<Offices id="0" enabled="false">
  <office />
</Offices>

当我试图通过C#来访问它:

When I try to access it through c#:

XmlDocument doc = new XmlDocument();
doc.LoadXml(HttpContext.Current.Server.MapPath("officeList.xml"));

我得到这个错误:

I get this error:

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

Data at the root level is invalid. Line 1, position 1.

请告诉我错此行??

推荐答案

本:

doc.LoadXml(HttpContext.Current.Server.MapPath("officeList.xml"));

应该是:

doc.Load(HttpContext.Current.Server.MapPath("officeList.xml"));

的loadXML()是加载XML字符串,而不是一个文件名。

LoadXml() is for loading an XML string, not a file name.

阅读全文

相关推荐

最新文章