I am trying to delete child from my jobs.xml file using a php script.
the way my jobs.xml looks like is :
<jobs>
<event jobid="1">
<title>jobtitle</title>
<desc>description</desc>
<date>postdate</date>
</event>
<event jobid="2">
<title>jobtitle</title>
<desc>description</desc>
<date>postdate</date>
</event>
<event jobid="3">
<title>jobtitle</title>
<desc>description</desc>
<date>postdate</date>
</event>
</jobs>
I have created a php script where I take jobid from the user and on submit and delete the event child who has that jobid.
but the problem is that when i create a new job i get a duplicate jobid as when I create new job event I use $jobid = $xmlobj->count() + 1;
Could some one help me in this. I prefer to use php script but java script will be fine too.
EDIT :
Here's my code to delete :
<?php
$jobs = simplexml_load_file('jobs.xml');
$jobid = $_POST['jobid'];
foreach ($jobs->children() as $event) {
if($event->attributes()->jobid == $jobid)
{
$dom=dom_import_simplexml($event);
$dom->parentNode->removeChild($dom);
}
}
$jobs->asXML('jobs.xml');
?>