function saveXMLFormatted( $xml, $filename ) {
// @param SimpleXMLElement $xml SimpleXML object
// @param string $filename name of file to write output to
$doc = new DOMDocument('1.0');
$doc->preserveWhiteSpace = false;
$doc->loadXML( $xml->asXML());
$doc->formatOutput = true;
file_put_contents( $filename, $doc->saveXML());
}
if (file_exists($rootRiegerweb.'/akte/china/galleries.xml')) {
$xml = simplexml_load_file($rootRiegerweb.'/akte/china/galleries.xml');
// erzeuge neue gallery
$gal = $xml->addChild('gallery');
$gal->addAttribute('base', '../china/');
$gal->addAttribute('file', 'test123.xml');
$site = $gal->addChild('sitename', 'London');
$graf = $gal->addChild('photographer', 'Karl');
$contact = $gal->addChild('contactinfo', 'http://www.stangerweb.de');
$email = $gal->addChild('email', 'kstanger@stangerweb.de');
$secur = $gal->addChild('security', ' ');
// schreibe galleries
saveXMLFormatted($xml, $rootRiegerweb.'/akte/china/galleries2.xml');
} else {
exit('Konnte '.$rootRiegerweb.'/akte/china/galleries.xml nicht oeffnen.');
}