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

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条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失