I need to append new tags to a XML file and I can achieve this by using this code:
$file = 'xml/config.xml';
$xml = simplexml_load_file($file);
$galleries = $xml->examples;
$gallery = $galleries->addChild('Example');
$gallery->addChild('ExampleID', '123');
$gallery->addChild('ExampleText', 'this is text');
$gallery->addChild('ExampleDate', '23/12/1234');
$xml->asXML($file);
My problem is the ID.
Basically I need to get the last ExampleID and increment it to the new Example tag.
How can I achieve this?
Edit
This is the XML structure:
<Examples>
<Example>
<ExampleID>1</ExampleID>
<ExampleText>this is text</ExampleText>
...
</Example>
<Example>
<ExampleID>2</ExampleID>
<ExampleText>this is the secont text</ExampleText>
...
</Example>
</Examples>