我有一个简单的 XML 文件
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Document>
<DATEN>
<DTA_Coding_Line>0100011509856>249099000000000000004039555+ 010001456></DTA_Coding_Line>
</DATEN>
</Document>
我已使用多个在线 XML 验证工具验证了此文件,并且它不会产生错误。
但是,在 XML 文档中,我可以看到我必须使用 >
转义 ">"字符。
- 这是强制性的吗?
- 我什么时候必须用
>
替换>
? - 如果读取上述文件的软件存在
>
未转义的问题,是否仍可被视为“符合”XML 标准? - 有这样的“合规性”吗?
最佳答案
">"仅当在内容中的字符串“]]>”中使用时才需要转义,其中字符串“]]>”不标记 CDATA 部分的结尾。
另一方面,“<”和“&”必须始终被转义。
链接到
2.4 Character Data and Markup
Text consists of intermingled character data and markup. [Definition: Markup takes the form of start-tags, end-tags, empty-element tags, entity references, character references, comments, CDATA section delimiters, document type declarations, processing instructions, XML declarations, text declarations, and any white space that is at the top level of the document entity (that is, outside the document element and not inside any other markup).]
[Definition: All text that is not markup constitutes the character data of the document.]
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 " & " and " < " respectively. The right angle bracket (>) may be represented using the string " > ", and MUST, for compatibility, be escaped using either " > " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.
In the content of elements, character data is any string of characters which does not contain the start-delimiter of any markup and does not include the CDATA-section-close delimiter, " ]]> ". In a CDATA section, character data is any string of characters not including the CDATA-section-close delimiter, " ]]> ".
To allow attribute values to contain both single and double quotes, the apostrophe or single-quote character (') may be represented as " ' ", and the double-quote character (") as " " ".
Character Data
[14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
关于xml - XML 文件中是否必须将 ">"替换为 ">"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51816694/