我正在查询apache solr并以下列格式获取XML响应
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">10</int>
</lst>
<result name="response" numFound="1015" start="0">
<doc>
<str name="city">zzzzzzz</str>
<str name="id">130</str>
<long name="inst_type">2</long>
<str name="area">yyyyyyyyy</str>
<str name="address">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</str>
<str name="name">Check</str>
<long name="_version_">1435275837198827521</long>
</doc>
<doc>
<str name="city">zzzzzzz</str>
<str name="id">130</str>
<long name="inst_type">2</long>
<str name="area">yyyyyyyyy</str>
<str name="address">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</str>
<str name="name">Check</str>
<long name="_version_">1435275837198827521</long>
</doc>
goes on..
</result>
</response>
如何在php中处理以下xml文件?我需要获取响应的id值
答案 0 :(得分:1)
<?php
$xml = simplexml_load_file("NewFile.xml");
foreach ($xml->children() as $second_gen) {
//echo $second_gen->getName()."=><br />";
foreach ($second_gen->children() as $third_gen) {
//echo $third_gen->getName()."=><br />";
foreach ($third_gen->children() as $fourth_gen) {
if($fourth_gen['name']=='id') {echo "ids=>";echo $fourth_gen;}
echo "<br />";
}
}
}
?>