在这个问题上有几个帖子,但没有一个解决方案似乎适合我。不确定我做错了什么。 我试图读取一个如下所示的XML文件:
<?xml version="1.0"?>
<content languageCode="en" languageID="1">
<ftypeparser>c:\users\pdeoliveira\Documents\Xmlparsernew.xml</ftypeparser>
<xmlparser>c:\users\pdeoliveira\Documents\Xmlparser.xml</xmlparser>
<sourcelocation>c:\localization\2015</sourcelocation>
<rpkfile>RPK_DefaultSyllabi_2015.xml</rpkfile>
<loglocation>c:\users\pdeoliveira\Documents\Buildloc_Log.txt</loglocation>
<losefiles><locfile>c:\localization\2015\Strings.xml</locfile></losefiles>
</content>
以下是读取它的代码:
XmlDocument doc = new XmlDocument();
string filetoload = "config.xml";
try
{
doc.Load(filetoload);
}
catch (Exception e)
{
Console.Writeline(e);
}
这是我得到的例外:
System.Xml.XmlException: Reference to undeclared entity 'nbsp'. Line 1960, position 12.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.HandleGeneralEntityReference(String name, Boolean isInAttributeValue, Boolean pushFakeEntityIfNullResolver, Int32 entityStartLinePos)
at System.Xml.XmlTextReaderImpl.ResolveEntity()
at System.Xml.XmlLoader.LoadEntityReferenceNode(Boolean direct)
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(String filename)
at ConsoleApplication9.Program.getrestype(String fname) in c:\Users\pdeoliveira\Documents\Visual Studio 2013\Projects\BuildLoc\BuildLoc\Program.cs:line 1067
我尝试使用其他帖子中建议的声明:
<!DOCTYPE doctypeName [
<!ENTITY nbsp " ">
]>
那也没有用。有趣的是,我的文件只有10行左右,它指向1960年的一个问题......? 任何帮助,将不胜感激。