0

我目前正在开发必须从 XML 流中读取数据的程序,该数据有时可能包含“&”符号

IE :

<XMLRoot>
    <Element>
        <Node>
            This is a dummy data&more!
        </Node>
    </Element>
</XMLRoot>

当我解析此文本时,我收到一条错误消息,告诉我“对未声明实体的引用”。

有没有办法用 C# 的 XMLParser 删除“实体检查”?

4

1 回答 1

5

我相信问题在于您发布的 XML 是格式错误的 XML,“&”是 XML 中的保留字符,需要转义或包含在 CDATA 部分中:

<XMLRoot>
<Element>
    <Node>
        This is a dummy data&amp;more!
    </Node>
</Element>
</XMLRoot>

或者:

<XMLRoot>
<Element>
    <Node>
        <![CDATA[ This is a dummy data&more! ]]>
    </Node>
</Element>
</XMLRoot>
于 2009-06-04T02:34:40.500 回答