为什么在 xml 中允许多个 '>'

why are multiple '>' allowed in xml

这是一个“有效”XML:

<?xml version="1.0"?><class>>>>>>>>>>>>>>>>>>>>>>>>>>>>><abc att="da"/></class>

我有一个相对简单的问题:为什么这个 XML 被几乎所有可能的解析器正确验证? 我检查了 w3.org https://www.w3.org/TR/2008/REC-xml-20081126/ 的最新 xml 规格,但我找不到与此相关的任何内容。这是特定于实现的东西吗?

符号“<”不能多次使用,即

<?xml version="1.0"?><class><<abc att="da"/></class>

这个XML无效。

https://www.w3.org/TR/2008/REC-xml-20081126/#syntax

The ampersand character (&) and the left angle bracket (<) must not appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they must be escaped using either numeric character references or the strings "&amp;" and "&lt; " respectively. The right angle bracket (>) may be represented using the string "&gt;", and must, for compatibility, be escaped using either "&gt;" or a character reference when it appears in the string "]]>" in content, when that string is not marking the end of a CDATA section.

如果您有一个未编码的文字 <,那么解析器将假设您正在启动一个元素。你不能有它们的序列,因为你不能在元素名称中有 <

如果您有未编码的文字 >,则关闭元素不会造成任何混淆。它只是一个元素的 text() 节点中的 > 序列。

您可以将 < 编码为 &lt;:

<class>&lt;<abc att="da"/></class>