</div><p>这表明名为 "gif" 的notation与处理GIF图像的应用程序相关联。</p><p><strong>PUBLIC标识符</strong></p><p><code>PUBLIC</code> 关键字允许使用一个公共标识符,这通常是一个正式注册的名称。系统标识符作为备用,以防公共标识符不可用。例如:</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:xml;toolbar:false;'><!NOTATION svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"></pre>
</div><p>这里,公共标识符是SVG 1.1 DTD的正式名称,系统标识符是DTD的URI。</p><p><strong>使用案例</strong></p><p>假设有一个XML文档需要嵌入一个未解析的GIF图像。首先,声明一个notation:</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:xml;toolbar:false;'><!NOTATION gif SYSTEM "image/gif"></pre>
</div><p>然后,在文档中声明一个未解析的实体:</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:xml;toolbar:false;'><!ENTITY logo SYSTEM "images/logo.gif" NDATA gif></pre>
</div><p><code>NDATA gif</code> 告诉解析器,这个实体的数据类型由名为 "gif" 的notation处理。</p><p><strong>
</div><p>然后,声明一个未解析的实体:</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:xml;toolbar:false;'><!ENTITY report SYSTEM "reports/annual_report.pdf" NDATA pdf></pre>
</div><p>最后,在文档中使用这个实体:</p><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:xml;toolbar:false;'><document> <title>Annual Report</title> <content>&report;</content></document></pre>
</div><p>当XML解析器遇到 <code>&report;</code> 实体时,它会知道这个实体的数据类型是 "pdf",并且应该使用 <code>application/pdf</code> 相关的程序来处理它。</p><p>如何处理XML文档中的非法字符?</p><p>XML文档中的非法字符是指那些不符合XML规范的字符,例如某些控制字符和特殊符号。处理这些字符对于确保XML文档的有效性和可解析性至关重要。</p><p><strong>使用字符实体引用</strong></p> <div class="aritcle_card">
微信扫一扫
支付宝扫一扫