function openXML($file) { $doc = new DOMIT_Document(); if ($doc->loadXML(CONTENTDIR . $file)) { $xml =& $doc->documentElement; return $xml; } else { echo 'Could not open or read XML file: ' . $file . '<br />' . $doc->getErrorString(); return false; } }
function moreGranulesFromXML() { if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Harmoni"); $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified."); $priorityType = new Type("logging", "edu.middlebury", "Error", "Events involving critical system errors."); } $moreXML = $this->_import->documentElement->getElementsByTagName("repositoryfile"); $granules = 0; for ($i = 0; $i < $moreXML->getLength(); $i++) { $element = $moreXML->item($i); $path = $element->getText(); if (!preg_match("#^([a-zA-Z]+://|[a-zA-Z]+:\\|/)#", $path)) { $path = $element->ownerDocument->xmlPath . $path; } $import = new DOMIT_Document(); // attempt to load (parse) the xml file if ($import->loadXML($path)) { if (!$import->documentElement->hasChildNodes()) { $this->addError("There are no Importables in this file"); // log error $item = new AgentNodeEntryItem("XMLImporter Error", "No Importables in the file: " . htmlspecialchars($path) . "."); if (isset($log)) { $log->appendLogWithTypes($item, $formatType, $priorityType); } } else { $nodes = $import->documentElement->getElementsByTagName($this->_granule); $granules += $nodes->getLength(); } } else { // any errors encountered by DOMIT in parsing handled here $this->addError("DOMIT error: " . $import->getErrorCode() . "<br/>\t meaning: " . $import->getErrorString() . "<br/>"); $item = new AgentNodeEntryItem("XMLImporter DOMIT Error", "Error Code: " . $import->getErrorCode() . ", meaning: " . $import->getErrorString() . "."); if (isset($log)) { $log->appendLogWithTypes($item, $formatType, $priorityType); } } } return $granules; }