XML CDATA

来源:互联网 发布:网络女主播自我介绍 编辑:程序博客网 时间:2024/05/16 07:43

最近在尝试用osgearth做个三维数据展示平台,看到 feature_stencil_polygon_draping.earth中的代码:


<map name="Feature Stencil Demo" type="geocentric" version="2">



  <options lighting="false"/>


  <image name="world" driver="gdal">
    <url>/data/world.tif</url>
  </image>


  <model name="countries" driver="feature_stencil">


    <!-- Configure the OGR feature driver to read the shapefile.
             Applying a slight negative buffer will "erode" the
             shapes, highlighting the borders between countries. -->


    <features name="states" driver="ogr">
      <url>/data/world.shp</url>
      <buffer distance="-0.05"/>
    </features>


    <!-- Since some countries span large areas on the globe, we need to
             use a larger-than-normal extrusion distance on the stencil
             volumes. (300000 is the default for a geocentric map.) -->


    <extrusion_distance>400000</extrusion_distance>


    <!-- Define a feature style class for each category: -->


    <styles>


      <style type="text/css">
        p1 {
        fill: #ffff80;
        fill-opacity: 0.4;
        }
        p2 {
        fill: #fad155;
        fill-opacity: 0.4;
        }
        p3 {
        fill: #f2a82f;
        fill-opacity: 0.4;
        }
        p4 {
        fill: #b3520d;
        fill-opacity: 0.4;
        }
        p5 {
        fill: #6a0000;
        fill-opacity: 0.4;
        }
      </style>


      <selector class="p1">
        <query>
          <expr><![CDATA[ POP_CNTRY <= 14045470 ]]></expr>
        </query>
      </selector>


      <selector class="p2">
        <query>
          <expr><![CDATA[ POP_CNTRY > 14045470 and POP_CNTRY <= 43410900 ]]></expr>
        </query>
      </selector>


      <selector class="p3">
        <query>
          <expr><![CDATA[ POP_CNTRY > 43410900 and POP_CNTRY <= 97228750 ]]></expr>
        </query>
      </selector>


      <selector class="p4">
        <query>
          <expr><![CDATA[ POP_CNTRY > 97228750 and POP_CNTRY <= 258833000 ]]></expr>
        </query>
      </selector>


      <selector class="p5">
        <query>
          <expr><![CDATA[ POP_CNTRY > 258833000 ]]></expr>
        </query>
      </selector>


    </styles>


  </model>

</map>

其中CDATA

术语 CDATA 指的是不应由 XML 解析器进行解析的文本数据(Unparsed Character Data)。

在 XML 元素中,"<" 和 "&" 是非法的。

"<" 会产生错误,因为解析器会把该字符解释为新元素的开始。

"&" 也会产生错误,因为解析器会把该字符解释为字符实体的开始。

某些文本,比如 JavaScript 代码,包含大量 "<" 或 "&" 字符。为了避免错误,可以将脚本代码定义为 CDATA。

CDATA 部分中的所有内容都会被解析器忽略。

CDATA 部分由 "<![CDATA[" 开始,由 "]]>" 结束:

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

在上面的例子中,解析器会忽略 CDATA 部分中的所有内容。

关于 CDATA 部分的注释:

CDATA 部分不能包含字符串 "]]>"。也不允许嵌套的 CDATA 部分。

标记 CDATA 部分结尾的 "]]>" 不能包含空格或折行。