XML中的CDATA(字符数据)

Introduction

介绍

The Term CDATA basically refers to Character Data. In XML it is basically a block of texts or sentences that are not parsed by the parser and are treated as regular English text. It is difficult to read predefined entities such as &lt(),&amp(&) in the markup. For such situation, the concept of CDATA section introduced. In this section basically, we are commanding the parser that this particular section of XML document doesn’t contain markup and consider them as normal plain text.

术语CDATA基本上是指字符数据 。 在XML中,它基本上是解析器未解析的文本或句子的一部分,被视为常规英语文本。 很难读取标记中的预定义实体,例如&lt(),&amp(&)。 针对这种情况,引入了CDATA部分的概念。 基本上,在本部分中,我们命令解析器确保XML文档的这一特定部分不包含标记,并将其视为普通纯文本。

Syntax

句法

Basic syntax of CDATA section as follows:

CDATA部分的基本语法如下:

    <![CDATA[
        code  with markup
    ]]>

Characteristics

特点

CDATA section basically composed of three section these are as follows:

CDATA部分主要由以下三个部分组成:

  1. CDATA Start section: CDATA starts with nine character delimiter that is <![CDATA[.

    CDATA开始部分: CDATA以九个字符定界符开始,即<![CDATA [ 。

  2. CDATA End section: CDATA basically ends with three character delimiter that is ]]>.

    CDATA结束部分: CDATA基本上以三个字符定界符结尾,即]]> 。

  3. CData section: Characters written between Cdata Start section and Cdata End Section will be treated as characters, not as markup.

    CData部分:在Cdata起始部分和Cdata结束部分之间写入的字符将被视为字符,而不是标记。

In this section, we basically deal with characters such as (, and &) but these characters are ignored by the processor of XML.

在本节中,我们基本上处理诸如( , && )之类的字符,但是这些字符被XML处理器忽略。

CDATA Rules

CDATA规则

There are some basic rules to write CDATA section

有一些写CDATA部分的基本规则

  1. CDATA cannot contain the string ]]< anywhere in the XML document.

    CDATA不能在XML文档的任何地方包含字符串]] < 。

  2. We cannot put CDATA section under another CDATA section in other words we can say that nesting is not allowed in CDATA.

    我们不能将CDATA节放在另一个CDATA节的下面,换句话说,我们可以说CDATA中不允许嵌套。

Usefulness of CDATA

CDATA的有用性

These sections are useful when we cannot write XML code within the XML document.

当我们无法在XML文档中编写XML代码时,这些部分很有用。

For example, if a user wants to write a book with XSL which have an explanation about the use of an XML application, the XML markup which is going to appear in the book will be going to write in the source file in a CDATA section which will be ignored by the processor of XML.

例如,如果用户想用XSL编写一本关于XML应用程序使用说明的书,那么将要出现在书中的XML标记将被写在CDATA部分的源文件中, XML处理器将忽略它。

Examples of CDATA

CDATA的例子

Following is an example of CDATA here each character written inside CDATA section is ignored by parser.

以下是CDATA的示例,此处解析器忽略CDATA节中写入的每个字符。

<![CDATA[
	IncludeHelp!!!
]] >

In the above example IncludeHelp!!! which is written inside the is treated as character not as markup.

在上面的示例中,IncludeHelp !!! 写在里面 被视为字符而不是标记。

Lets try to understand this using following examples. The following example basically stores the student information that is name.

让我们尝试使用以下示例来理解这一点。 以下示例基本上存储了作为名称的学生信息。

<?xml version="1.0" encoding="UTF-8"?>
<student>
	<stu_info rollno="7">
		<name>
			<firstname>Akash</firstname>
			<lastname>Sharma</lastname>
		</name>
		<contact_info>
			<entities>
				<![CDATA[
					This is the CDATA area.
					We are basically storing special character that are recognize.
				]]>
			</entities>
		</contact_info>
	</stu_info>
</student>


翻译自: https://www.includehelp.com/XML/character-data-cdata-in-xml.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值