我一直试图弄清楚几个小时。我试图从只使用str属性的XMl中获取数据。这里是一个示例XMl即时通讯尝试使用。尝试从仅使用str的XML获取PHP数据
<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];
?>
服务器给了我一个错误
谁能帮助我?
你会得到哪个错误?也许你需要这样做xpath:'$ xml-> xpath(“/ result/doc/str [@ name ='author']”)[1]' –
这是以下错误:解析错误:语法错误,意想不到的'[',期待','或';' 我已经尝试了一切。似乎没有任何帮助。我错过了什么? – user2831723