getName() != ''; } /** * @param SimpleXMLElement $xml * @param string $attributeName * @return string|NULL */ public static function getAttributeValue($xml, $attributeName) { return (isset($xml->attributes()->$attributeName)) ? (string) $xml->attributes()->$attributeName : NULL; } /** * @param SimpleXMLElement $xml * @return string */ public static function getTextContent($xml) { // HACK: Some versions of PHP 5 can't access the [0] element // of a SimpleXMLElement object properly. return (string) $xml; } /** * @param SimpleXMLElement $xml * @param string $xpathExpr * @return string|NULL */ public static function getTextContentAtXpath($xml, $xpathExpr) { $matchingElements = $xml->xpath($xpathExpr); return (count($matchingElements) == 0) ? NULL : Splunk_XmlUtil::getTextContent($matchingElements[0]); } /** * Returns true if the specified SimpleXMLElement represents a unique * element or false if it represents a collection of elements. * * @param SimpleXMLElement $xml * @return bool */ public static function isSingleElement($xml) { $count = 0; foreach ($xml as $item) { $count++; if ($count >= 2) return false; } return ($count == 1); } }