encoding'是一个意外的令牌。预期的令牌是'?>'将XML数据读入DataSet时

时间:2013-09-03 10:26:18

标签: c# xml

当我的xml文件数据使用Readxml读入DataSet时,我遇到了运行时错误。

“encoding”是一个意外的令牌。预期的令牌是'?>'“

我的C#代码是:

XmlReader xmlFile = XmlReader.Create("WH7_Inventory.xml", new XmlReaderSettings());            
DataSet ds = new DataSet();
ds.ReadXml(xmlFile);

我的xml文件是

<?xml version="1.0" encoding="UTF-8" standalone="true"?>

1 个答案:

答案 0 :(得分:0)

standalone的属性值不正确。它应该是yesno

请参阅Standalone Document Declaration

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

虽然假设这是您在XML文档中的全部内容,但由于没有根元素,您可能仍会收到错误。