【发布时间】:2016-07-06 16:18:01
【问题描述】:
我正在尝试将我的 XML 解析为 MYSQL 数据库。但我得到一个错误:
警告:SimpleXMLElement::__construct():实体:第 68 行:解析器错误:开始和结束标记不匹配:命中第 3 行和第 72 行 ******* 中的事件
我想我拼错了一些东西,但我似乎找不到它。这是我第一次使用 XML。
这是我的代码:
$xml = new SimpleXMLElement($xmlstr);
echo 'single value: <br />';
echo $xml->events->hits->hits->hits->hits[0]->_id; // get single value
这里是 $xmlstr:
$xmlstr = <<<XML
<events>
<hits>200</hits>
<hits>
<_shards>
<failed>0</failed>
<successful>5</successful>
<total>5</total>
</_shards>
<hits>
<hits>
<hits>
<_id>2307</_id>
<_index>events</_index>
<_score null="true" />
<_type>event</_type>
<fields>
<description>
<hits>Bla</hits>
</description>
<genres>
<hits>
<hits>Classic</hits>
<hits>Rock</hits>
<hits>Pop</hits>
</hits>
</genres>
<header>
<hits>https://media.hugo.events/events/2307/56820e2ac5fa1eecf115fc8aaf250e9c.jpg</hits>
</header>
<logo>
<hits>https://media.hugo.events/events/2307/240e3f379e5996ac4c5e20b9c874cc6f.png</hits>
</logo>
<name>
<hits>Cultureel Festival Baarn 2016</hits>
</name>
<start>
<hits>2016-09-02T12:00:00+0000</hits>
</start>
<venue.city>
<hits>Baarn</hits>
</venue.city>
<venue.country>
<hits>Nederland</hits>
</venue.country>
<venue.location>
<hits>5.2906804</hits>
<hits>52.210896</hits>
</venue.location>
</fields>
<sort>
<hits>1472817600000</hits>
</sort>
</hits>
</hits>
</hits>
</events>
XML;
我在指向要解析的部分时做错了吗?
我希望有人可以帮助我。
提前致谢。
【问题讨论】:
-
如错误消息所述,您的 XML 无效。 (你开始 4 个
<hits>标签,只关闭 3 个。)