Be aware that SimpleXML is a very simple implementation of a XML API in PHP.
So, there's no SimpleXML function that directly achieves what you want. But: You can use a different approach of building your XML structure:
<?php
$newXml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><News></News>');
$entry = $newXml->addChild('NewsModel');
$entry->addChild('ID', $_POST['inputIDNumber']);
$entry->addChild('Headline', $_POST['inputHeadline']);
$entry->addChild('ShortDescription', $_POST['inputShorDesc']);
$entry->addChild('Description', $_POST['inputDesc']);
$entry->addChild('LinkText', $_POST['inputLinkText']);
$entry->addChild('Link', $_POST['inputLink']);
$xml = simplexml_load_file($xmlurl) or die("Kann keine Verbindung zu $xmlurl aufbauen");
foreach ($xml as $child) {
$entry = $newXml->addChild('NewsModel');
$entry->addChild('ID', $child->ID);
$entry->addChild('Headline', $child->Headline);
$entry->addChild('ShortDescription', $child->ShortDescription);
$entry->addChild('Description', $child->Description);
$entry->addChild('LinkText', $child->LinkText);
$entry->addChild('Link', $child->Link);
}
file_put_contents($xmlurl, $newXml->asXML(), 0, stream_context_create(['ftp' => ['overwrite' => true]]));
You start by creating a new XML structure and adding the new NewsModel entry to it. After that you import the existing NewsModels.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…