我有一个来自外部服务器的 xml,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<Response ResponseReference="200002">
<ResponseDetails Language="en">
<SearchCurrencyResponse>
<CurrencyDetails>
<Currency Code="ARS"><![CDATA[Argentine Peso]]></Currency>
<Currency Code="AUD"><![CDATA[Australian Dollar]]></Currency>
</CurrencyDetails>
</SearchCurrencyResponse>
</ResponseDetails>
</Response>
获取所有货币(里面的代码和文本)的正确方法是什么?
我已经尝试过这种方式并且可以工作,但是有没有办法让它更快?因为我可以拥有数千个元素:
$searchCurrencyReponseElements = $xpath->query( 'ResponseDetails/SearchCurrencyResponse', $responseElement );
foreach( $searchCurrencyReponseElements as $searchCurrencyReponseElement ) {
$CurrencyElements = $xpath->query( 'CurrencyDetails/Currency', $searchCurrencyReponseElement );
foreach( $CurrencyElements as $CurrencyElement ) {
echo '<p>Currency: '.$CurrencyElement->textContent.'</p>';
}
}
以及如何取代码属性?谢谢