xml - XML 文件中是否必须将 ">"替换为 ">"?

标签 xml xml-parsing

我有一个简单的 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 文档中,我可以看到我必须使用 &gt; 转义 ">"字符。

  • 这是强制性的吗?
  • 我什么时候必须用 > 替换 &gt;
  • 如果读取上述文件的软件存在 > 未转义的问题,是否仍可被视为“符合”XML 标准?
  • 有这样的“合规性”吗?

最佳答案

">"仅当在内容中的字符串“]]>”中使用时才需要转义,其中字符串“]]>”不标记 CDATA 部分的结尾。

另一方面,“<”和“&”必须始终被转义。

Character Data and Markup

链接到

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 文件中是否必须将 ">"替换为 "&gt;"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51816694/

相关文章:

java - 使用 DOM 解析动态内容的 Xml

javascript - 使用Firefox XML DOM解析XML(RSS)

C# WriteAttributeString - 多元素

java - java中解析XML的大多数 "SECURE"方式

ios - 当我回来时,TableView 显示相同的数据两次或更多次?

java - 从许多属性中,我需要获取其中之一并使用 jaxb 在 xml 字符串中打印

xml - 类型 - 在 go 中解码 XML

android - 如何创建具有最小和最大高度的布局?

php - 在 php 中使用 simplexml 获取 xml 中的父元素?

java - 读取和写入 xml 字符串的最简单且最简单的 java API 是什么?