是否绝对强制替换“>"?由“>"在 XML 文件中? [英] Is it absolutely mandatory to replace ">" by ">" in XML files?

查看:29
本文介绍了是否绝对强制替换“>"?由“>"在 XML 文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 XML 文件

I have a simple XML file

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Document>
 <DATEN>
  <DTA_Coding_Line>0100011509856>249099000000000000004039555+ 010001456></DTA_Coding_Line>
 </DATEN>
</Document>

我已经使用多个在线 XML 验证工具验证了该文件,并且没有产生错误.

I have validated this file with several online XML validation tools and it does not create errors.

然而,在 XML 文档中,我可以读到我必须用 &gt; 转义 ">" 字符.

Yet, in XML documentations I can read that I would have to escape the ">" character with &gt;.

  • 这是强制性的吗?
  • 我什么时候必须用 &gt; 替换 >?
  • 如果读取上述文件的软件存在 > 未转义的问题,是否仍可将其视为符合"XML 标准?
  • 有这样的合规性"吗?
  • Is this mandatory at all?
  • When would I have to replace > with &gt;?
  • If the software reading this file above has issues with the > not being escaped, can it still be considered as "compliant" the XML standard?
  • Is there such a "compliancy"?

推荐答案

">" 只在字符串 "]]>" 中使用时才需要转义,其中字符串 "]]>" 未标记结尾CDATA 部分.

">" only needs to be escaped when used in the string "]]>" in content where the string "]]>" is not marking the end of a CDATA section.

另一方面,<"和&"必须总是被转义.

On the other hand, "<" and "&" must always be escaped.

字符数据和标记

链接到哪些

2.4 字符数据和标记

2.4 Character Data and Markup

文本由混合的字符数据和标记组成.[定义:标记采用开始标签、结束标签、空元素标签的形式,实体引用、字符引用、注释、CDATA 部分分隔符、文档类型声明、处理指令、XML声明、文本声明和任何位于文档实体的顶层(即文档外部元素,而不是在任何其他标记内).]

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.]

与符号 (&) 和左尖括号 (<) 不得以字面形式出现,除非用作标记分隔符,或在注释、处理指令或 CDATA 部分中.如果它们在其他地方需要,它们必须使用任一数字进行转义字符引用或字符串"& "和"< "分别.右尖括号 (>) 可以使用字符串"> ",并且必须,为了兼容性,使用任一方法进行转义" > " 或出现在字符串中时的字符引用 " ]]>" 在内容中,当该字符串未标记 CDATA 的结尾时部分.

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.

在元素的内容中,字符数据为任意字符串它不包含任何标记的开始分隔符,并且不包括 CDATA-section-close 分隔符,]]>".在 CDATA部分,字符数据是任何字符串,不包括CDATA-section-close 分隔符," ]]> ".

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 " " ".

字符数据

[14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)

[14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)

这篇关于是否绝对强制替换“>"?由“&amp;gt;"在 XML 文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆