Quindi, ho questo codice che cerca un nodo particolare nel mio file XML, disattiva un nodo esistente e inserisce un nuovo nodo figlio con i dati corretti. C'è un modo per ottenere questi nuovi dati per salvare all'interno del file XML effettivo con simpleXML? In caso contrario, esiste un altro metodo efficiente per farlo?Come salvare l'oggetto SimpleXML modificato su file?
public function hint_insert() {
foreach($this->hints as $key => $value) {
$filename = $this->get_qid_filename($key);
echo "$key - $filename - $value[0]<br>";
//insert hint within right node using simplexml
$xml = simplexml_load_file($filename);
foreach ($xml->PrintQuestion as $PrintQuestion) {
unset($xml->PrintQuestion->content->multichoice->feedback->hint->Passage);
$xml->PrintQuestion->content->multichoice->feedback->hint->addChild('Passage', $value[0]);
echo("<pre>" . print_r($PrintQuestion) . "</pre>");
return;
}
}
}
Così guardando il mio codice di cui sopra, questo salverà il mio oggetto $ XML aggiornato a qualsiasi $ nomefile è? – ThinkingInBits
Ho provato a cambiarlo in $ dom = new DOMDocument ('1.0'); \t \t \t $ dom-> preserveWhiteSpace = falso; \t \t \t $ dom-> formatOutput = true; \t \t \t $ dom-> loadXML ($ xml-> asXML()); \t \t \t $ dom-> save ($ nomefile); Ma ancora nessun aggiornamento nel file – ThinkingInBits
Ok, in realtà funziona ora con $ dom-> save ($ nomefile) ... Grazie! – ThinkingInBits