需要了解 - 为什么 CDATA 部分被视为 <![CDATA[ 和 ]]>? [英] Need to understand - why CDATA section is treated as if the <![CDATA[ and ]]>?
问题描述
我正在阅读一本教科书来学习XPath.我从那本书中找到的下面一行:
I was reading a text book to learn XPath. And the below line I found from that book:
XPath 如何处理 XML CDATA 部分中的文本?CDATA 部分中的每个字符都被视为字符数据.换句话说,CDATA 部分被视为 和
]]>
被删除,并且每次出现像 <;
和 &
被替换为相应的字符实体,如 <
和 &
.
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<
and&
.
但是书中并没有给出任何例子来解释上面的句子.任何人都可以帮助我理解作者在下面要说的内容:
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[
和 ]]>
被删除,并且每次出现类似 的标记<
和 &
被替换为相应的字符实体,如 <
和 &
.强>
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<
and&
.
推荐答案
我反过来想 - <![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><foo>text&more</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 部分被视为 <![CDATA[ 和 ]]>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!