使用XDocument.Load解析Xml文档(file.FullName) [英] Parsing Xml Document by using XDocument.Load(file.FullName)
问题描述
大家好,我正在使用XDocument.Load(文件)读取XML文件。它将异常提示为对未申报实体的反对'和复制'。背后的原因是,在xml文件中实体'©'就在那里。有没有人知道摆脱它的解决方案.. ??在此先感谢。
以下是参考的简单代码::
FileInfo fi = new FileInfo(value);
如果(!fi.Exists)抛出新的异常(xml缺失!);
返回XDocument。加载(fi.FullName);
Hi all , I am reading the XML file by using XDocument.Load(file). it prompt the exception as "refrence to undeclared entity '©' ". Reason behind is, in the xml file entity '©' is there. Is there anybody knows the solution to get out of it..?? Thanks in advance.
Here is the simple code for the reference::
FileInfo fi = new FileInfo(value);
if (!fi.Exists) throw new Exception("xml missing!");
return XDocument.Load(fi.FullName);
推荐答案
XML文件必须只包含有效字符:
请参阅:
http://en.wikipedia.org/wiki/Valid_characters_in_XML [ ^ ]
解决方法可能是阅读XML文件作为文本
然后替换任何不需要的字符。
然后你必须解析清理过的XML字符串,如下所述:
https://msdn.microsoft.com/de- de / library / ce3x426k(v = vs.110).aspx [ ^ ]
An XML file must contain only valid characters:
See here:
http://en.wikipedia.org/wiki/Valid_characters_in_XML[^]
A workaround could be to read the XML file as text
and then replace any unwanted characters.
Then you must parse the cleaned XML string as described here:
https://msdn.microsoft.com/de-de/library/ce3x426k(v=vs.110).aspx[^]
这篇关于使用XDocument.Load解析Xml文档(file.FullName)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!