我有这个XML:
<response>
<method>keyword.domain.seo</method>
<answer>
<result kw="moos entfernen" position="74" competition="39" traffic="30" url="https://www.gartenbau.org/moos-entfernen-201816621"/>
<result kw="moosentfernung" position="93" competition="52" traffic="20" url="https://www.gartenbau.org/moos-entfernen-201816621"/>
</answer>
<date>2018-08-27T15:13:04+02:00</date>
<credits used="2"/>
</response>
我想解析两个标签<result>
中的属性。我使用了这段代码,但是它只获取“ first”标记<result>
中的属性。
$xml=simplexml_load_string($content) or die("Error: Cannot create object");
foreach($xml->answer->result as $result){
foreach($result->attributes() as $a => $b) {
echo $a,'="',$b,"\"\n";
}
}