+ /**
+ * Gets first node's value
+ *
+ * @param DOMXPath $xpath XPath object
+ * @param string $element Element name
+ * @param DOMNode $context Context object or NULL
+ * @return string First value or empty string on failure
+ */
+ public static function getFirstValue(DOMXPath $xpath, string $element, DOMNode $context = null): string
+ {
+ $result = @$xpath->query($element, $context);
+ if (!is_object($result)) {
+ return '';
+ }
+
+ $first_item = $result->item(0);
+ if (!is_object($first_item)) {
+ return '';
+ }
+
+ return $first_item->nodeValue;
+ }
+