在根级别的数据无效 [英] Data at the root level is invalid

查看:624
本文介绍了在根级别的数据无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下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.

这篇关于在根级别的数据无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆