How can I parse an XML response into variable and store in to table?
XML response is fetched with the following script:
<?php
require_once 'db.php';
define( 'HOST', 'https://gateway.autodns.com');
define( 'XML_FILE', 'test.xml' );
$xml = implode( "", file(XML_FILE) );
header( 'Content-Type: text/xml' );
echo requestCurl( $xml );
function requestCurl( $data )
{
$ch = curl_init( HOST );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
if( !$data = curl_exec( $ch )) {
echo 'Curl execution error.', curl_error( $ch ) ."\n"; return FALSE;
}
curl_close( $ch );
return $data;
}
$api_insert = $mysqli->query("INSERT INTO api name, created, payable VALUES ('', '', '')");
?>
echo requestCurl( $xml ); prints XML content shown below. I need to take <name>, <payable> and <created> element values for each domain and store them into a table.
XML
<response>
<result>
<data>
<summary>2</summary>
<domain>
<name>facebook.bayern</name>
<payable>2017-05-06 13:34:46</payable>
<domainsafe>false</domainsafe>
<dnssec>false</dnssec>
<owner>
<user>dhabi</user>
<context>4</context>
</owner>
<created>2015-05-06 13:34:46</created>
<updated>2016-12-20 11:29:10</updated>
</domain>
<domain>
<name>google.com</name>
<payable>2017-04-08 22:04:04</payable>
<domainsafe>false</domainsafe>
<dnssec>false</dnssec>
<owner>
<user>dhabi</user>
<context>4</context>
</owner>
<created>2016-04-08 22:04:05</created>
<updated>2016-12-20 17:44:39</updated>
</domain>
</data>
<status>
<code>S0105</code>
<text>Domaindaten wurden erfolgreich ermittelt.</text>
<type>success</type>
</status>
</result>
<stid>20161221-app4-40522</stid>
</response>