mmm... Sto guardando quelle funzioni ma non mi funzionano neanche gli esempi...
codice:
<?PHP
$doc = new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput = true;
$root = $doc->createElement('book');
$root = $doc->appendChild($root);
$title = $doc->createElement('title');
$title = $root->appendChild($title);
$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);
echo "Saving all the document:\n";
echo $doc->saveXML() . "\n";
echo "Saving only the title part:\n";
echo $doc->saveXML($title);
?>
output:
codice:
Saving all the document: Saving only the title part:
[EDIT]: Ho controllato meglio... Il codice xml viene scritto nella pagina ma Firefox non lo visualizza... è normale?
In ogni caso.. come si tradurrebbe questo?
codice:
<?PHP
$xmlSource = simplexml_load_file('_items.xml');
$xmlDest = simplexml_load_file('empty.xml');
foreach($xmlSource->item as $oggetto){
$item = $xmlDest->AddChild($oggetto['id'],'');
$item->AddChild('nome',$oggetto->nome);
$item->AddChild('dannomin',$oggetto->danni->min);
$item->AddChild('dannomax',$oggetto->danni->max);
$item->AddChild('piedistallo',$oggetto->piedistallo);
$prezzo = $item->AddChild('prezzo',$oggetto->prezzo);
$prezzo->AddAttribute('moneta',$oggetto->prezzo['moneta']);
foreach($oggetto->mod as $m){
$item->AddChild($m['id'],$m);
}
foreach($oggetto->premessa as $m){
$item->AddChild($m['id'],$m);
}
$item->AddChild('img',$oggetto->img);
$xmlDest->asXML('risultato.xml');
}
?>