]> git.mjollnir.org Git - moodle.git/commitdiff
More error info about XML parse failures
authordonal72 <donal72>
Fri, 2 Nov 2007 00:11:23 +0000 (00:11 +0000)
committerdonal72 <donal72>
Fri, 2 Nov 2007 00:11:23 +0000 (00:11 +0000)
mnet/xmlrpc/xmlparser.php

index 0c9b9b5ed02279326609d71631f4cb03e256a2ae..1d74381d25546a5d74ab1e343395a65770193a46 100644 (file)
@@ -94,7 +94,23 @@ class mnet_encxml_parser {
             // Parse failed
             $errcode = xml_get_error_code($this->parser);
             $errstring = xml_error_string($errcode);
-            $this->error[] = array('code' => $errcode, 'string' => $errstring);
+            $lineno = xml_get_current_line_number($this->parser);
+            if ($lineno !== false) {
+                $error = array('lineno' => $lineno);
+                $lineno--; // Line numbering starts at 1.
+                while ($lineno > 0) {
+                    $data = strstr($data, "\n");
+                    $lineno--;
+                }
+                $data .= "\n"; // In case there's only one line (no newline)
+                $line = substr($data, 0, strpos($data, "\n"));
+                $error['code']   = $errcode;
+                $error['string'] = $errstring;
+                $error['line']   = $line;
+                $this->error[] = $error;
+            } else {
+                $this->error[] = array('code' => $errcode, 'string' => $errstring);
+            }
         }
 
         if (count($this->cipher) > 0) {