为什么XML中的CDATA语法看起来很奇怪?(Why does the CDATA syntax in XML look so strange?)

编程入门 行业动态 更新时间:2024-10-24 16:25:24
为什么XML中的CDATA语法看起来很奇怪?(Why does the CDATA syntax in XML look so strange?)

CDATA在XML中使用如下所示:

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

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

我的问题:为什么CDATA部分看起来像是这样的,是否有理由,例如是某种SGML事物的特例? 或者有些语言设计者有一天会想:“我会在CDATA之前用CDATA做一个CDATA部分,之后是一个括号,一个感叹号,并用尖括号包围起来。”

CDATA is used in XML like:

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

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.

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)分隔符。 接下来是状态关键字,接下来是第二个声明子集打开(dso)分隔符。 标记部分以标记部分关闭(msc)分隔符后跟标记声明关闭(mdc)分隔符结束。 因此标注部分声明的抽象语法是:

mdo dso status-keyword dso my-data msc mdc

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

标记声明打开: <! 声明子集打开: [ 标记栏关闭: ]] 标记声明关闭: >

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

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

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

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

这使我们能够:

<![ CDATA [my-data]]>

请参阅Martin Bryan撰写的SGML和HTML解释手册中的以下章节:

SGML声明 标记的部分和处理说明

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

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

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

Which brings us to:

<![ CDATA [my-data]]>

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

The SGML Declaration Marked Sections and Processing Instructions

更多推荐

本文发布于:2023-08-05 18:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1435724.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:很奇怪   语法   CDATA   XML   syntax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!