需要了解 - 为什么 CDATA 部分被视为 <![CDATA[ 和 ]]>? [英] Need to understand - why CDATA section is treated as if the <![CDATA[ and ]]>?

查看:17
本文介绍了需要了解 - 为什么 CDATA 部分被视为 <![CDATA[ 和 ]]>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读一本教科书来学习XPath.我从那本书中找到的下面一行:

I was reading a text book to learn XPath. And the below line I found from that book:

XPath 如何处理 XML CDATA 部分中的文本?CDATA 部分中的每个字符都被视为字符数据.换句话说,CDATA 部分被视为 ]]> 被删除,并且每次出现像 <;& 被替换为相应的字符实体,如 &lt;&amp;.

How does XPath handle text in XML CDATA sections? Each character within a CDATA section is treated as character data. In other words, a CDATA section is treated as if the <![CDATA[ and ]]> were removed and every occurrence of markup like < and & was replaced by the corresponding character entities like &lt; and &amp;.

但是书中并没有给出任何例子来解释上面的句子.任何人都可以帮助我理解作者在下面要说的内容:

But the book didn't give any examples to explain the above sentences. Can any one help me to understand what the Author tried to say in the below:

CDATA 部分被视为 <![CDATA[]]> 被删除,并且每次出现类似 的标记<& 被替换为相应的字符实体,如 &lt;&amp;.强>

a CDATA section is treated as if the <![CDATA[ and ]]> were removed and every occurrence of markup like < and & was replaced by the corresponding character entities like &lt; and &amp;.

推荐答案

我反过来想 - <![CDATA[ 和下一个 ]] 之间的一切> 被视为文本,不受实体引用的通常解码的约束,并且 < 符号不引入元素名称.所以

I think of it the other way round - everything between a <![CDATA[ and the next ]]> is treated as text, and not subject to the usual decoding of entity references, and < signs don't introduce element names. So

<something><![CDATA[<foo>text&more</foo>]]></something>

<something>&lt;foo>text&amp;more&lt;/foo></something>

<something><foo>text&more</foo></something>

不是格式良好的 XML(因为 & 被视为实体引用的开始,但没有相应的 ; 结束它).

is not well-formed XML (because the & is treated as the start of an entity reference but there's no corresponding ; to end it).

这篇关于需要了解 - 为什么 CDATA 部分被视为 &lt;![CDATA[ 和 ]]&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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