+
+ public static function parseString($s, $strict = true)
+ {
+ // the "strict" parameter is deactivated
+ libxml_use_internal_errors(true);
+
+ $x = @simplexml_load_string($s);
+ if (!$x) {
+ logger('libxml: parse: error: ' . $s, LOGGER_DATA);
+ foreach (libxml_get_errors() as $err) {
+ logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA);
+ }
+ libxml_clear_errors();
+ }
+ return $x;
+ }
+
+ public static function getFirstNodeValue($xpath, $element, $context = null)
+ {
+ $result = $xpath->evaluate($element, $context);
+ if (!is_object($result)) {
+ return '';
+ }
+
+ $first_item = $result->item(0);
+ if (!is_object($first_item)) {
+ return '';
+ }
+
+ return $first_item->nodeValue;
+ }
+
+ public static function getFirstAttributes($xpath, $element, $context = null)
+ {
+ $result = $xpath->query($element, $context);
+ if (!is_object($result)) {
+ return false;
+ }
+
+ $first_item = $result->item(0);
+ if (!is_object($first_item)) {
+ return false;
+ }
+
+ return $first_item->attributes;
+ }