diff options
author | Urban Müller | 2024-08-14 15:38:46 +0200 |
---|---|---|
committer | Urban Müller | 2024-08-14 15:39:23 +0200 |
commit | 9287218831d8cf6034e03eef899f5d8e36bb2e18 (patch) | |
tree | 8ce365f35716e86c58ab0c35ea18ee898e0c6ee1 | |
parent | 24331e26b7308f25ed9e75401c79152e58bd9557 (diff) | |
download | itools-9287218831d8cf6034e03eef899f5d8e36bb2e18.tar.gz itools-9287218831d8cf6034e03eef899f5d8e36bb2e18.tar.bz2 itools-9287218831d8cf6034e03eef899f5d8e36bb2e18.zip |
add simplexml_load_string() with better error reporting
-rw-r--r-- | it.class | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -1404,4 +1404,23 @@ static function utf8_encode($latin1) return UConverter::transcode($latin1, 'UTF8', 'ISO-8859-1'); } +/** + * Parse xml and put any offending input into error report + */ +static function simplexml_load_string($data, $class_name = null, $options = 0) +{ + $oldsetting = libxml_use_internal_errors(true); + + if (($result = simplexml_load_string($data, $class_name, $options)) === false) + { + $titles = it::map('trim($v->message) . " at line $v->line col $v->column"', libxml_get_errors()); + it::error('title' => $titles[0], ['body' => join("\n", $titles) . "\n\n$data"]); + libxml_clear_errors(); + } + + libxml_use_internal_errors($oldsetting); + + return $result; +} + } |