This is part of the XML I want to edit
<ScrapBook>
<Event>
<Name> Name of Event <Name>
<Other Elements>
</Event>
<ScrapBook>
I need to modify the Name of the Event.
I am able to delete the node using remove_child. But I dont know how to add another element at the same spot.
This is my code:
public function editEventName($oldEventName, $newEventName){
$xmlDoc = new DOMDocument();
$xmlDoc->load($this->xmlFileName);
$events = $xmlDoc->getElementsByTagName("Event");
foreach($events as $event){
$eventNames = $event->getElementsByTagName("Name");
$eventN = $eventNames->item(0)->nodeValue;
if($oldEventName == $eventN){
$nud = $eventNames->item(0)->parentNode;
$nud->removeChild($eventNames->item(0));
// set name to $newEventName
}
$xmlDoc->saveXML();
$xmlDoc->save($this->xmlFileName);
}