我又遇到了一个问题,目前XML对我不好。
为什么我收到此错误消息,我该如何解决?

我收到每个XML文件的错误消息!

错误信息:

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

代码:
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>

问候和谢谢!

最佳答案

loadXML期望使用string of XML,但是您正在尝试为其提供文件路径。尝试load。或者,您可以将XML文件加载到字符串中,然后调用loadXML。

关于php - DOMDocument::loadXML():起始标签应为: "<",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41452807/

10-12 19:47