@param SimpleXmlElement $xml
@param $node
@param string $type

@return SimpleXMLElement
333911
protected function numberData(SimpleXmlElement $xml, $node,  $type='latn')
    {

        if (!$xml->numbers) {
            return;
        }

        foreach ($xml->numbers->children() as $child) {
            if ( $child->getName() == $node && $child['numberSystem'] == $type) {
                return $child;
            }
            
        }
    }
557811
private function parseMetadataType(\SimpleXMLElement $node, $type)
    {
        $options = $this->parseOptions($node);

        return $this->getMetadataType((string) $node['name'], $type, $options);
    }
436270
public function buildNodeEntityMetadata(\SimpleXMLElement $node, $className)
    {
        $reflection = new \ReflectionClass($className);

        return new NodeEntityMetadata(
            $className,
            $reflection,
            $this->buildNodeMetadata($node, $className),
            $this->idXmlMetadataFactory->buildEntityIdMetadata($node, $className, $reflection),
            $this->propertyXmlMetadataFactory->buildPropertiesMetadata($node, $className, $reflection),
            $this->relationshipXmlMetadataFactory->buildRelationshipsMetadata($node, $className, $reflection)
        );
    }
906470
public static function parseResponseRuleXml(SimpleXMLElement $xml){
        $returnValue = self::parseElementXml($xml);
        foreach($xml->children() as $child){
            $returnValue['expression'] = self::parseExpressionXml($child);
            break;
        }
        return $returnValue;
    }
1168606
public static function fromString(string $xml) : DOMDocument
    {
        if (trim($xml) === '') {
            throw InvalidArgumentException::invalidType('non-empty string', $xml);
        }

        $entityLoader = libxml_disable_entity_loader(true);
        $internalErrors = libxml_use_internal_errors(true);
        libxml_clear_errors();

        $domDocument = self::create();
        $options = LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_NONET;
        if (defined('LIBXML_COMPACT')) {
            $options |= LIBXML_COMPACT;
        }

        $loaded = $domDocument->loadXML($xml, $options);

        libxml_use_internal_errors($internalErrors);
        libxml_disable_entity_loader($entityLoader);

        if (!$loaded) {
            $error = libxml_get_last_error();
            libxml_clear_errors();

            throw new UnparseableXmlException($error);
        }

        libxml_clear_errors();

        foreach ($domDocument->childNodes as $child) {
            if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
                throw new RuntimeException(
                    'Dangerous XML detected, DOCTYPE nodes are not allowed in the XML body'
                );
            }
        }

        return $domDocument;
    }
984166
protected function getRouteConfigOptions(SimpleXmlElement $node, $type)
    {
        $config = null;

        if (!isset($node->$type)) {
            return $config;
        }

        $routeType = $type;
        $typeNode = $node->$type;

        switch ($type) {
            case 'standard':
                $routeType = 'rampage.route.standard';
                $config = array(
                    'frontname' => (string)$typeNode['frontname'],
                    'namespace' => (string)$typeNode['namespace'],
                    'allowed_params' => array(),
                    'defaults' => $this->childToArray($typeNode, 'defaults'),
                );

                foreach ($typeNode->xpath("./parameters/allow[@name != '']") as $allowedParam) {
                    $allowedParam = (string)$allowedParam['name'];
                    $config['allowed_params'][$allowedParam] = $allowedParam;
                }

                break;

            case 'literal':
                $config = array(
                    'route' => (string)$typeNode['route'],
                    'constraints' => $this->childToArray($typeNode, 'constraints'),
                    'defaults' => $this->childToArray($typeNode, 'defaults')
                );

                break;

            case 'segment':
                $config = array(
                    'route' => (string)$typeNode['route'],
                    'constraints' => $this->childToArray($typeNode, 'constraints'),
                    'defaults' => $this->childToArray($typeNode, 'defaults')
                );

                break;

            case 'regex':
                $config = array(
                    'spec' => (string)$typeNode['spec'],
                    'regex' => (string)$typeNode['regex'],
                    'constraints' => $this->childToArray($typeNode, 'constraints'),
                    'defaults' => $this->childToArray($typeNode, 'defaults')
                );

                break;

            case 'layout':
                $routeType = 'rampage.route.layout';
                $config = array(
                    'route' => (string)$typeNode['route'],
                    'layout' => (string)$typeNode['layout'],
                    'handles' => array()
                );

                foreach ($typeNode->xpath("./handle[@name != '']") as $handleNode) {
                    $handle = (string)$handleNode['name'];
                    $config['handles'][$handle] = $handle;
                }

                break;

            case 'custom':
            default:
                $typeNode = $node->custom;
                $config = (isset($typeNode->options))? $typeNode->options->toPhpValue('array') : null;

                if (isset($config['type'])) {
                    $routeType = $config['type'];
                    unset($config['type']);
                }

                break;
        }

        if (!$config) {
            return false;
        }

        if (isset($typeNode['controller'])) {
            $config['defaults']['controller'] = (string)$typeNode['controller'];
        }

        if (isset($typeNode['action'])) {
            $config['defaults']['action'] = (string)$typeNode['action'];
        }

        $config = array(
            'type' => $routeType,
            'options' => $config
        );

        return $config;
    }
121289
public function sendXml($type, $name, $xml)
    {
        $this->factory
            ->setBuilder($this->getBuilder($type))
            ->setSender($this->getSender($type));

        return $this->factory->sendXml($name, $xml);
    }
226129
private function buildRelationshipMetadata(\SimpleXMLElement $node, $className)
    {
        if (!isset($node['type'])) {
            throw new MappingException(
                sprintf('Class "%s" OGM XML configuration is missing "type" attribute', $className)
            );
        }
        $entity = new RelationshipEntity();
        $entity->type = (string) $node['type'];

        if (isset($node['direction'])) {
            $entity->direction = (string) $node['direction'];
        }

        return $entity;
    }
1349990
public static function parseExpressionXml(SimpleXMLElement $xml){
        $returnValue = self::parseElementXml($xml);
        $value = trim($xml);
        $expressions = array();
        foreach($xml->children() as $child){
            $expressions[] = self::parseExpressionXml($child);
        }
        if(count($expressions)){
            $returnValue['expressions'] = $expressions;
        }
        if(strlen($value)){
            $returnValue['value'] = $value;
        }
        return $returnValue;
    }
396187
public function toXml(\SimpleXMLElement $root) {
    	$propertyNode = $root->addChild("parameter");
    	$propertyNode->addAttribute("name", $this->getName());
    	$propertyNode->addAttribute("position", $this->getPosition());
    	$propertyNode->addAttribute("hasDefault", $this->isDefaultValueAvailable()?"true":"false");
    	if ($this->isDefaultValueAvailable()) {
			$propertyNode->addAttribute("default", serialize($this->getDefaultValue())); 
    	}
    	$propertyNode->addAttribute("isArray", $this->isArray()?"true":"false");
    	if ($this->getClass() != null) {
    		$propertyNode->addAttribute("class", $this->getClass()->getName());
    	}
    }
1295199
private function parseXml(\DOMNode $node, array $context = [])
    {
        $data = $this->parseXmlAttributes($node, $context);

        $value = $this->parseXmlValue($node, $context);

        if (!\count($data)) {
            return $value;
        }

        if (!\is_array($value)) {
            $data['#'] = $value;

            return $data;
        }

        if (1 === \count($value) && key($value)) {
            $data[key($value)] = current($value);

            return $data;
        }

        foreach ($value as $key => $val) {
            $data[$key] = $val;
        }

        return $data;
    }
795612
public static function formXml($xml, $file)
    {
        $xml = simplexml_load_string($xml);
        /** @var  $dataArray \SimpleXMLElement[] */
        $dataArray = $xml->attributes();

        $dataFileInfo = new DataFileInfo();
        if (isset($dataArray['Id'])) {
            $dataFileInfo->setId($dataArray['Id']->__toString());
        }
        if (isset($dataArray['Filename'])) {
            $dataFileInfo->setFilename($dataArray['Filename']->__toString());
        }
        if (isset($dataArray['ContentType'])) {
            $dataFileInfo->setContentType($dataArray['ContentType']->__toString());
        }
        if (isset($dataArray['MimeType'])) {
            $dataFileInfo->setMimeType($dataArray['MimeType']->__toString());
        }
        if (isset($dataArray['Size'])) {
            $dataFileInfo->setSize($dataArray['Size']->__toString());
        }
        if (isset($dataArray['DigestType'])) {
            $dataFileInfo->setDigestType($dataArray['DigestType']->__toString());
        }
        if (isset($dataArray['DigestValue'])) {
            $dataFileInfo->setDigestValue($dataArray['DigestValue']->__toString());
        }
        if (isset($dataArray['DfData'])) {
            $dataFileInfo->setDfData($dataArray['DfData']->__toString());
        } elseif (file_exists($file)) {
            $dataFileInfo->setDfData(base64_encode(file_get_contents($file)));
        }

        // TODO: validate data

        return $dataFileInfo;
    }
159663
public function xml(SimpleXMLElement $parent)
    {
        $command = $parent->addChild('command');
        $command->addAttribute('name', $this->_name);
        $command->addAttribute('help', $this->_help);

        return $parent;
    }
1251295
private static function convert(XMLElement $root = null, DOMNode $node)
    {
        $el = new XMLElement($node->tagName);

        self::convertNode($el, $node);

        if (is_null($root)) {
            return $el;
        } else {
            $root->appendChild($el);
        }
    }
1063064
final public function write($xml)
    {

        if($xml instanceof \SimpleXMLElement){
            $xml = $xml->asXML();
        } elseif($xml instanceof \DOMDocument){
            $xml = $xml->saveXML();
        }

        $this->log("SENT: ".$xml);

        return parent::write($xml);
    }
1145420
public static function createFromXML( DOMElement $node )
    {
        $newObj = new eZPageBlock();

        if ( $node->hasAttributes() )
        {
            foreach ( $node->attributes as $attr )
            {
                if ( $attr->name == 'id' )
                {
                    $value = explode( '_', $attr->value );
                    $newObj->setAttribute( $attr->name, $value[1] );
                }
                else
                {
                    $newObj->setAttribute( $attr->name, $attr->value );
                }
            }
        }

        foreach ( $node->childNodes as $node )
        {
            if ( $node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'item' )
            {
                $blockItemNode = eZPageBlockItem::createFromXML( $node );
                $newObj->addItem( $blockItemNode );
            }
            elseif ( $node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'rotation' )
            {
                $attrValue = array();

                foreach ( $node->childNodes as $subNode )
                {
                    if ( $subNode->nodeType == XML_ELEMENT_NODE )
                        $attrValue[$subNode->nodeName] = $subNode->nodeValue;
                }

                $newObj->setAttribute( $node->nodeName, $attrValue );
            }
            elseif ( $node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'custom_attributes' )
            {
                $attrValue = array();

                foreach ( $node->childNodes as $subNode )
                {
                    if ( $subNode->nodeType == XML_ELEMENT_NODE )
                        $attrValue[$subNode->nodeName] = $subNode->nodeValue;
                }

                $newObj->setAttribute( $node->nodeName, $attrValue );
            }
            else
            {
                if ( $node->nodeType == XML_ELEMENT_NODE )
                    $newObj->setAttribute( $node->nodeName, $node->nodeValue );
            }
        }

        return $newObj;
    }
480409
protected function buildXML(DOMDocument $dom, \DOMNode $node, $data)
    {
        $normalizer = $this->getNormalizer();

        if (null === $data) {
            return;
        }

        if ((is_array($data) || $data instanceof \Traversable) && !$this->isXmlElement($data)) {
            return $this->buildXmlFromTraversable($dom, $node, $normalizer->ensureBuildable($data));
        }

        $this->setElementValue($dom, $node, $data);
    }