How can i update parent with child node when updating the stop time again. how can i update the stop time using php with XML. In the code i gave below, the start time is getting removed when the stop time is updated.
$stoppingTime = date("H:i A");
$cur_date = date("d-m-Y");
$dom = new DOMDocument("1.0");
header("Content-Type: text/plain");
// Root Element
$root = $dom->createElement("server");
$dom->appendC开发者_运维技巧hild($root);
$id = $dom->createAttribute("id");
$root->appendChild($id);
$att = $dom->createTextNode("1");
$id->appendChild($att);
//Child Element
$date = $dom->createElement("date");
$root->appendChild($date);
$curDate = $dom->createTextNode($cur_date);
$date->appendChild($curDate);
$start = $dom->createElement("start_time");
$root->appendChild($start);
$startTime = $dom->createTextNode($startingTime);
$start->appendChild($startTime);
$stop = $dom->createElement("stop_time");
$root->appendChild($stop);
$stopTime = $dom->createTextNode($stoppingTime);
$stop->appendChild($stopTime);
Maybe I'm completely wrong, but your XML forming code looks OK. The reason why you don't have start_time
in the document is that you don't have $startingTime
variable in your script. Adding the
$startingTime = date("d-m-Y");
Solves the problem, so make sure you initialize that variable before using it.
精彩评论