当前位置: 首页 > 网络学院 > XML相关教程 > XML > XML CDATA

XML
XML 介绍
XML 的用途
XML 语法规则
XML 元素
XML 属性
XML 的有效性验证
XML 校验器
支持 XML 的浏览器
浏览 XML 文件
用 CSS 显示 XML
用 XSL 显示 XML
XML 数据岛
XML 解析器
现实中的 XML
XML 命名空间
XML CDATA
XML 服务器
XML 应用程序
XMLHttpRequest 对象
XML 保存数据

XML CDATA


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 807 ::
收藏到网摘: n/a

All text in an XML document will be parsed by the parser.
XML文档中的所有文本都会被解析器解析。

Only text inside a CDATA section will be ignored by the parser.
只有在CDATA片断内的文本会被解析器忽略。


Parsed Data
被解析的数据

XML parsers normally parse all the text in an XML document.
XML解析器通常会解析XML文档内的所有文本内容。

When an XML element is parsed, the text between the XML tags is also parsed:
当XML元素被解析时,XML标签之间的文本内容也会被解析:

<message>This text is also parsed</message>

The parser does this because XML elements can contain other elements, as in this example, where the <name> element contains two other elements (first and last):
解析器这样做是因为XML元素中可能包含其它的元素。如在下面这个案例中,<name>元素含有其它两个元素(第一个和最后一个):

<name><first>Bill</first><last>Gates</last></name>

and the parser will break it up into sub-elements like this:
解析器会把它分解成下面这样的子元素:

<name>
<first>Bill</first>
<last>Gates</last>
</name>

 


Escape Characters
转义符

Illegal XML characters have to be replaced by entity references.
非法的XML字符必须由实体参数替代。

If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element. You cannot write something like this:
如果你在一个XML元素中放置一个 "<" 字符,就会产生错误,因为解析器会误认为它是新元素的开始。你不可以写成下面这样:

<message>if salary < 1000 then</message>

To avoid this, you have to replace the "<" character with an entity reference, like this:
为了避免这种情况的发生,你必须使用一个实体参数来替换 "<" ,如下所示:

<message>if salary &lt; 1000 then</message>

There are 5 predefined entity references in XML:
在XML里,包含5个预定义的实体参数:

&lt; < less than[小于]
&gt; > greater than[大于]
&amp; & ampersand [和]
&apos; ' apostrophe[省略号]
&quot; " quotation mark[引号]


注意:
只有字符"<" 和 "&" 在XML里是严格意义上非法的。省略符,引号和更高级的符号是合法的,用"<" 和 "&"代替它们是更为简便的方法。


CDATA

Everything inside a CDATA section is ignored by the parser.
在CDATA片断内的一切内容都会被解析器忽略。

If your text contains a lot of "<" or "&" characters - as program code often does - the XML element can be defined as a CDATA section.
如果你的文本中包含大量的 "<" 或 "&" 字符——就象程序码中经常的那样——XML元素可以被定义为一个CDATA部分。

A CDATA section starts with "<![CDATA[" and ends with "]]>":
一个CDATA片断由 "<![CDATA[" 开始,由 "]]>" 结束:

<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1
}
else
{
return 0
}
}
]]>

</script>

In the example above, everything inside the CDATA section is ignored by the parser.
在上述案例中,CDATA片断中的所有内容都被解析器忽略了。

Notes on CDATA sections:
CDATA片断的注意事项:

A CDATA section cannot contain the string "]]>", therefore, nested CDATA sections are not allowed.
CDATA片断不能包含字符串 "]]>",因此,嵌套CDATA片断是不允许的。

Also make sure there are no spaces or line breaks inside the "]]>" string.
同时还要注意:在 "]]>" 字符串内不应该包含空格或换行键。

评论 (1) 1 All

登陆 | 还没注册?