引用了未声明的实体“NBSP”,而从URL在C#中读取XML? [英] Reference to undeclared entity 'nbsp' while reading xml from URL in c#?

查看:1457
本文介绍了引用了未声明的实体“NBSP”,而从URL在C#中读取XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 的XmlDocument xmlDoc中=新的XmlDocument();
    xmldoc.XmlResolver = NULL;

    xmldoc.Load(URL);
    的XmlWriter xmlWrite = XmlWriter.Create(@使用Server.Mappath(的test.xml));
    xmldoc.Save(xmlWrite);
    xmlWrite.Close();
 

以上是code我使用读取XML文件。我加载XML包含类似实体 NBSP; 正因为如此,在code被抛出XMLException:

  

引用了未声明的实体NBSP

解决方案

有两种方式来处理这个问题,但为你需要的修改输入文件。

1)改变你的&放大器; NBSP; &放大器;#160; 在你输入文件。它始终是更好地使用统一code和避免在XML文档中读取的实体。使用普通的Uni code字符或数字的形式。

2)如果你还需要/想使用&放大器; NBSP; 你可以声明自定义文档类型的文件中,将做转换为你:

 <!DOCTYPE doctypeName [
   <!实体NBSP&放大器;#160;>
]≥
 

这个问题来,因为&放大器; NBSP; 不是XMLS predefined实体之一

    XmlDocument xmldoc = new XmlDocument();
    xmldoc.XmlResolver = null;

    xmldoc.Load("URL");
    XmlWriter xmlWrite = XmlWriter.Create(@Server.MapPath("Test.xml"));
    xmldoc.Save(xmlWrite);
    xmlWrite.Close();

Above is the code I am using to read an XML file. The XML I am loading contains entities like nbsp; and because of that, the code is throwing an XMLException:

Reference to undeclared entity 'nbsp'

解决方案

There are two ways to handle this, but for both you need to make changes to the input file.

1) Change your   to   in you input files. It is always better to use Unicode and avoid readable entities in XML documents. Use plain Unicode characters or their numerical form.

2) If you still need/want to use   You can declare a custom doctype in the file that will do the conversion for you:

<!DOCTYPE doctypeName [
   <!ENTITY nbsp "&#160;">
]> 

This problem is coming because &nbsp; isn't one of XMLs predefined entities.

这篇关于引用了未声明的实体“NBSP”,而从URL在C#中读取XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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