ich versuche folgender xml struktur mittels dom hinzubekommen.
PHP-Code:
<root>
<child attribute1="abc" attribute2="abcd" attribute3="abcde">
<child/>
<child attribute1="abc" attribute2="abcd" attribute3="abcde">
<child/>
</root>
habs so versucht
PHP-Code:
<?php
$attribute_1= $_POST ['txt_1'];
$attribute_2= $_POST ['txt_2'];
$attribute_3= $_POST ['txt_3'];
$myXML = "myXML.xml";
$myRoot = "root";
$mySub = "childs";
$mySubNodes = array("attribute1", "attribute2", "attribute3");
if(!file_exists($myXML)) {
$dom = new DOMDocument("1.0","UTF-8");
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$root = $dom->createElement($myRoot);
$root = $dom->appendChild($root);
}
if(!isset($dom)) {
$dom = new DOMDocument();
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$dom->load($myXML);
$root = $dom->documentElement ;
}
if(!isset($root->childNodes->item(0)->parentNode)){
$node = $dom->createElement($mySub);
$node->setAttribute($mySubNodes[0],$attribute_1);
$node->setAttribute($mySubNodes[1],$attribute_2);
$node->setAttribute($mySubNodes[2],$attribute_2);
$node = $root->appendChild($node);
}else{
$node = $dom->createElement($mySub);
$node->setAttribute($mySubNodes[0],$attribute_1);
$node->setAttribute($mySubNodes[1],$attribute_2);
$node->setAttribute($mySubNodes[2],$attribute_2);
$node = $root->appendChild($node);
$root->childNodes->item(0)->parentNode->insertBefore($node,$root->childNodes->item(0));
}
if($dom->save($myXML)){
echo "&Erstellt = OK";
}else{
echo "&Erstellt = ERROR";
}
?>
wie kann ich xml struktur wie ganz oben hinbekommen?
danke vorraus.