你大多不走运。
首先,您正在处理的内容称为“字符引用”,这就是 CreateEntityReference 失败的原因。字符引用存在的唯一原因是提供对给定上下文中非法或难以创建的字符的访问。
定义:字符引用
指的是一个特定的字符
ISO/IEC 10646 字符集,用于
示例一不可直接访问
从可用的输入设备。
(请参阅 XML 规范第 4.1 节 http://www.w3.org/TR/REC-xml/#sec-references)
当 XML 处理器遇到字符引用时,如果在属性值中引用了该字符(也就是说,如果&#xxx
格式在属性内部使用),它被设置为“包含”,这意味着查找其值并替换文本。
字符串“AT&T;
“扩展为”AT&T;
" 剩下的 & 符号是
不被识别为实体引用
分隔符
(请参阅 XML 规范第 4.4 节 http://www.w3.org/TR/REC-xml/#entproc)
这已纳入 XML 规范中,并且 Microsoft XML 堆栈正在执行其需要执行的操作:处理字符引用。
我能看到您做的最好的事情就是看一下这些旧的 XML.com 文章,其中一篇使用 XSL 来禁用输出转义,以便{
会变成{
在输出中。
http://www.xml.com/pub/a/2001/03/14/trxml10.html http://www.xml.com/pub/a/2001/03/14/trxml10.html
<!DOCTYPE stylesheet [
<!ENTITY ntilde
"<xsl:text disable-output-escaping='yes'>&ntilde;</xsl:text>">
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output doctype-system="testOut.dtd"/>
<xsl:template match="test">
<testOut>
The Spanish word for "Spain" is "España".
<xsl:apply-templates/>
</testOut>
</xsl:template>
</xsl:stylesheet>
这个使用 XSL 将特定字符引用转换为其他文本序列(以实现与上一个链接相同的目标)。
http://www.xml.com/lpt/a/1426 http://www.xml.com/lpt/a/1426
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output use-character-maps="cm1"/>
<xsl:character-map name="cm1">
<xsl:output-character character=" " string="&nbsp;"/>
<xsl:output-character character="é" string="&233;"/> <!-- é -->
<xsl:output-character character="ô" string="&#244;"/>
<xsl:output-character character="—" string="--"/>
</xsl:character-map>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>