Odyssey
xml_processing.i
1 <?php
2 // Utility script to include xml processing related shared functions.
3 
4 /**
5  * Modify default libxml_get_errors, and add useful
6  * context to the error message before logging it to
7  * error console.
8  *
9  * @param $errors - libxml_get_errors output list
10  * @param $xmlstr - actual xml packet str
11 
12  * @return array (logging friendly list of errors,
13  * error or not flag)
14  */
15 function modifyXmlErrorsForLogging($errors, $xmlstr) {
16  $allLibXmlErrors = array();
17  $xml = explode("\n", $xmlstr);
18  $isError = False;
19 
20  foreach($errors as $error) {
21  $customError = array();
22 
23  $msg = trim($error->message);
24  // convert error level to actual words for log filtering
25  switch ($error->level) {
26  case LIBXML_ERR_WARNING:
27  $customError["level"] = "WARNING";
28  break;
29  case LIBXML_ERR_ERROR:
30  $isError = True;
31  $customError["level"] = "ERROR";
32  break;
33  case LIBXML_ERR_FATAL:
34  $isError = True;
35  $customError["level"] = "FATAL ERROR";
36  break;
37  }
38  $customError["code"] = $error->code;
39  $customError["line"] = $error->line;
40  $customError["column"] = $error->column;
41  // actual xml substring
42  $customError["message"] = implode(",", explode("\n", trim($error->message)));
43  $customError["context"] = $xml[$error->line - 1];
44 
45  $allLibXmlErrors[] = $customError;
46  }
47  return array($allLibXmlErrors, $isError);
48 }
49 ?>