I am reading in an xml file, processing though it and the saving it out to a daily actiivity file. The 2nd line & last line of the initial file looks like this:
<ReportDriver xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ReportDriver.xsd">
...
</ReportDriver>
However, after it's been though my script one time, the </ReportDriver> is not there and the 2nd line of the daily actitity xml file looks like this:
<ReportDriver xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ReportDriver.xsd"/>
Notice that that line is terminated with the /> at the end. I am just learning xml, so am really struggling with this. Of couse, when my script runs again, this time against the daily activity xml file, I get an error that the xml is not well formed.
The foreach loop follows:
function xmlParse ($xmlDriver, $dailyActivityDriver) {
global $debug;
global $runtime;
global $server;
global $pulse;
$message = "";
$ReportDOM = new DomDocument;
$ReportDOM->preserveWhiteSpace = FALSE;
$ReportDOM->load($xmlDriver, LIBXML_NOBLANKS);
$root = $ReportDOM->documentElement;
$xsd = $server."/ReportDriver/ReportDriver.xsd";
if (isset($ReportDOM) AND $ReportDOM != "") {
if ($ReportDOM->schemaValidate($xsd)) {
$template = new DOMDocument("1.0", "UTF-8");
$xpath = new DOMXPath($ReportDOM);
$fields = $xpath->query("//Report");
foreach ($fields as $field) {
$stamped = stampPulse($pulse);
if ($field->hasAttributes()) {
$statusX = $field->getAttribute("status");
} else {
$statusX = "idle";
}
if ($statusX != "success") {
$the_client = new theClient($field);
$domDailyActivity = $the_client->callIT();
if ($domDailyActivity->hasAttributes()) {
$status = $domDailyActivity->getAttribute("status");
$newStatus = $ReportDOM->appendChild($domDailyActivity);
$newStatus->setAttribute("status",$status);
}
$message .= "*** Wrote ". $ReportDOM->save($dailyActivityDriver)." bytes to $dailyActivityDriver\n";
} else { // status = "success"
continue;
} // end -- process Report
} // end -- foreach (fields as field)
} else {
$message .= "$xmlDriver xml document is NOT valid.";
}
} else {
$message .= "DOM is not set or is empty";
}
return $message;
}
Does anyone know why I'm getting this terminated line for the ReportDriver when I save it?