ciao ragazzi, stò cercando di creare un file xml e spedirlo via curl, cosa che dovrebbe essere relativamente semplice.. se non fosse che non ho mai utilizzato ne curl, ne il DOM.
cioè, mi basterebbe modificare un esempio già scritto che trovate qui:
esempio
quell'esempio, se ho capito bene, alla fine crea e spedisce questo risultato xml:
Codice PHP:
<?xml version="1.0" encoding="UTF-8" ?>
<packet version="1.4.1.2">
<domain>
<get>
<filter/>
<dataset>
<limits/>
<prefs/>
<user/>
<hosting/>
<stat/>
<gen_info/>
</dataset>
</get>
</domain>
</packet>
mentre quello che dovrei spedire io, dovrebbe essere fatto così:
Codice PHP:
<packet version="1.4.2.0">
<database>
<add-db>
<domain-id>7</domain-id>
<name>mio_database_di_prova_visibile_da_plesk</name>
<type>mysql</type>
</add-db>
</database>
</packet>
ho provato a modificare l'esempio ma non funziona:
Codice PHP:
function domainsInfoRequest($domainId, $dbName){
$xmldoc = new DomDocument('1.0', 'UTF-8');
$xmldoc->formatOutput = true;
// <packet>
$packet = $xmldoc->createElement('packet');
$packet->setAttribute('version', '1.4.1.0');
$xmldoc->appendChild($packet);
// <packet/database>
$database = $xmldoc->createElement('database');
$packet->appendChild($database);
// <packet/domain/add>
$add = $xmldoc->createElement('add-db');
$database->appendChild($add);
// <packet/domain/add/domain_id>
$domain_id = $xmldoc->createElement('domain-id');
//$domain_id->setValue($domainId);
$add->appendChild($domain_id);
$database_name = $xmldoc->createElement('name');
//$database_name->setValue($dbName);
$add->appendChild($database_name);
$type = $xmldoc->createElement('type');
//$type->setValue('mysql');
$add->appendChild($type);
return $xmldoc;
}
se tolgo i commenti dalle righe con il ->setValue() mi restituisce pagina bianca (non è quella la sintassi?)
altrimenti:
Livello errore: 8, Trying to get property of non-object, hex.php, riga 99
Livello errore: 8, Trying to get property of non-object, hex.php, riga 102
e in quelle righe c'è questa funzione:
Codice PHP:
function checkResponse(SimpleXMLElement $response){
$resultNode = $response->domain->get->result;//riga 99
// check if request was successful
if ('error' == (string)$resultNode->status){//riga 102
throw new ApiRequestException("Plesk API returned error: " . (string)$resultNode->result->errtext);
}
}
un aiutino?
come faccio a creare il file xml che mi serve, e a popolarlo?