1
私はnamecheapから、次の消毒APIレスポンスを解析しようとしている:namecheap api xml returnを正しく解析するにはどうすればよいですか?
<ApiResponse xmlns="http://api.namecheap.com/xml.response" Status="OK">
<Errors/>
<Warnings/>
<RequestedCommand>namecheap.domains.getlist</RequestedCommand>
<CommandResponse Type="namecheap.domains.getList">
<DomainGetListResult>
<Domain ID="########" Name="website1.com" User="user1" Created="08/18/2014" Expires="08/18/2016" IsExpired="false" IsLocked="false" AutoRenew="false" WhoisGuard="NOTPRESENT"/>
<Domain ID="########" Name="website2.com" User="user1" Created="08/25/2015" Expires="08/24/2016" IsExpired="false" IsLocked="false" AutoRenew="false" WhoisGuard="NOTPRESENT"/>
</DomainGetListResult>
<Paging>
<TotalItems>2</TotalItems>
<CurrentPage>1</CurrentPage>
<PageSize>20</PageSize>
</Paging>
</CommandResponse>
<Server>Servername</Server>
<GMTTimeDifference>--4:00</GMTTimeDifference>
<ExecutionTime>0.034</ExecutionTime>
</ApiResponse>
これは私がこれまで持っている最も近いですが、それはまだそれではないです。
$url="https://api.namecheap.com/xml.response?ApiUser=user1&ApiKey=StackExchangeRocks&UserName=user1&Command=namecheap.domains.getList&ClientIp=127.0.0.1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url); // get the url contents
$data = curl_exec($ch); // execute curl request
curl_close($ch);
$xml = simplexml_load_string($data);
foreach ($xml->CommandResponse->DomainGetListResult->Domain as $domain) {
echo $domain->Name, PHP_EOL;
}
ほとんどの場合、オブジェクトが見つからないか、まったく応答がないというエラーが表示されます。
私がする必要があるのは、ドメイン名をデータベースに格納できるようにすることだけです。何か案は?
あなたはXML([ここ](http://www.w3schools.com/php/php_xml_simplexml_read.asp)のように扱わ何か)をロードするときにエラーエン得ますか? –
http://stackoverflow.com/questions/6576773/how-to-get-attribute-of-node-with-namespace-using-simplexml – Ghost
xmlはウェブブラウザを使用して問題なく表示され、ゴーストのヒントは関係ありません。 – cente