doushuzd3033 2017-01-03 21:38
浏览 137
已采纳

DOMDocument :: loadXML():期望开始标记:“<”

I have again a problem and at the moment XML isn't nice to me... Why I'm getting this error message and how can I solve it?

I get the error message by every XML file!

Error Message:

PHP Warning:  DOMDocument::loadXML(): Start tag expected, '<' not found in Entity, line: 1 in C:\Users\Jan\PhpstormProjects\censored\Matcher.php on line 36
Warning: DOMDocument::loadXML(): Start tag expected, '<' not found in Entity, line: 1 in C:\Users\Jan\PhpstormProjects\censored\Matcher.php on line 36

Code:

function loadTitlesIntoArray($tagName, $path){

$dom = new DOMDocument('1.0', 'utf-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($path);

$titels = array();
$marker = $dom->getElementsByTagName($tagName);

for ($i = $marker->length - 1; $i >= 0; $i--) {
    $new = $marker->item($i)->textContent;
    array_push($titels, $new);
}

print_r($titels);
}

loadTitlesIntoArray('title', $kinguinPath);

XML:

<?xml version="1.0" encoding="UTF-8"?>
<rss>
  <channel xmlns:g="http://base.google.com/ns/1.0" version="2.0">
    <title><![CDATA[google_EUR_english_1]]></title>
    <link><![CDATA[http://cdn.kinguin.net/media/feedexport/google_EUR_english_1.xml]]></link>
    <item>
      <title><![CDATA[Anno 2070 Uplay CD Key]]></title>
      <link><![CDATA[http://www.kinguin.net/category/4/anno-2070/?nosalesbooster=1&country_store=1&currency=EUR]]></link>
      <g:price><![CDATA[3.27 EUR]]></g:price>
      <g:image_link><![CDATA[http://cdn.kinguin.net/media/catalog/category/anno_8.jpg]]></g:image_link>
    </item>
    <item>
      <title><![CDATA[Anno 2070: Deep Ocean DLC Uplay CD Key]]></title>
      <link><![CDATA[http://www.kinguin.net/category/5/anno-2070-deep-ocean-expansion-pack-dlc/?nosalesbooster=1&country_store=1&currency=EUR]]></link>
      <g:price><![CDATA[4.74 EUR]]></g:price>
      <g:image_link><![CDATA[http://cdn.kinguin.net/media/catalog/category/anno-2070-deep-ocean-releasing-this-spring-1089268_1.jpg]]></g:image_link>
    </item>
  </channel>
</rss>

Greetings and Thank You!

  • 写回答

2条回答 默认 最新

  • dsjzmrz78089 2017-01-03 21:49
    关注

    loadXML is expecting a string of XML but you are trying to give it a file path. Try load. Or, you can load the XML file into a string and then call loadXML.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改