PHP错误:DOMDocument :: loadXML()[domdocument.loadxml]:起始标签应为'<'在实体中找不到 [英] PHP Error: DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity

查看:58
本文介绍了PHP错误:DOMDocument :: loadXML()[domdocument.loadxml]:起始标签应为'<'在实体中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查此波纹管程序。

Please check this bellow program.

:: Program ::

::Program::

      <?php
      $xml='
      &lt;books&gt;
           &lt;book&gt;
                &lt;name&gt;Java complete reference&lt;/name&gt;
                &lt;cost&gt;256&lt;/cost&gt;
           &lt;/book&gt;

           &lt;book&gt;
                &lt;name&gt;Head First PHP and Mysql&lt;/name&gt;
                &lt;cost&gt;389&lt;/cost&gt;
           &lt;/book&gt;
      &lt;/books&gt;';


      $dom=new DOMDocument();
      $dom->loadXML($xml);
      foreach ($dom->getElementsByTagName('book') as $book)
      {
              foreach($book->getElementsByTagName('name') as $name)
              {
                   $names[]=$name->nodeValue;
              }

              foreach($book->getElementsByTagName('cost') as $cost)
              {
                   $costs[]=$cost->nodeValue;
              }
      }
      print_r($names);
      ?>

显示错误:


DOMDocument :: loadXML()[domdocument.loadxml]:应为开始标签,在实体中找不到'<<'

DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity

这是正确的方法吗?

如果正确,是否有任何方法可以在不更改此&的情况下获得正确的结果; lt; < & gt; >

If it is correct, Is there any way to get the proper result without changing this &lt; to < and &gt; to >?

推荐答案

您不应该将字符实体用于 < > 实际上是表示XML的字符串中的XML标签。应当是这样:

You should not be using character entities for < and > on things that are actually XML tags in the string that represents your XML. It should be this:

$xml='
  <books>
       <book>
...

这样做,警告就消失了。

Do that and the warning goes away.

您只需在< > 中使用字符实体是实际数据的一部分,而不是分隔XML标签。

You only need to use character entities for < and > when they are part of the actual data rather than delimiting an XML tag.

这篇关于PHP错误:DOMDocument :: loadXML()[domdocument.loadxml]:起始标签应为'&lt;'在实体中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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