Canonicalizes a DOM document or a single DOM node

@param	\DOMNode					$data	Node(s) to be canonicalized
@throws	\UnexpectedValueException			If the canonicalization process failed
@return	string|bool							Canonicalized node(s), or false on failure
510930
protected function canonicalize(\DOMNode $object)
	{		
		$options = $this->c14nOptionMapping[$this->canonicalMethod];
		
		// canonicalize the provided data with the preset options
		$c14nData = $object->C14N($options['exclusive'], $options['withComments']);
		
		if (is_string($c14nData) && strlen($c14nData))
		{
			return $c14nData;
		}
		
		throw new \UnexpectedValueException('Unable to canonicalize the provided DOM document');
	}
67987
public function writeText(string $data): XmlStreamWriter
    {
        return $this->append(
                function(\DOMNode $parent) use ($data)
                {
                    $parent->appendChild(
                            $this->doc->createTextNode($this->encode($data))
                    );
                },
                'text'
        );
    }
263415
public function toXML( DOMDocument $dom )
    {
        if ( !$this->XMLStorable )
        {
            return false;
        }

        $itemNode = $dom->createElement( 'item' );

        foreach ( $this->attributes as $attrName => $attrValue )
        {
            switch ( $attrName )
            {
                case 'id':
                    $itemNode->setAttribute( 'id', $attrValue );
                    break;

                case 'action':
                    $itemNode->setAttribute( 'action', $attrValue );
                    break;

                default:
                    $node = $dom->createElement( $attrName );
                    $nodeValue = $dom->createTextNode( $attrValue );
                    $node->appendChild( $nodeValue );
                    $itemNode->appendChild( $node );
                    break;
            }
        }

        return $itemNode;
    }
1226439
public function to_xml($data){
        if(!is_array($data) || count($data) <= 0) throw new \Exception('xml data exception!');
        $xml = "<xml>";
        foreach ($data as $key=>$val){
            if (is_numeric($val)){
                $xml.="<".$key.">".$val."</".$key.">";
            }else{
                $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
            }
        }
        $xml.="</xml>";
        return $xml;
    }
1266749
public function parseReadData($data)
	{
		$results = array();

		foreach ($data as $row) {
			if (is_array($row)) {
				$key = $row['key'];
				$value = $row['value'];
			} elseif (is_object($row)) {
				$key = $row->key;
				$value = $row->value;
			} else {
				$msg = 'Expected array or object, got '.gettype($row);
				throw new \UnexpectedValueException($msg);
			}

			SettingsUtilities::set($results, $key, $value);
		}

		return $results;
	}
1182029
protected function convertValue($data)
    {
        if ($this->isTraversable($data)) {
            return $this->recursiveConvertArray($data);
        }

        if (is_object($data)) {
            return $this->convertObject($data) ?: null;
        }

        return $data;
    }
796706
public function parseReadData($data)
	{
		$results = array();

		foreach ($data as $row) {
			if (is_array($row)) {
				$key = $row[$this->keyColumn];
				$value = $row[$this->valueColumn];
			} elseif (is_object($row)) {
				$key = $row->{$this->keyColumn};
				$value = $row->{$this->valueColumn};
			} else {
				$msg = 'Expected array or object, got '.gettype($row);
				throw new \UnexpectedValueException($msg);
			}

			ArrayUtil::set($results, $key, $value);
		}

		return $results;
	}
685030
private function handleValue( $value, DOMDocument $domDocument )
    {
        switch ( gettype( $value ) )
        {
            case 'integer':
                $node = $domDocument->createElement( 'int', $value );
                break;

            case 'boolean':
                $node = $domDocument->createElement( 'boolean', $value );
                break;

            case 'string':
                $node = $domDocument->createElement( 'string', $value );
                break;

            case 'double':
                $node = $domDocument->createElement( 'double', $value );
                break;

            case 'array':
                // array
                if ( empty( $value ) || key( $value ) === 0 )
                {
                    $node = $domDocument->createElement( 'array' );
                    $dataNode = $domDocument->createElement( 'data' );
                    $node->appendChild( $dataNode );

                    foreach ( $value as $cell )
                    {
                        $valueNode = $domDocument->createElement( 'value' );
                        $valueNode->appendChild( $this->handleValue( $cell, $domDocument ) );
                        $dataNode->appendChild( $valueNode );
                    }
                }
                // hash
                else
                {
                    $node = $domDocument->createElement( 'struct' );

                    foreach ( $value as $name => $cell )
                    {
                        // //member
                        $memberNode = $domDocument->createElement( 'member' );

                        // //member/name
                        $memberNode->appendChild( $domDocument->createElement( 'name', $name ) );

                        // //member/value
                        $valueNode = $domDocument->createElement( 'value' );
                        $memberNode->appendChild( $valueNode );
                        // //member/value/*
                        $valueNode->appendChild( $this->handleValue( $cell, $domDocument ) );

                        $node->appendChild( $memberNode );
                    }
                }
                break;

            case 'object':
                {
                    // DateTime is okay
                    if ( !$value instanceof DateTime )
                        continue;
                    $node = $domDocument->createElement( 'dateTime.iso8601', $value->format( DateTime::ISO8601 ) );
                }
                break;

            default:
                {
                    throw new \UnexpectedValueException( "Unknown return value type" );
                }
        }

        return $node;
    }
233067
public function toArray($data)
    {
        $doc = new DomDocument('1.0', 'UTF-8');
        $doc->loadXML($data);
        $element = $doc->documentElement;

        return $this->convertDOMElementToArray($element);
    }
1306346
public function resolveDataValue($data)
    {
        if ($data instanceof Data) {

            return $this->setData($data);

        } elseif (is_array($data)) {

            return $this->setData(new Data($data));
        }

        throw new \InvalidArgumentException(
            "Data must be View\Data or array value"
        );
    }
1181023
public function update($data) {
        $data = Values::of(array('Data' => Serialize::jsonObject($data), ));

        $payload = $this->version->update(
            'POST',
            $this->uri,
            array(),
            $data
        );

        return new DocumentInstance(
            $this->version,
            $payload,
            $this->solution['serviceSid'],
            $this->solution['sid']
        );
    }
193558
public function createMenuNode($data) {
		$cls = $this->itemClass;
		$node = $cls::create($data, $this);
		$this->items[$node->ID] = $node;
		return $node;
	}
1016373
public function appendXml($data)
    {
        $xml                        = new Xml();
        $xml->preserveWhiteSpace    = false;
        $bool                       = @$xml->loadXML($data);

        if (!$bool) {
            $this->_errorsList['xml_load_error']    = $data;
            $this->_hasErrors                       = true;
            return $this;
        }

        try {
            $temp = $this->_xmlToArray($xml->documentElement);
            $this->appendArray($temp);
        } catch (DOMException $exception) {
            $this->_addException($exception);
        }

        if ($this->_objectCreation) {
            return $this->_afterAppendDataToNewObject();
        }
        return $this;
    }
1146647
protected function arrayToXml($data, \SimpleXmlElement $element, $parent = null)
    {
        foreach ($data as $key => $value) {
            if (is_array($value) || $value instanceof \Traversable) {
                if (!is_numeric($key)) {
                    if (count($value) > 0 && isset($value[0])) {
                        $this->arrayToXml($value, $element, $key);
                    } else {
                        $subnode = $element->addChild($key);
                        $this->arrayToXml($value, $subnode, $key);
                    }
                } else {
                    $subnode = $element->addChild($parent);
                    $this->arrayToXml($value, $subnode, $parent);
                }
            } else {
                if (!is_numeric($key)) {
                    if (substr($key, 0, 1) === '@') {
                        $element->addAttribute(substr($key, 1), $value);
                    } elseif ($key === 'value' and count($data) === 1) {
                        $element[0] = $value;
                    } elseif (is_bool($value)) {
                        $element->addChild($key, intval($value));
                    } else {
                        $element->addChild($key, htmlspecialchars($value, ENT_QUOTES));
                    }
                } else {
                    $element->addChild($parent, htmlspecialchars($value, ENT_QUOTES));
                }
            }
        }
    }
359162
protected function serializeData($data, $contentType)
    {
        if (is_string($data)) {
            return $data;
        }
        
        $repository = new ApacheMimeTypes();
        list($format) = $repository->findExtensions($contentType) + [null];
        
        $method = 'serializeDataTo' . $format;
        
        if (method_exists($this, $method)) {
            return $this->$method($data);
        }

        $type = (is_object($data) ? get_class($data) . ' ' : '') . gettype($data);
        throw new \UnexpectedValueException("Unable to serialize $type to '$contentType'");
    }
698532
public function withValues($data)
    {
        $copy = $this->values;
        foreach ($data as $key => $value) {
            $copy[$key] = $value;
        }
        return new Context($copy);
    }
1149138
protected function dataToXml($data)
    {
        if (!is_string($data)) {
            throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_PARSE_XML);
        }
        $xml = new DOMDocument();
        $error = null;
        try {
            $loaded = $xml->loadXML($data, $this->getLoadFlags());
        } catch (Exception $x) {
            $error = $x;
        } catch (Throwable $x) {
            $error = $x;
        }
        if ($error !== null || $loaded === false) {
            throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_PARSE_XML, $error ? $error->getMessage() : '');
        }

        return $xml;
    }