本文介绍了而使用XML引用了未声明的实体异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置xmlDoc中的innerxml但得到异常:引用了未声明实体

I am trying to set the innerxml of a xmldoc but get the exception: Reference to undeclared entity

XmlDocument xmldoc = new XmlDocument();
string text = "Hello, I am text α   – —"
xmldoc.InnerXml = "<p>" + text + "</p>";

这引发异常:

引用了未声明实体'阿尔法'。 2号线,位置2 ..

我将如何去解决这个问题呢?

How would I go about solving this problem?

推荐答案

XML,HTML不像没有定义实体(UNI到code字符即命名引用),所以和放大器;字母; &安培; MDASH;等不被翻译成其相应的字符。您必须使用数值来代替。您只能使用与放大器; LT;和&放大器;放大器;在XML

XML, unlike HTML does not define entities (ie named references to UNICODE characters) so &alpha; &mdash; etc. are not translated to their corresponding character. You must use the numerical value instead. You can only use &lt; and &amp; in XML

如果您要创建HTML,使用的HTMLDocument来代替。

If you want to create HTML, use an HtmlDocument instead.

这篇关于而使用XML引用了未声明的实体异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:15