@param SimpleXMLElement $akv

@return SimpleXMLElement
761123
public function exportValue(SimpleXMLElement $akv)
    {
        $val = '';
        if ($this->attributeValue) {
            $val = $this->attributeValue->getValue();
            if (is_object($val)) {
                $val = (string) $val;
            }
        }

        if (is_array($val)) {
            $val = json_encode($val);
        }

        $cnode = $akv->addChild('value');
        $node = dom_import_simplexml($cnode);
        $no = $node->ownerDocument;
        $node->appendChild($no->createCDataSection($val));

        return $cnode;
    }
219310
private function parseSimpleXMLMessage( SimpleXMLElement $message )
    {
        $status = ezcTranslationData::TRANSLATED;
        if ( $message->translation['type'] == 'unfinished' )
        {
            $status = ezcTranslationData::UNFINISHED;
        }
        else if ( $message->translation['type'] == 'obsolete' )
        {
            if ( $this->options->keepObsolete )
            {
                $status = ezcTranslationData::OBSOLETE;
            }
            else
            {
                return null;
            }
        }

        $source = trim( (string) $message->source );
        $translation = trim( (string) $message->translation );
        $comment = trim( (string) $message->comment );

        $source = strlen( $source ) ? $source : false;
        $translation = strlen( $translation ) ? $translation : false;
        $comment = strlen( $comment ) ? $comment : false;

        $location = $message->location;
        $file = $line = false;
        if ( $location )
        {
            $file = trim( (string) $location['filename'] );
            $line = trim( (string) $location['line'] );
        }

        return new ezcTranslationData( $source, $translation, $comment, $status, $file, $line );
    }
1076846
public function getAttributeValueObject($ak, $createIfNotExists = false)
    {
        if (!is_object($ak)) {
            $ak = UserKey::getByHandle($ak);
        }
        if (is_object($ak)) {
            $value = $this->getObjectAttributeCategory()->getAttributeValue($ak, $this->entity);
        } else {
            $value = null;
        }

        if ($value === null && $createIfNotExists) {
            $value = new UserValue();
            $value->setUser($this->entity);
            $value->setAttributeKey($ak);
        }

        return $value;
    }
835614
private static function parseResponseRulesContainerXml(SimpleXMLElement $xml){
        $returnValue = self::parseElementXml($xml);
        $responseRules = array();
        foreach($xml->children() as $child){
            $name = $child->getName();
            $methodName = 'parse'.ucfirst($name).'Xml';

            if(method_exists(__CLASS__, $methodName)){
                $responseRules[] = self::$methodName($child);
            }else{
                $responseRules[] = self::parseResponseRuleXml($child);
            }
        }
        $returnValue['responseRules'] = $responseRules;
        return $returnValue;
    }
636314
protected static function arrayToXML($data, &$xml = null){

            if($xml === null)
                $xml = new \SimpleXMLElement("<?xml version=\"1.0\"?><nondb></nondb>");
            foreach($data as $k=>$v){
                if(is_array($v)){
                    $sub = $xml->addChild("$k");
                    self::arrayToXML($v, $sub);
                }else{
                    $xml->addChild("$k", htmlspecialchars("$v"));
                }
            }

            return $xml->asXML();

        }
949521
protected function arrayToXml($result, &$xml)
	{
		foreach ($result as $key => $value) {
			if (is_array($value)) {
				if (!is_numeric($key)) {
					$subnode = $xml->addChild((string) $key);
				} else {
					$subnode = $xml->addChild('item_' . $key);
				}
				$this->arrayToXml($value, $subnode);
			} else {
				$xml->addChild($key, $value);
			}
		}
	}
647478
public static function raw2xml($val)
    {
        if (is_array($val)) {
            foreach ($val as $k => $v) {
                $val[$k] = self::raw2xml($v);
            }
            return $val;
        }

        return htmlspecialchars($val, ENT_QUOTES, 'UTF-8');
    }
465359
static function RecurseXmlObjToArr($obj, &$arr)
	{
		$children = $obj->children();
		foreach ($children as $elementName => $node)
		{
			$nextIdx = count($arr);
			$arr[$nextIdx] = array();
			$arr[$nextIdx]['@name'] = strtolower((string)$elementName);
			$arr[$nextIdx]['@attributes'] = array();
			$attributes = $node->attributes();
			foreach ($attributes as $attributeName => $attributeValue)
			{
				$attribName = strtolower(trim((string)$attributeName));
				$attribVal = trim((string)$attributeValue);
				$arr[$nextIdx]['@attributes'][$attribName] = $attribVal;
			}
			$text = (string)$node;
			$text = trim($text);
			if (strlen($text) > 0)
			{
				$arr[$nextIdx]['@text'] = $text;
			}
			$arr[$nextIdx]['@children'] = array();
			VerySimpleXmlUtil::RecurseXmlObjToArr($node, $arr[$nextIdx]['@children']);
		}
		return;
	}
649619
public function xml(SimpleXMLElement $parent)
    {
        $option = $parent->addChild('option');
        $option->addAttribute('name', '--' . $this->_name);
        $short = '';
        if (strlen($this->_short) > 0) {
            $short = '-' . $this->_short;
        }
        $option->addAttribute('short', $short);
        $option->addAttribute('help', $this->_help);
        $option->addAttribute('boolean', (int)$this->_boolean);
        $option->addChild('default', $this->_default);
        $choices = $option->addChild('choices');
        foreach ($this->_choices as $valid) {
            $choices->addChild('choice', $valid);
        }

        return $parent;
    }
644615
public static function xmlToArray(SimpleXMLElement $xml, $format = self::XML_GROUP) {
        if (count($xml->children()) <= 0) {
            return static::autobox((string) $xml);
        }

        $array = array();

        /** @type SimpleXMLElement $node */
        foreach ($xml->children() as $element => $node) {
            $data = array();
            $children = $node->children();

            if (!isset($array[$element])) {
                $array[$element] = '';
            }

            if (!$node->attributes() || $format === static::XML_NONE) {
                $data = static::xmlToArray($node, $format);

            } else {
                switch ($format) {
                    case static::XML_GROUP:
                        $data = array(
                            'value' => static::autobox((string) $node),
                            'attributes' => array()
                        );

                        if (count($children) > 0) {
                            $data['value'] = static::xmlToArray($node, $format);
                        }

                        foreach ($node->attributes() as $attr => $value) {
                            $data['attributes'][$attr] = static::autobox((string) $value);
                        }
                    break;

                    case static::XML_MERGE:
                        if (count($children) > 0) {
                            $data = $data + static::xmlToArray($node, $format);
                        } else {
                            $data['value'] = static::autobox((string) $node);
                        }
                    /* fall-through */

                    case static::XML_ATTRIBS:
                        foreach ($node->attributes() as $attr => $value) {
                            $data[$attr] = static::autobox((string) $value);
                        }
                    break;
                }
            }

            if (count($xml->{$element}) > 1) {
                $array[$element][] = $data;
            } else {
                $array[$element] = $data;
            }
        }

        return $array;
    }
1067691
public static function ToXmlNode( $nav )
	{
		if ( $nav instanceof \DOMNode ) return $nav;

		if ( $nav instanceof XPathNavigator ) return $nav->getUnderlyingObject();

		return null;
	}
396432
public static function xmlToElement(string $string): \SimpleXMLElement
    {
        $disableEntities = libxml_disable_entity_loader(true);
        $internalErrors = libxml_use_internal_errors(true);

        try {
            // Allow XML to be retrieved even if there is no response body
            $xml = new \SimpleXMLElement($string ?: '<root />', LIBXML_NONET);

            libxml_disable_entity_loader($disableEntities);
            libxml_use_internal_errors($internalErrors);
        } catch (\Exception $e) {
            libxml_disable_entity_loader($disableEntities);
            libxml_use_internal_errors($internalErrors);

            throw new \RuntimeException('Unable to parse XML data: '.$e->getMessage());
        }

        return $xml;
    }
184169
protected function _simpleXml($mixed): \SimpleXMLElement
    {
        if ($mixed instanceof \DOMNode) {
            return \simplexml_import_dom($mixed);
        }

        if (File::isFile($mixed))
        {
            $mixed = \file_get_contents($mixed);
        }

        return \simplexml_load_string($mixed);
    }
555097
public static function xml(array $arr) {
        parent::setContentType('application/xml');

        $simpleXML = new \SimpleXMLElement('<?xml version="1.0"?><data></data>');
        self::arrayToXML($arr, $simpleXML);

        return $simpleXML->asXML();
    }
670774
static function simpleXmlToStdClass(SimpleXMLElement &$source)
  {
    $res = new StdClass;
    $children = false;
    foreach ($source as $key => $value) {
      if (isset($res->$key)) {
        if (!is_array($res->$key)) {
          $res->$key = array($res->$key);
        }
        $ref = &$res->$key;
        $ref[] = CPS_Response::simpleXmlToStdClass($value);
      } else {
        $res->$key = CPS_Response::simpleXmlToStdClass($value);
      }
      $children = true;
    }
    if (!$children)
      return (string)$source;
    return $res;
  }
442314
private static function _unserializeRecursive(SimpleXMLElement $xml)
    {
        $result = [];
        $dataNamespace = Resources::DS_XML_NAMESPACE;
        /** @var SimpleXMLElement $child */
        foreach ($xml->children($dataNamespace) as $child) {
            if (count($child->children($dataNamespace)) > 0) {
                $value = [];
                $children = $child->children($dataNamespace);
                /** @var SimpleXMLElement $firstChild */
                $firstChild = $children[0];
                if ($firstChild->getName() == 'element') {
                    foreach ($children as $subChild) {
                        $value[] = self::_unserializeRecursive(
                            $subChild
                        );
                    }
                } else {
                    $value = self::_unserializeRecursive(
                        $child
                    );
                }
            } else {
                $value = (string) $child;
            }

            $result[$child->getName()] = $value;
        }

        return $result;
    }
657081
public function getAttributeValueObject($ak, $createIfNotExists = false)
    {
        if (!is_object($ak)) {
            $ak = CollectionKey::getByHandle($ak);
        }
        $value = false;
        if (is_object($ak)) {
            $value = $this->getObjectAttributeCategory()->getAttributeValue($ak, $this);
        }

        if ($value) {
            return $value;
        } elseif ($createIfNotExists) {
            $attributeValue = new PageValue();
            $attributeValue->setPageID($this->getCollectionID());
            $attributeValue->setVersionID($this->getVersionID());
            $attributeValue->setAttributeKey($ak);

            return $attributeValue;
        }
    }