<bdo id='yNcct'></bdo><ul id='yNcct'></ul>
<tfoot id='yNcct'></tfoot>

<small id='yNcct'></small><noframes id='yNcct'>

    <i id='yNcct'><tr id='yNcct'><dt id='yNcct'><q id='yNcct'><span id='yNcct'><b id='yNcct'><form id='yNcct'><ins id='yNcct'></ins><ul id='yNcct'></ul><sub id='yNcct'></sub></form><legend id='yNcct'></legend><bdo id='yNcct'><pre id='yNcct'><center id='yNcct'></center></pre></bdo></b><th id='yNcct'></th></span></q></dt></tr></i><div id='yNcct'><tfoot id='yNcct'></tfoot><dl id='yNcct'><fieldset id='yNcct'></fieldset></dl></div>
    1. <legend id='yNcct'><style id='yNcct'><dir id='yNcct'><q id='yNcct'></q></dir></style></legend>

        LIBXML_NOENT 做什么(为什么不叫 LIBXML_ENT)?

        时间:2023-12-01
        • <tfoot id='5hjnl'></tfoot>
          1. <small id='5hjnl'></small><noframes id='5hjnl'>

              <bdo id='5hjnl'></bdo><ul id='5hjnl'></ul>
            • <i id='5hjnl'><tr id='5hjnl'><dt id='5hjnl'><q id='5hjnl'><span id='5hjnl'><b id='5hjnl'><form id='5hjnl'><ins id='5hjnl'></ins><ul id='5hjnl'></ul><sub id='5hjnl'></sub></form><legend id='5hjnl'></legend><bdo id='5hjnl'><pre id='5hjnl'><center id='5hjnl'></center></pre></bdo></b><th id='5hjnl'></th></span></q></dt></tr></i><div id='5hjnl'><tfoot id='5hjnl'></tfoot><dl id='5hjnl'><fieldset id='5hjnl'></fieldset></dl></div>

                <legend id='5hjnl'><style id='5hjnl'><dir id='5hjnl'><q id='5hjnl'></q></dir></style></legend>
                    <tbody id='5hjnl'></tbody>

                  本文介绍了LIBXML_NOENT 做什么(为什么不叫 LIBXML_ENT)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 PHP 中,可以将可选参数传递给各种 XML 解析器,其中之一是 LIBXML_NOENT.documentation 有这样的说法:

                  In PHP, one can pass optional arguments to various XML parsers, one of them being LIBXML_NOENT. The documentation has this to say about it:

                  LIBXML_NOENT(整数)
                  替代实体

                  LIBXML_NOENT (integer)
                  Substitute entities

                  替代实体 信息量不是很大(什么实体?它们什么时候被替代?).但我认为假设 NOENTNO_ENTITIESNO_EXTERNAL_ENTITIES 的缩写是公平的,所以对我来说,这个标志似乎是一个公平的假设禁用(外部)实体的解析.

                  Substitute entities isn't very informative (what entities? when are they substituted?). But I think it's fair to assume that NOENT is short for NO_ENTITIES or NO_EXTERNAL_ENTITIES, so to me it seems to be a fair assumption that this flag disables the parsing of (external) entities.

                  但确实不是这样的:

                  $xml = '<!DOCTYPE root [<!ENTITY c PUBLIC "bar" "/etc/passwd">]>
                  <test>&c;</test>';
                  $dom = new DOMDocument();
                  $dom->loadXML($xml, LIBXML_NOENT);
                  echo $dom->textContent;
                  

                  结果是回显了/etc/passwd 的内容.如果没有 LIBXML_NOENT 参数,情况并非如此.

                  The result is that the content of /etc/passwd is echoed. Without the LIBXML_NOENT argument this is not the case.

                  对于非外部实体,该标志似乎没有任何作用.示例:

                  For non-external entities, the flag doesn't seem to have any effect. Example:

                  $xml = '<!DOCTYPE root [<!ENTITY c "TEST">]>
                  <test>&c;</test>';
                  $dom = new DOMDocument();
                  $dom->loadXML($xml);
                  echo $dom->textContent;
                  

                  这段代码的结果是TEST",有没有LIBXML_NOENT.

                  The result of this code is "TEST", with and without LIBXML_NOENT.

                  该标志似乎对 &lt; 等预定义实体没有任何影响.

                  The flag doesn't seem to have any effect on pre-defined entities such as &lt;.

                  所以我的问题是:

                  • LIBXML_NOENT 标志到底有什么作用?
                  • 为什么叫LIBXML_NOENT?它的缩写是什么,LIBXML_ENTLIBXML_PARSE_EXTERNAL_ENTITIES 不是更合适吗?
                  • 是否存在实际上阻止解析所有实体的标志?
                  • What exactly does the LIBXML_NOENT flag do?
                  • Why is it called LIBXML_NOENT? What is it short for, and wouldn't LIBXML_ENT or LIBXML_PARSE_EXTERNAL_ENTITIES be a better fit?
                  • Is there a flag that actually prevents the parsing of all entities?

                  推荐答案

                  问:LIBXML_NOENT 标志具体有什么作用?

                  该标志允许替换 XML 字符实体引用,无论是否外部.

                  The flag enables the substitution of XML character entity references, external or not.

                  问:为什么叫LIBXML_NOENT?它的缩写是什么,LIBXML_ENT 或 LIBXML_PARSE_EXTERNAL_ENTITIES 不是更合适吗?

                  这个名字确实具有误导性.我认为 NOENT 只是意味着解析文档的节点树不会包含任何实体节点,因此解析器将替换实体.如果没有 NOENT,解析器会为实体创建 DOMEntityReference 节点参考文献.

                  The name is indeed misleading. I think that NOENT simply means that the node tree of the parsed document won't contain any entity nodes, so the parser will substitute entities. Without NOENT, the parser creates DOMEntityReference nodes for entity references.

                  问:是否存在实际上阻止解析所有实体的标志?

                  LIBXML_NOENT 启用所有实体引用的替换.如果您不想扩展实体,只需省略该标志即可.例如

                  LIBXML_NOENT enables the substitution of all entity references. If you don't want entities to be expanded, simply omit the flag. For example

                  $xml = '<!DOCTYPE test [<!ENTITY c "TEST">]>
                  <test>&c;</test>';
                  $dom = new DOMDocument();
                  $dom->loadXML($xml);
                  echo $dom->saveXML();
                  

                  打印

                  <?xml version="1.0"?>
                  <!DOCTYPE test [
                  <!ENTITY c "TEST">
                  ]>
                  <test>&c;</test>
                  

                  似乎 textContent 会自行替换实体,这可能是 PHP 绑定的一个特性.如果没有 LIBXML_NOENT,它会导致内部和外部实体的行为不同,因为后者不会被加载.

                  It seems that textContent replaces entities on its own which might be a peculiarity of the PHP bindings. Without LIBXML_NOENT, it leads to different behavior for internal and external entities because the latter won't be loaded.

                  这篇关于LIBXML_NOENT 做什么(为什么不叫 LIBXML_ENT)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么使用 XML 解析器? 下一篇:AjaxFileUpload 插件不检索 $_POST 或 $_FILES 数据

                  相关文章

                  <legend id='0kCIe'><style id='0kCIe'><dir id='0kCIe'><q id='0kCIe'></q></dir></style></legend>

                        <bdo id='0kCIe'></bdo><ul id='0kCIe'></ul>
                    1. <i id='0kCIe'><tr id='0kCIe'><dt id='0kCIe'><q id='0kCIe'><span id='0kCIe'><b id='0kCIe'><form id='0kCIe'><ins id='0kCIe'></ins><ul id='0kCIe'></ul><sub id='0kCIe'></sub></form><legend id='0kCIe'></legend><bdo id='0kCIe'><pre id='0kCIe'><center id='0kCIe'></center></pre></bdo></b><th id='0kCIe'></th></span></q></dt></tr></i><div id='0kCIe'><tfoot id='0kCIe'></tfoot><dl id='0kCIe'><fieldset id='0kCIe'></fieldset></dl></div>

                      <small id='0kCIe'></small><noframes id='0kCIe'>

                    2. <tfoot id='0kCIe'></tfoot>