Returns a XML string content as a DOMDocument or as a formated XML string
@throws \InvalidArgumentException
@param string $string
@param bool $asDomDocument
@return \DOMDocument|string|null
421844
public static function getFormatedXml($string, $asDomDocument = false)
    {
        if (!is_null($string)) {
            $domDocument = self::getDOMDocument($string);
            return $asDomDocument ? $domDocument : $domDocument->saveXML();
        }
        return null;
    }
849610
public function read($string)
	{
		// if $string is not a string, short-circuit
		if ( ! is_string($string)) {
			throw new \InvalidArgumentException(
				__METHOD__."() expects parameter one, string, to, er, be a string"
			);
		}
		
		// otherwise, create a new text chunker
		$chunker = new \Jstewmc\Chunker\Text($string);
		
		return $this->create($chunker);
	}
923570
public function getDomDocumentResponse()
    {
        $response = $this->getResponse();
        $xml = new DOMDocument();
        $xml->loadXML($response);
        return $xml;
    }
175124
public static function getDOM($str)
	{
		//create domdocument
		$dom = new DOMDocument();
		//load by file or string
		is_file($str) ? $dom->load($str) : $dom->loadXML($str);
		// return the DOMDoc
		return $dom;
	}
728398
protected function loadXMLString($xmlString)
    {
        $document = new DOMDocument();

        libxml_use_internal_errors(true);
        libxml_clear_errors();

        // Options:
        // - substitute entities
        // - disable network access
        // - relax parser limits for document size/complexity
        $success = $document->loadXML($xmlString, LIBXML_NOENT | LIBXML_NONET | LIBXML_PARSEHUGE);

        if (!$success) {
            $messages = array();

            foreach (libxml_get_errors() as $error) {
                $messages[] = trim($error->message);
            }

            throw new InvalidArgumentException(
                '$inputValue',
                'Could not create XML document: ' . implode("\n", $messages)
            );
        }

        return $document;
    }
883115
private function loadXmlInDom(\DOMDocument $dom, $xml, $method)
    {
        $usedInternalErrors       = libxml_use_internal_errors(true);
        $externalEntitiesDisabled = libxml_disable_entity_loader(false);

        libxml_clear_errors();

        if (!$this->loadDomDocument($dom, $xml, $method)) {
            libxml_disable_entity_loader($externalEntitiesDisabled);

            throw new InvalidArgumentException($this->formatLibXmlErrors($usedInternalErrors));
        }

        // restore previous libxml setting:
        libxml_use_internal_errors($usedInternalErrors);
        libxml_disable_entity_loader($externalEntitiesDisabled);

        return $dom;
    }
1049997
public function setHtml($html)
    {
        if (!\is_string($html)) {
            throw new \InvalidArgumentException('The provided HTML must be a string.', 1540403913);
        }
        if ($html === '') {
            throw new \InvalidArgumentException('The provided HTML must not be empty.', 1540403910);
        }

        $this->createUnifiedDomDocument($html);
    }
1085656
public function loadXml($sXml, $oDomDocument = null)
    {
        if (!$oDomDocument) {
            $oDomDocument = new DOMDocument('1.0', 'utf-8');
        }

        libxml_use_internal_errors(true);
        $oDomDocument->loadXML($sXml);
        $errors = libxml_get_errors();
        $blLoaded = empty($errors);
        libxml_clear_errors();

        if ($blLoaded) {
            return $oDomDocument;
        }

        return false;
    }
1362052
public static function recode( $xml, $encodeTo = "UTF-8" )
	{
		$validator	= new XML_DOM_SyntaxValidator();
		if( !$validator->validate( $xml ) )
			throw new InvalidArgumentException( 'String is no valid XML' ); 

		$encodeTo	= strtoupper( $encodeTo );
		
		$document	= new DOMDocument();
		$document->loadXml( $xml );
		$encoding	= strtoupper( $document->actualEncoding );
#		remark( "Encoding: ".$encoding );
		if( $encoding == $encodeTo )
			return $xml;
		
		$pattern		= '@<\?(.*) encoding=(\'|")'.$encoding.'(\'|")(.*)\?>@i';
		$replacement	= '<?\\1 encoding="'.$encodeTo.'"\\4?>';
		$xml	= iconv( $encoding, $encodeTo, $xml );
		$xml	= preg_replace( $pattern, $replacement, $xml );
		return $xml;
	}
910424
public function unserialize($text)
    {
        $xml = new \DOMDocument();
        $internalErrors = libxml_use_internal_errors(true);
        if(!$text || ($text && !$xml->loadXML($text))) {
            libxml_use_internal_errors($internalErrors);
            throw new \InvalidArgumentException('Failed to parse provided XML!');
        }
        libxml_use_internal_errors($internalErrors);

        $xpath = new \DOMXPath($xml);
        $shortcode = $xpath->query('/shortcode');
        if($shortcode->length !== 1) {
            throw new \InvalidArgumentException('Invalid shortcode XML!');
        }
        $name = $this->getAttribute($shortcode->item(0), 'name');

        $bbCode = $this->getValue($xpath->query('/shortcode/bbCode'));
        $content = $this->getValue($xpath->query('/shortcode/content'));

        $parameters = array();
        $elements = $xpath->query('/shortcode/parameters/parameter');
        for($i = 0; $i < $elements->length; $i++) {
            $node = $elements->item($i);

            $parameters[$this->getAttribute($node, 'name')] = $node->hasChildNodes() ? $node->nodeValue : null;
        }

        return new Shortcode($name, $parameters, $content, $bbCode);
    }
1046213
function xmlString( )
    {
        $doc = new DOMDocument( '1.0', 'utf-8' );

        $root = $doc->createElement( "ezoption" );
        $doc->appendChild( $root );

        $name = $doc->createElement( "name" );
        $name->appendChild( $doc->createCDATASection( $this->Name ) );
        $root->appendChild( $name );

        $options = $doc->createElement( "options" );
        $root->appendChild( $options );

        foreach ( $this->Options as $option )
        {
            $optionNode = $doc->createElement( "option" );
            $optionNode->appendChild( $doc->createCDATASection( $option["value"] ) );
            $optionNode->setAttribute( "id", $option['id'] );
            $optionNode->setAttribute( 'additional_price', $option['additional_price'] );
            $options->appendChild( $optionNode );
        }

        $xml = $doc->saveXML();

        return $xml;
    }
489102
public function read($string)
    {
        try {
            $wasUsingErrors = libxml_use_internal_errors();
            @$xmlObject = simplexml_load_string($string);
            libxml_use_internal_errors($wasUsingErrors);
            if ($xmlObject) {
                return $this->recurseToArray($xmlObject);
            }
        } catch (\Exception $e) {
            // Do nothing
        }
        return null;
    }
971997
private function loadDomDocument(\DOMDocument $dom, $xml, $method)
    {
        return call_user_func_array(
            [$dom, $method],
            // set LIBXML_NONET to prevent local and remote file inclusion attacks.
            [$xml, LIBXML_NONET | LIBXML_DTDATTR | defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0]
        );
    }
1234368
function decodeXML( $xmlString )
    {
        $dom = new DOMDocument( '1.0', 'utf-8' );
        $success = $dom->loadXML( $xmlString );

        if ( $success )
        {
            $authors = $dom->getElementsByTagName( 'author' );
            foreach ( $authors as $author )
            {
                $this->addAuthor( $author->getAttribute( "id" ), $author->getAttribute( "name" ), $author->getAttribute( "email" ) );
            }
        }
    }
1315789
public static function convertFromXMLString($root_element, $xml)
    {
        $doc = new DOMDocument('1.0', 'utf-8');
        $doc->loadXML($xml);

        return self::convertFromDOMDocument($root_element, $doc);
    }
524365
public function asDom(): \DOMDocument
    {
        $doc = new \DOMDocument();
        $doc->loadXML($this->writer->outputMemory());
        return $doc;
    }
1312591
public function getXML(\DOMDocument $document)
    {
        $xml = $document->createElement('ns2:DataStorageItem');

        $ccData = $this->creditCardData->getXML($document);
        $dataId = $document->createElement('ns2:HostedDataID');
        $dataId->textContent = $this->hostedDataId;

        if ($this->function != null) {
            $function = $document->createElement('ns2:Function');
            $function->textContent = $this->function;
            $xml->appendChild($function);
        }
        if ($this->declineHostedDataDuplicates != null) {
            $declineDuplicates = $document->createElement('ns2:DeclineHostedDataDuplicates');
            $declineDuplicates->textContent = $this->declineHostedDataDuplicates;
            $xml->appendChild($declineDuplicates);
        }

        $xml->appendChild($ccData);
        $xml->appendChild($dataId);

        return $xml;
    }