Load XML from a string.

@param string   $xml     The XML string
@param int|null $options Additional parameters

@return \DiDom\Document

@throws \InvalidArgumentException if the provided argument is not a string
424779
public function loadXml($xml, $options = null)
    {
        return $this->load($xml, false, Document::TYPE_XML, $options);
    }
648585
public function load(string $str, array $options = []): Dom
    {
        AbstractNode::resetCount();
        // check if it's a file
        if (strpos($str, "\n") === false && is_file($str)) {
            return $this->loadFromFile($str, $options);
        }
        // check if it's a url
        if (preg_match("/^https?:\/\//i", $str)) {
            return $this->loadFromUrl($str, $options);
        }

        return $this->loadStr($str, $options);
    }
1180344
public function loadXMLString(string $xmlString): DOMDocument
    {
        $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) {
            throw new InvalidXmlException('$xmlString', libxml_get_errors());
        }

        return $document;
    }
1093879
public static function fromXml(\DOMElement $xml)
    {
        $static = new static();
        $static->libraryItemMetadata = LibraryItemMetadata::fromXml($xml);
        $static->pickupLocation = PickupLocation::fromXml($xml);

        $requestStartDate = $xml->getElementsByTagName('requestDate');
        $requestEndDate = $xml->getElementsByTagName('endRequestDate');
        $static->requestDateRange = DateTimeRange::fromXml($requestStartDate, $requestEndDate);

        $holdStartDate = $xml->getElementsByTagName('holdDate');
        $holdEndDate = $xml->getElementsByTagName('endHoldDate');
        $static->holdDateRange = DateTimeRange::fromXml($holdStartDate, $holdEndDate);

        $cancelable = $xml->getElementsByTagName('cancelable');
        $static->cancelable = BoolLiteral::fromXml($cancelable);

        $stringLiterals = array(
            'requestNumber' => $xml->getElementsByTagName('requestNumber'),
            'sequence' => $xml->getElementsByTagName('sequence'),
            'queuePosition' => $xml->getElementsByTagName('queuePosition'),
            'itemSequence' => $xml->getElementsByTagName('itemSequence'),
            'status' => $xml->getElementsByTagName('status'),
        );
        foreach ($stringLiterals as $propertyName => $xmlTag) {
            $static->$propertyName = StringLiteral::fromXml($xmlTag);
        }

        return $static;
    }
735193
protected function __parseXmlToUpdateObject($xml)
  {
    $dom = new DOMDocument();

    // Attempt to prevent XXE that could be exploited through loadXML()
    libxml_disable_entity_loader(true);

    if (empty($xml) || !$dom->loadXML($xml, LIBXML_NOBLANKS)) return null;

    $rootNode = $dom->documentElement;

    if ($rootNode->nodeName == $this->getNodeName()) {
      // update the current object
      Recurly_Resource::__parseXmlToObject($rootNode->firstChild, $this, $this->_client);
    } else if ($rootNode->nodeName == 'errors') {
      // add element to existing object
      Recurly_Resource::__parseXmlToObject($rootNode->firstChild, $this->_errors, $this->_client);
    }
    $this->updateErrorAttributes();
  }
116644
private function loadFromExtensions(\DOMDocument $xml)
    {
        foreach ($xml->documentElement->childNodes as $node) {
            if (!$node instanceof \DOMElement || self::NS === $node->namespaceURI) {
                continue;
            }

            $values = static::convertDomElementToArray($node);
            if (!is_array($values)) {
                $values = array();
            }

            $this->container->loadFromExtension($node->namespaceURI, $values);
        }
    }
1374159
public function softParse(
        string $xml,
        string $className = null,
        int $options = null,
        string $ns = null,
        bool $isPrefix = null
    ): array {
        \assert('$options === null || $options >= 0');
        $before = libxml_use_internal_errors();
        libxml_use_internal_errors(true);
        libxml_clear_errors();
        $content = simplexml_load_string(
            $xml,
            $className ?? $this->className,
            $options ?? $this->options,
            $ns ?? $this->namespace,
            $isPrefix ?? $this->isPrefix
        );
        $error = $this->getError($xml);
        libxml_use_internal_errors($before);
        return [$content, $error];
    }
1039055
public static function fromXml(\DOMNodeList $xml)
    {
        $items = array();
        foreach ($xml as $xmlTag) {
            $items[] = Hold::fromXml($xmlTag);
        }
        return new static($items);
    }
792826
public static function decode($xml)
	{
		$p = xml_parser_create();

		xml_parser_set_option($p, self::XML_OPTION_CASE_FOLDING, 0);
		xml_parser_set_option($p, self::XML_OPTION_SKIP_WHITE, 1);
		xml_parse_into_struct($p, $xml, $vals, $index);
		xml_parser_free($p);

		$count = count($vals);

		$stack = array();

		$obj = null;

		for ($i = 0; $i < $count; $i++)
		{
			$v = $vals[$i];

			if ($v['type'] == 'open')
			{
				if ($v['attributes']['type'] == 'object')
				{
					if (is_null($obj))
					{
						array_push($stack, array(null,$obj));
					}
					else if (is_array($obj) || is_object($obj))
					{
						array_push($stack, array($v['tag'],$obj));
					}
					else
					{
						if ($fatal)
						{
							die('invalid container');
						}
						else
						{
							return false;
						}
					}

					$obj = new \stdClass();
				}
				else if ($v['attributes']['type'] == 'array')
				{
					if (is_null($obj))
					{
						array_push($stack, array(null,$obj));
					}
					else if (is_array($obj) || is_object($obj))
					{
						array_push($stack, array($v['tag'],$obj));
					}
					else
					{
						die('invalid container');
					}

					$obj = array();
				}
				else
				{
					die('invalid element');
				}
			}
			else if ($v['type'] == 'complete')
			{
				if ($v['attributes']['type'] == 'string')
				{
					$value = $v['value'];
				}
				else if ($v['attributes']['type'] == 'boolean')
				{
					$value = $v['value'] == 'true';
				}
				else if ($v['attributes']['type'] == 'number')
				{
					$value = $v['value'];

					if (!is_numeric($value))
					{
						die('invalid numeric value');
					}

					$value = $value + 0; // converts to type int or float as required
				}
				else if ($v['attributes']['type'] == 'null')
				{
					$value = null;
				}
				else if ($v['attributes']['type'] == 'array')
				{
					$value = array();
				}
				else if ($v['attributes']['type'] == 'object')
				{
					$value = new \stdClass();
				}
				else
				{
					die('invalid value type');
				}

				if (is_null($obj))
				{
					$obj = $value;
				}
				else if (is_array($obj))
				{
					$obj[] = $value;
				}
				else if (is_object($obj))
				{
					if (isset($v['attributes']['item']))
					{
						$obj->{$v['attributes']['item']} = $value;
					}
					else
					{
						$obj->{$v['tag']} = $value;
					}
				}
				else
				{
					die('invalid container 2');
				}
			}
			else if ($v['type'] == 'close')
			{
				$prev = array_pop($stack);

				if (is_object($prev[1]))
				{
					$prev[1]->{$prev[0]} = $obj;
				}
				else if (is_array($prev[1]))
				{
					$prev[1][$prev[0]] = $obj;
				}
				else if (is_null($prev[1]))
				{
					break;
				}
				else
				{
					die('invalid container in stack');
				}

				$obj = $prev[1];
			}
			else
			{
				die('unknown parse part');
			}

		}

		self::last_error(self::XML_ERROR_NONE);

		return $obj;
	}
359742
public static function fromXml(\DOMElement $xml)
    {
        $static = new static();

        $locationId = $xml->getElementsByTagName('pickupLocation');
        $static->locationId = StringLiteral::fromXml($locationId);

        $text = $xml->getElementsByTagName('pickupLocationText');
        $static->text = StringLiteral::fromXml($text);

        return $static;
    }
1273253
public function fromXml(string $xml): array
    {
        if (!$this->isEmptyValue($xml)) {

            libxml_use_internal_errors(true);

            // convert string to xml object
            $result = simplexml_load_string("$xml", 'SimpleXMLElement', LIBXML_NOCDATA);

            if ($result) {
                return $this->fromClass($result);

            } else {

                foreach (libxml_get_errors() as $error) {

                    // if don`t have container add that`s
                    if ($error->code == 5) {
                        $this->errors = [];

                        // append container and parse again
                        return $this->fromXml("<DATA>$xml</DATA>");

                    } else
                        $this->setError($error->code, $error->message);
                }
            }
        }

        return $this->result;
    }
662355
public function load($file, array $options = [])
    {
        if ($this->getDefault($options, self::SIMPLEXML, false)) {
            return $this->loadSimpleXml($file, $options);
        }

        return $this->loadDom($file, $options);
    }
1281710
protected function generateXMLObject($xml)
    {
        try {
            libxml_use_internal_errors(true);
            return new SimpleXMLElement($xml, LIBXML_NOCDATA);
        } catch (\Exception $e) {
            return false;
        }
    }
934499
public function createResponseFromXml($xml)
    {
        $dom = new \DomDocument($xml);
        if (!$dom->loadXML($xml)) {
            return;
        }

        $data = array();

        foreach($dom->childNodes as $root) {
            if ($root->nodeType !== XML_ELEMENT_NODE) {
                continue;
            }
            foreach($root->childNodes as $node) {
                $name = $node->nodeName;
                $text = $node->textContent;
                $data[$name] = $text;
            }
        }

        return new Response($data);
    }
1334063
private function createDomDocument($xml)
    {
        $domDocument = new \DOMDocument();
        if ($domDocument->loadXML($xml) === false) {
            throw new ParseException("Could not parse xml input");
        }
        return $domDocument;
    }
400598
public function saveXML(\DOMNode $node = null, $options = null)
    {
        $xml = parent::saveXML($node, $options);
        $xml = $this->fixEntities($xml);
        return $xml;
    }
900334
public static function createStringWalkerParser($file, $options = array())
    {
        $stream = new Stream\File($file, 16384);
        $parser = new Parser\StringWalker($options);
        return new XmlStringStreamer($parser, $stream);
    }