@param \SimpleXMLElement $xml
@param integer $recursiveDepth
@param boolean $format

@return null|array<string,array>
334127
public function xml2array(\SimpleXMLElement $xml, $recursiveDepth = 0, $format = TRUE) {
        $recursiveDepth++;
        $result = [];

        // Extraction of the node
        $key   = trim($xml->getName());
        $value = trim((string) $xml);

        // Specific Attribute: do nothing when it is not the good language
        if ($xml->attributes()->lang) {
            if ($xml->attributes()->lang <> $this->language) {
                return NULL;
            }
            unset($xml->attributes()->lang);
        }

        // Specific Attributes changing the xml
        $key    = $this->setSpecificAttributeKeyWithGivenId($xml, $key);
        $value  = $this->setSpecificAttributeAge($xml, $recursiveDepth, $value);
        $result = $this->retrieveSpecificAttributeCrossRef($xml, $recursiveDepth, $result, $key);
        // Standard Attributes
        $result = $this->setStandardAttributes($xml, $result, $key);
        // Specific Key
        $value = $this->setValueForSpecificKeys($key, $value, $format);

        $result = $this->setValue($result, $key, $value);
        return $this->setChildren($xml, $recursiveDepth, $key, $result);
    }
1200358
private function setChildren(\SimpleXMLElement $xml, $depth, $key, array $arrayXML) {
        $return = $arrayXML;
        if ($xml->children()->count() > 0) {
            foreach ($xml->children() as $childValue) {
                $child = $this->xml2array($childValue, $depth);
                if ($depth > 1 && ! empty($child)) {
                    $return = array_merge_recursive($return, [$key => $child]);
                } elseif (! empty($child)) {
                    $return = array_merge_recursive($return, $child);
                }
            }
        }
        return $return;
    }
1373909
final protected function parseSimpleXML(\SimpleXMLElement $element)
    {
        $elements = [];

        foreach ($element->attributes() as $attribute => $value) {
            $elements[$attribute] = $value instanceof \SimpleXMLElement ? $this->parseSimpleXML($value) : $value;
        }

        foreach ($element->children() as $node => $child) {
            $elements[$node] = $child instanceof \SimpleXMLElement ? $this->parseSimpleXML($child) : $child;
        }

        if ($element->count() === 0 && \trim((string) $element) !== '') {
            $value = $this->getTypedValue((string) $element);

            if (\count($elements) === 0) {
                return $value;
            }

            $elements['_value_'] = $value;
        }

        return $elements;
    }
941196
public static function getTemplate($template, $format = 'html5')
	{
		$templates = static::getTemplates($template, $format = 'html5');

		return isset($templates[0]) ? $templates[0] : null;
	}
1013325
private static function simpleXmlToArray($element)
    {
        //====================================================================//
        // Safety Check
        if (false === $element) {
            return false;
        }
        //====================================================================//
        // Init Result
        $result = array();
        //====================================================================//
        // Get First Level Childrens
        $children = $element->children();
        $isArrayElement = false;
        //====================================================================//
        // For All Childrens
        foreach ($children as $elementName => $node) {
            //====================================================================//
            // This Element is an ArrayElement
            $isArrayElement = true;
            //====================================================================//
            // If Element Doesn't Already Exists => Store as Single Element
            if (!isset($result[$elementName])) {
                $result[$elementName] = array();
                $result[$elementName] = self::simpleXmlToArray($node);

                continue;
            }
            //====================================================================//
            // Element Already Exists => Store as Array Element
            //====================================================================//
            // Convert Single Element to Array Element
            if (!is_array($result[$elementName])) {
                $singleElement = $result[$elementName];       // Store Firts Element
                $result[$elementName] = array();                    // Create New Array
                $result[$elementName][] = $singleElement;             // Append To Array
            }
            //====================================================================//
            // Append Array Element
            $result[$elementName][] = self::simpleXmlToArray($node);
        }
        //====================================================================//
        // Return Single Element
        if (!$isArrayElement && '' == $children->getName()) {
            $result = base64_decode((string) $element, true);
        }

        return $result;
    }
690090
public function setInverted($recursive=true) {
		if($recursive===true){
			$content=$this->_self->getContent();
			if($content instanceof HtmlSemDoubleElement)
				$content->setInverted($recursive);
			elseif(\is_array($content) || $content instanceof \Traversable){
				foreach ($content as $elm){
					if($elm instanceof  HtmlSemDoubleElement){
						$elm->setInverted($recursive);
					}
				}
			}
		}
		return $this->_self->addToProperty("class", "inverted");
	}
906470
public static function parseResponseRuleXml(SimpleXMLElement $xml){
        $returnValue = self::parseElementXml($xml);
        foreach($xml->children() as $child){
            $returnValue['expression'] = self::parseExpressionXml($child);
            break;
        }
        return $returnValue;
    }
453498
protected function handleXml(\SimpleXMLElement $xml)
    {
        $this->name = XmlHelper::get($xml, 'name');
        $this->label = XmlHelper::get($xml, 'label');

        $this->attributes = XmlHelper::getAttributes($xml);

        $form = $xml;

        $group = [];

        while ($parent = $form->xpath('..')) {
            $parent = $parent[0];

            $name = $parent->getName();

            if ($name === 'fieldset') {
                $this->fieldset = $this->fieldset ?: (string) $parent['name'];
            } elseif ($name === 'group') {
                array_unshift($group, (string) $parent['name']);
            }

            $form = $parent;
        }

        $this->group = implode('/', $group);
    }
915659
protected function _from_xml($string, $recursive = false)
	{
		// If it forged with 'xml:ns'
		if ( ! $this->ignore_namespaces)
		{
			static $escape_keys = array();
			$recursive or $escape_keys = array('_xmlns' => 'xmlns');

			if ( ! $recursive and strpos($string, 'xmlns') !== false and preg_match_all('/(\<.+?\>)/s', $string, $matches))
			{
				foreach ($matches[1] as $tag)
				{
					$escaped_tag = $tag;

					strpos($tag, 'xmlns=') !== false and $escaped_tag = str_replace('xmlns=', '_xmlns=', $tag);

					if (preg_match_all('/[\s\<\/]([^\/\s\'"]*?:\S*?)[=\/\>\s]/s', $escaped_tag, $xmlns))
					{
						foreach ($xmlns[1] as $ns)
						{
							$escaped = \Arr::search($escape_keys, $ns);
							$escaped or $escape_keys[$escaped = str_replace(':', '_', $ns)] = $ns;
							$string = str_replace($tag, $escaped_tag = str_replace($ns, $escaped, $escaped_tag), $string);
							$tag = $escaped_tag;
						}
					}
				}
			}
		}

		$_arr = is_string($string) ? simplexml_load_string($string, 'SimpleXMLElement', LIBXML_NOCDATA) : $string;

		// Convert all objects SimpleXMLElement to array recursively
		$arr = array();
		foreach ((array)$_arr as $key => $val)
		{
			$this->ignore_namespaces or $key = \Arr::get($escape_keys, $key, $key);
			if ( ! $val instanceOf \SimpleXMLElement or $val->count() or $val->attributes())
			{
				$arr[$key] = (is_array($val) or is_object($val)) ? $this->_from_xml($val, true) : $val;
			}
			else
			{
				$arr[$val->getName()] = null;
			}
		}

		return $arr;
	}
1014072
public function setFormat($format = null)
    {
        if ( ! is_null($format)) {
            self::checkFormat($format);
            $this->format = $format;
        }

        return $this;
    }
510414
protected function parseXML($xml){
        if (!$xml){
            return false;
        }
        foreach($xml->children() as $key=>$x){
            $i = $this->index;
            if ($key != 'ReportInfo'){
                continue;
            }
            
            $this->reportList[$i]['ReportId'] = (string)$x->ReportId;
            $this->reportList[$i]['ReportType'] = (string)$x->ReportType;
            $this->reportList[$i]['ReportRequestId'] = (string)$x->ReportRequestId;
            $this->reportList[$i]['AvailableDate'] = (string)$x->AvailableDate;
            $this->reportList[$i]['Acknowledged'] = (string)$x->Acknowledged;
            if (isset($x->AcknowledgedDate)) {
                $this->reportList[$i]['AcknowledgedDate'] = (string)$x->AcknowledgedDate;
            }
            
            $this->index++;
        }
    }
286381
public function build(SimpleXMLElement $parent = null) : SimpleXMLElement
    {
        if ($parent === null) {
            $xml = new SimpleXMLElement('<' . get_called_class()::getTagName() . "/>", LIBXML_PARSEHUGE);
        } else {
            $xml = $parent->addChild(get_called_class()::getTagName());
        }
        $this->setAttributes($xml);
        $this->setChilds($xml);

        return $xml;
    }
282998
public function getCmdResultFromXml($xml, $parentTag = 'sh') {
        $this->error = '';
        
        $xmlobj = simplexml_load_string($xml);
        if (!$xmlobj instanceof \SimpleXMLElement) {
            /*bad xml returned*/
            $this->error = "Can't read output xml";
            error_log($xml, 3, '/tmp/bad.xml');
            
            return false;
        }
        
        $retval = true; // assume OK unless error found. Was false, but sh doesn't return success flag.
        $params = $xmlobj->xpath("/script/$parentTag");
        
        foreach ($params as $simpleXMLElement) {
            // Note: there may be multiple ->error tags
            if (isset($simpleXMLElement->error)) {//*** error
                
                // newer way in XMLSERVICE 
                ///bookstore/book[last()]
                
                // get last joblogscan/joblogrec nested tags in the XML section. Returned as one-element array. function 'current' returns the one element.
                $lastJoblogTag = current($simpleXMLElement->xpath("joblogscan/joblogrec[last()]"));
                
                // if last job log tag contained a real CPF-style code, of length 7 (e.g. CPF1234), parsed for us.
                if ($lastJoblogTag && isset($lastJoblogTag->jobcpf) && (strlen($lastJoblogTag->jobcpf) == 7)) {
                    $this->cpfErr = (string) $lastJoblogTag->jobcpf;
                    $this->error = $this->cpfErr; // ->error has ambiguous meaning. Include for backward compatibility.
                    
                    $this->errorText = (string) $lastJoblogTag->jobtext;
                
                    $retval = false;
                    break;
                }
                
                /**
                 * <joblogscan>
                 * <joblogrec>
                 * <jobcpf>CPF1124</jobcpf>
                 * <jobtime><![CDATA[10/11/12  19:33:54.102423]]></jobtime>
                 * <jobtext><![CDATA[Job 127257/ASEIDEN/XTOOLKIT started on 10/11/12 at Job 127257/ASEIDEN/XTOOLKIT submitted.]]></jobtext>
                 * </joblogrec>
                 * <joblogrec>
                 * <jobcpf>*NONE</jobcpf>
                 * <jobtime><![CDATA[10/11/12  19:33:54.102423]]></jobtime>
                 * <jobtext><![CDATA[CALL PGM(XMLSERVICE/XMLSERVICE) PARM('/tmp/ASEIDEN_abc')]]></jobtext>
                 * </joblogrec>
                 * <joblogrec>
                 * <jobcpf>CPF3142</jobcpf>
                 * <jobtime><![CDATA[10/11/12  19:33:54.102423]]></jobtime>
                 * <jobtext><![CDATA[PLUGILE ILECMDEXC 5116 File NONEXIST in library *LIBL not found.]]></jobtext>
                 * </joblogrec>
                 * </joblogscan>
                 */
                // xpath(joblogscan/joblogrec[last()])
                // then ->jobcpf and ->jobtext
                
                // Note: there may be multiple ->error tags
                
                // As of XMLSERVICE 1.60:
                // array element[0] is probably the *** error text.
                // array element[1] may be the CPF code (not likely).
                if (isset($simpleXMLElement->error[1])) {
                    $this->error = (string) $simpleXMLElement->error[1];
                } else {
                    $this->error = "Command execute failed.";
                }
                
                //$err = (string )$simpleXMLElement->error;
                // there's an error code of some kind. use it.
                // A change: get rid of standard msg. Only return the err, which may be a CPF.
                //$this->error = "Command execute failed. ".$err;
                
                $retval = false;
                break;
            }
            
            // Older style. Now, *** error appears in ->error tag
            if (strstr(((string)$simpleXMLElement),"*** error")){
                // this message is a generic failure so it's OK.
                $this->error = "Command execute failed. ";
                $retval = false;
                break;
            }
            
            // in the case of interactive commands, there may be no "success" msg.
            if (isset($simpleXMLElement->success)) {
                $retval = true;
                break;
            }
            
            // Older style. Now, +++ success appears in ->success tag
            if (strstr(((string)$simpleXMLElement),"+++ success")) {
                $retval = true;
                break;
            }
        }
        
        return $retval;
    }
886010
public function getRequestXml(&$docRootXpath, &$docIdXpath, &$envelopeParams, $resetDocIds) {
        unset($this->_requestDom);
        $this->_requestDom = new DomDocument('1.0', 'utf-8');
        $root = $this->_requestDom->createElementNS('www.clusterpoint.com', 'cps:request');
        $this->_requestDom->appendChild($root);

        // envelope parameters first
        foreach ($envelopeParams as $name => $value) {
					if($value) {
            $root->appendChild($this->_requestDom->createElement('cps:' . $name , $this->getValidXmlValue($value)));
        	}
				}
        $contentTag = $root->appendChild($this->_requestDom->createElement('cps:content'));

        // content tag text parameters
        foreach ($this->_textParams as $name => $values) {
            if (!is_array($values)) {
                $values[0] = $values;
            }
            foreach ($values as $value) {
                $contentTag->appendChild($this->_requestDom->createElement($name , $this->getValidXmlValue($value)));
            }
        }

        // special fields: query, list, ordering
        foreach ($this->_rawParams as $name => $values) {
            if (!is_array($values)) {
                $values[0] = $values;
            }
            foreach ($values as $value) {
                $fragment = $this->_requestDom->createDocumentFragment();
                $fragment->appendXML('<' . $name . ' xmlns:cps="www.clusterpoint.com">' . $value . '</' . $name . '>');
                $contentTag->appendChild($fragment);
            }
        }

        if (!is_null($this->_changesets)) {
            $xmlContent = '';
            if (count($this->_changesets) > 1) {
                foreach ($this->_changesets as $cs) {
                    $xmlContent .= '<cps:changeset>';
                    $xmlContent .= $cs->renderXML($docRootXpath, $docIdXpath, $this);
                    $xmlContent .= '</cps:changeset>';
                }
            } else if (count($this->_changesets) == 1) {
                $xmlContent .= $this->_changesets[0]->renderXML($docRootXpath, $docIdXpath, $this);
            }
            if (strlen($xmlContent) > 0) {
                $tmpDoc = new DOMDocument();
                $tmpDoc->loadXML('<fakedoc xmlns:cps="www.clusterpoint.com">' . $xmlContent . '</fakedoc>');
                foreach ($tmpDoc->documentElement->childNodes as $child) {
                    $domNode2 = $this->_requestDom->importNode($child, true);
                    $contentTag->appendChild($domNode2);
                }
            }
        }

        // extra XML content
        if (!is_null($this->_extraXmlParam)) {
            $tmpDoc = new DOMDocument();
            if (!@$tmpDoc->loadXML('<fakedoc xmlns:cps="www.clusterpoint.com">' . $this->_extraXmlParam . '</fakedoc>')) {
                throw new CPS_Exception(array(array('long_message' => 'Invalid request parameter - unable to parse XML', 'code' => ERROR_CODE_INVALID_PARAMETER, 'level' => 'REJECTED', 'source' => 'CPS_API')));
            }
            foreach ($tmpDoc->documentElement->childNodes as $child) {
                $domNode2 = $this->_requestDom->importNode($child, true);
                $contentTag->appendChild($domNode2);
            }
        }

        // documents, document IDs
        foreach ($this->_documents as $id => $doc) {
            $subdoc = new DOMDocument();
            $subroot = NULL;
            $loadForEach = false;
            if (is_string($doc)) {
                $res = @$subdoc->loadXML($doc);
                if ($res === FALSE) {
                    throw new CPS_Exception(array(array('long_message' => 'Invalid request parameter - unable to parse XML', 'code' => ERROR_CODE_INVALID_PARAMETER, 'level' => 'REJECTED', 'source' => 'CPS_API')));
                }
            } else if (is_array($doc)) {
                // associative array
                $loadForEach = true;
            } else if (is_object($doc)) {
                if ($doc instanceof SimpleXMLElement) {
                    // SimpleXML
                    $loadForEach = true;
                } else if ($doc instanceof DOMNode) {
                    // DOM
                    $subdoc = $doc;
                } else if ($doc instanceof stdClass) {
                    // stdClass
                    $loadForEach = true;
                } else {
                    throw new CPS_Exception(array(array('long_message' => 'Invalid request parameter', 'code' => ERROR_CODE_INVALID_PARAMETER, 'level' => 'REJECTED', 'source' => 'CPS_API')));
                }
            } else if (is_null($doc)) {
                // just document IDs - no doc integration required
            } else {
                throw new CPS_Exception(array(array('long_message' => 'Invalid request parameter', 'code' => ERROR_CODE_INVALID_PARAMETER, 'level' => 'REJECTED', 'source' => 'CPS_API')));
            }

            if (!($subroot = $subdoc->documentElement)) {
                $subroot = $subdoc->createElement($docRootXpath);
                $subdoc->appendChild($subroot);
            }

            if ($loadForEach) {
                CPS_Request::_loadIntoDom($subdoc, $subroot, $doc);
            }

            if ($resetDocIds) {
                // integrating ID into the document
                CPS_Request::_setDocId($subdoc, $subroot, $id, $docIdXpath);
            }

            //importing subdoc
            $reqNode = $this->_requestDom->importNode($subdoc->documentElement, true);
            $contentTag->appendChild($reqNode);
        }
        $xml = $this->_requestDom->saveXML();
        unset($this->_requestDom);
        return $xml;
    }
667631
public function parseXML(\SimpleXMLElement $xml)
    {
        $name = $xml->getName();
        if ($name !== 'svg') {
            return null;
        }

        $width = isset($xml['width']) ? $xml['width'] : null;
        $height = isset($xml['height']) ? $xml['height'] : null;
        $namespaces = $xml->getNamespaces(true);

        $img = new SVG($width, $height, $namespaces);

        $nsKeys = array_keys($namespaces);

        $doc = $img->getDocument();
        $this->applyAttributes($doc, $xml, $nsKeys);
        $this->applyStyles($doc, $xml);
        $this->addChildren($doc, $xml, $nsKeys);

        return $img;
    }
39413
protected function parseManifestToArray( \SimpleXMLElement $xml ) {

		foreach ( $xml->manifest->children() as $item ) {
			/** @var \SimpleXMLElement $item */
			// Get attributes
			$id = '';
			$type = '';
			$href = '';
			foreach ( $item->attributes() as $key => $val ) {
				if ( 'id' === $key ) {
					$id = (string) $val;
				} elseif ( 'media-type' === $key ) {
						$type = (string) $val;
				} elseif ( 'href' === $key ) {
						$href = $val;
				}
			}

						// Skip
			if ( 'application/xhtml+xml' !== $type ) {
				continue;
			}

			$this->manifest[ $id ] = [
				'type' => $type,
				'href' => $href,
			];
		}

	}
1182948
XMLReader getXmlReader(final String format) throws SAXException {
        if (format == null || format.equals(ATTR_FORMAT_VALUE_DITA)) {
            return reader;
        }
        for (final Map.Entry<String, String> e : parserMap.entrySet()) {
            if (format.equals(e.getKey())) {
                try {
                    // XMLReaderFactory.createXMLReader cannot be used
                    final XMLReader r = (XMLReader) Class.forName(e.getValue()).newInstance();
                    final Map<String, Boolean> features = parserFeatures.getOrDefault(e.getKey(), emptyMap());
                    for (final Map.Entry<String, Boolean> feature : features.entrySet()) {
                        try {
                            r.setFeature(feature.getKey(), feature.getValue());
                        } catch (final SAXNotRecognizedException ex) {
                            // Not Xerces, ignore exception
                        }
                    }
                    return r;
                } catch (final InstantiationException | ClassNotFoundException | IllegalAccessException ex) {
                    throw new SAXException(ex);
                }
            }
        }
        return reader;
    }