为什么XML中的CDATA语法看起来如此奇怪? [英] Why does the CDATA syntax in XML look so strange?

查看:47
本文介绍了为什么XML中的CDATA语法看起来如此奇怪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CDATA在XML中的使用方式如下:

CDATA is used in XML like:

<my-tag><![CDATA[my-data]]></my-tag>

这是一个非常不寻常的语法。当我第一次看到它时,我以为它是我尚未学习的某种通用XML构造的特定形式。但是,据我所知( XML CDATA规范

It's quite an unusual syntax. When I first saw it, I assumed it was a specific form of some general XML construct I had yet to learn. But, as far as I can tell (XML CDATA spec) it isn't.

我的问题:CDATA部分看起来像是有原因的吗,例如我是SGML的特例吗?还是某个语言设计人员只是想过某天我将在CDATA的CDATA部分之前创建一个括号,然后在括号中放置一个感叹号,并用尖括号将其包围。

My question: Is there a reason why the CDATA section looks like it does, e.g. is i a special case of some SGML thing? Or did some language designer just think one day "I'll make a CDATA section with a bracket before CDATA, a bracket afterwards, an exclamation mark, surrounded by angle brackets."

推荐答案

CDATA部分是带标记的部分。在SGML中,既有抽象语法又有具体语法。标记节声明的抽象语法以标记声明打开(mdo)分隔符开头,然后是声明子集打开(dso)分隔符。接下来是 status关键字,其后是第二个声明子集打开的(dso)分隔符。标记的段以标记的段关闭(msc)分隔符结尾,然后是标记声明关闭(mdc)分隔符。因此,标记的节声明的抽象语法为:

The CDATA section is a marked section. In SGML there is both an abstract syntax as well as a concrete syntax. The abstract syntax of a marked section declaration begins with a markup declaration open (mdo) delimiter followed by a declaration subset open (dso) delimiter. A status keyword comes next followed by a second declaration subset open (dso) delimiter. A marked section ends with a marked section close (msc) delimiter followed by a markup declaration close (mdc) delimiter. Therefore the abstract syntax of a marked section declaration is:

mdo dso status-keyword dso my-data msc mdc

为每个文档定义了具体语法。在与每个文档关联的SGML声明中指定了此语法。具体语法定义了用于文档的定界符。我假设在ISO 8879:1986中定义了默认的SGML分隔符,如下所示:

A concrete syntax is defined for each document. This syntax is specified within the SGML declaration associated with each document. The concrete syntax defines the delimiters to be used for the document. The default SGML delimiters, which I assume are defined in ISO 8879:1986, are as follows:


  • 标记声明打开:<!

  • 打开声明子集: [

  • 标记的节关闭:]]

  • 标记声明关闭:>

  • Markup declaration open: <!
  • Declaration subset open: [
  • Marked section close: ]]
  • Markup declaration close: >

但是您可以自由定义自己的具体语法,因此可以修改用作定界符的字符。

But you are free to define your own concrete syntax and so can modify the characters used as the delimiters.

因此标记的节声明的默认具体语法为:

Therefore the default concrete syntax of a marked section declaration is:

<![ status-keyword [my-data]]>

可能的状态关键字为:CDATA,RCDATA,IGNORE,INCLUDE, TEMP

Possible status-keywords are: CDATA, RCDATA, IGNORE, INCLUDE, TEMP

这将我们带到:

<![ CDATA [my-data]]>

请参阅Martin Bryan所著的 SGML和HTML解释的书中的以下章节:

See the following chapters from the book SGML and HTML Explained by Martin Bryan:

  • The SGML Declaration
  • Marked Sections and Processing Instructions

这篇关于为什么XML中的CDATA语法看起来如此奇怪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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