Difference between PCDATA and CDATA

博客介绍了XML中#PCDATA和CDATA的相关知识。#PCDATA指定元素包含解析后的字符数据,解析时会测试字符是否符合XML 1.0的词法约束;CDATA用于属性声明,表明属性包含未解析的字符数据。还说明了二者作为标记在元素和属性声明中的作用及相关特殊字符的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

> #PCDATA [...] specifies that an element will contain parsed
> character data. Parsing tests whether the characters conform to the
> lexical constraints imposed by XML 1.0.
>
> CDATA appears in attribute declarations and specifies that an
> attribute will contain character data that is not parsed.

That's not accurate. All characters in an XML document are "parsed" in
the sense that you describe.

"CDATA" is a token used in an attribute declaration to declare the
attribute as having a string type. '&', and '<' and the quote character
used for delimiting the attribute value have special meaning in
attributes of this type.

"#PCDATA" is a token used in an element declaration to declare the
element as having mixed content (character data, or character data mixed
with other elements). The content of the element is parsed; '&' and '<'
have special meaning and must be escaped if they aren't the start of
markup.

A "CDATA section", bounded in markup by "<![CDATA[" and "]]>" is, by
comparison, "unparsed" character data (though even it is subject to at
least one restriction -- it can't contain "]]>"). A CDATA section can
only appear in element content, and it has nothing to do with the
"CDATA" token used in attribute decls.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值