是& gt;有必要吗 [英] Is > ever necessary?
问题描述
& gt;
的情况>
。所有的歧义都可以通过引用
,&
, code>和'
单独。
有没有人曾经遇到过一个情况(例如, SGML处理,浏览器问题,XSLT,...)你发现它不可避免地用& gt;
?
更新:我刚检查过 XML规范< a>,例如,关于第2.4节中的字符数据:
字符数据
[14] CharData :: = [^&] *']]>'[^< &] *)
所以即使在那里,>
不被提及作为特殊的东西,除了从CDATA部分的结束顺序。
这一个单一的情况,其中>
有任何意义,将是CDATA部分的结尾,]]>
,但是再一次,如果你引用它,引用(即文字字符串] ]& gt;
)将直接在输出中(因为它是 )。
解决方案你不需要绝对的,因为几乎任何XML解释器都会明白你的意思。但是如果你这样做,你仍然使用一个没有任何保护的特殊字符。
XML是关于语义的,这并不是真正符合语义的。
$ b
关于您的更新,您忘记了这一部分:
直角括号(>)可以使用字符串>来表示,并且为了兼容,必须使用& gt;
或字符引用转义出现在字符串]]>
内容中,当该字符串未标记CDATA节的结尾。
文档中给出的用例更多的是这样的:
< XmlMarkup中>
]]>
< / xmlmarkup>
这里]]>
对于旧的SGML解析器来说,这是一个问题,因此必须必须转义为= ]]& gt;
b $ b
I now develop websites and XML interfaces since 7 years, and never, ever came in a situation, where it was really necessary to use the >
for a >
. All disambiguition could so far be handled by quoting <
, &
, "
and '
alone.
Has anyone ever been in a situation (related to, e.g., SGML processing, browser issues, XSLT, ...) where you found it indespensable to escape the greater-than sign with >
?
Update: I just checked with the XML spec, where it says, for example, about character data in section 2.4:
Character Data
[14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
So even there, the >
isn't mentioned as something special, except from the ending sequence of a CDATA section.
This one single case, where the >
is of any significance, would be the ending of a CDATA section, ]]>
, but then again, if you'd quote it, the quote (i.e., the literal string ]]>
) would land literally in the output (since it's CDATA).
解决方案 You don't need to absolutely because almost any XML interpreter will understand what you mean. But still you use a special character without any protection if you do so.
XML is all about semantic, and this is not really semantic compliant.
About your update, you forgot this part :
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.
The use case given in the documentation is more about something like this :
<xmlmarkup>
]]>
</xmlmarkup>
Here the ]]>
part could be a problem with old SGML parsers, so it must be escaped into = ]]>
for compatibilities reasons.
这篇关于是& gt;有必要吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!