ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
inc.xml5compliance.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | Copyright (c) by Alexandre Alapetite, |
5  | http://alexandre.alapetite.net/cv/alexandre-alapetite.en.html |
6  | http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/ |
7  | Modifications by Alex Killing, alex.killing@gmx.de (search for ##) |
8  |-----------------------------------------------------------------------------|
9  | Allows PHP4/DOMXML scripts to run on PHP5/DOM |
10  | |
11  | Typical use: |
12  | { |
13  | if (version_compare(PHP_VERSION,'5','>=')) |
14  | require_once('domxml-php4-to-php5.php'); |
15  | } |
16  |-----------------------------------------------------------------------------|
17  | This code is published under Creative Commons |
18  | Attribution-ShareAlike 2.0 "BY-SA" licence. |
19  | See http://creativecommons.org/licenses/by-sa/2.0/ for details. |
20  +-----------------------------------------------------------------------------+
21 */
22 
23 function staticxmlerror(int $errno, string $errstr, ?string $errfile = null, ?int $errline = null, ?array $errcontext = null, bool $ret = false)
24 {
25  static $errs = array();
26 
27  $tag = 'DOMDocument::validate(): ';
28  $errs[] = str_replace($tag, '', $errstr);
29 
30  if ($ret === true) {
31  return $errs;
32  }
33 }
34 
35 define('DOMXML_LOAD_PARSING', 0);
36 
37 /*
38 * ##added
39 */
40 function domxml_open_mem($str, $mode = 0, &$error = null)
41 {
42  if (!is_int($mode)) {
43  $mode = 0;
44  }
45  $doc = new php4DOMDocument($str, false, $mode);
46  if (!$doc->success) {
47  $error = $doc->error;
48  }
49 
50  return $doc;
51 }
52 
54 {
55  public $success = null;
56  public string $error = "";
58 
59  // ##altered
60  public function __construct($source, $file = true, $a_mode = 0)
61  {
62  $this->myDOMDocument = new DOMDocument();
63  // temporary set error handler
64  set_error_handler('staticxmlerror');
65  $old = ini_set('html_errors', false);
66 
67  if (is_object($source)) {
68  $this->myDOMDocument = $source;
69  $this->success = true;
70  } else {
71  if ($file) {
72  $this->success = @$this->myDOMDocument->load($source, $a_mode);
73  } else {
74  $this->success = $this->myDOMDocument->loadXML($source, $a_mode);
75  }
76  }
77 
78  // Restore error handling
79  ini_set('html_errors', $old);
80  restore_error_handler();
81 
82  if (!$this->success) {
83  $this->error_arr = staticxmlerror(0, "", "", 0, null, true);
84  foreach ($this->error_arr as $error) {
85  $error = str_replace("DOMDocument::loadXML():", "", $error);
86  $this->error .= $error . "<br />";
87  }
88  }
89  }
90 }
DOMDocument $myDOMDocument
domxml_open_mem($str, $mode=0, &$error=null)
staticxmlerror(int $errno, string $errstr, ?string $errfile=null, ?int $errline=null, ?array $errcontext=null, bool $ret=false)
__construct($source, $file=true, $a_mode=0)