X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FXML.php;h=e06a92d25edf9a5a3d73951431064eaafb1f29c4;hb=72fc89d033070a72a01fd0b3f7a91d21d7467acb;hp=d8c5e032396df4f7626eab100f0700afff740836;hpb=f04d40a37eb36e903433478d671a9dcd5bb6aacb;p=friendica.git diff --git a/src/Util/XML.php b/src/Util/XML.php index d8c5e03239..e06a92d25e 100644 --- a/src/Util/XML.php +++ b/src/Util/XML.php @@ -52,6 +52,7 @@ class XML } } + $element = null; foreach ($array as $key => $value) { if (!isset($element) && isset($xml)) { $element = $xml; @@ -185,12 +186,13 @@ class XML return(null); } + $xml_element_copy = ''; if (!is_string($xml_element) && !is_array($xml_element) && (get_class($xml_element) == 'SimpleXMLElement') ) { - $xml_element_copy = $xml_element; - $xml_element = get_object_vars($xml_element); + $xml_element_copy = $xml_element; + $xml_element = get_object_vars($xml_element); } if (is_array($xml_element)) { @@ -429,4 +431,34 @@ class XML } 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; + } }