我已经想了好几个小时了。我试图从只使用str属性的XMl中获取数据。下面是XMl im试图使用的一个示例。
<doc>
<str name="author">timothy</str>
<str name="author_s">timothy</str>
<str name="title">French Gov't Runs Vast Electronic Spying Operation of Its Own</str>
<arr name="category">
<str>communications</str>
</arr>
<str name="slash-section">yro</str>
<str name="description">Dscription</str>
<str name="slash-comments">23</str>
<str name="link">http://rss.slashdot.org/~r/Slashdot/slashdot/~3/dMLqmWSFcHE/story01.htm</str>
<str name="slash-department">but-it's-only-wafer-thin-metadata</str>
<date name="date">2013-07-04T15:06:00Z</date>
<long name="_version_">1439733898774839296</long></doc>因此,我的问题是,我似乎无法用以下方法获取数据:
<?php
$x = simplexml_load_file('select.xml');
$xml = simplexml_load_string($x);
echo $xml->xpath("result/doc/str[@name='author']")[0];
?>服务器给我一个错误
有人能帮我吗?
发布于 2013-09-30 15:45:47
更改:
$xml->xpath("result/doc/str[@name='author']")[0]至:
$xml->xpath("result/doc/str[@name='author'][1]")第一次发生[0]是不正确的。在XPath中,首先出现的是[1]。同样与您的错误相关的是,[0]应该在XPath内部,而不是在最后。
https://stackoverflow.com/questions/19098065
复制相似问题