@param string $xml_string

@return null|\SimpleXMLElement
@throws \Exception
350336
public static function xmlToObject($xml_string)
    {
        if (empty($xml_string)) {
            return null;
        }

        libxml_use_internal_errors(true);
        try {
            if (false === $xml = simplexml_load_string($xml_string)) {
                throw new \Exception("Invalid XML Data: ");
            }
            // check for namespace
            $namespaces = $xml->getNamespaces();
            if (0 === $xml->count() && !empty($namespaces)) {
                $perNamespace = [];
                foreach ($namespaces as $prefix => $uri) {
                    if (false === $nsXml = simplexml_load_string($xml_string, null, 0, $prefix, true)) {
                        throw new \Exception("Invalid XML Namespace ($prefix) Data: ");
                    }
                    $perNamespace[$prefix] = $nsXml;
                }
                if (1 === count($perNamespace)) {
                    return current($perNamespace);
                }

                return $perNamespace;
            }

            return $xml;
        } catch (\Exception $ex) {
            $xmlstr = explode("\n", $xml_string);
            $errstr = "[INVALIDREQUEST]: Invalid XML Data: ";
            foreach (libxml_get_errors() as $error) {
                $errstr .= static::displayXmlError($error, $xmlstr) . "\n";
            }
            libxml_clear_errors();
            throw new \Exception($errstr);
        }
    }
578270
def get_element_by_xpath(self, xpath_str, namespaces=None):
        
        try:
            return self._root_el.findall('.' + xpath_str, namespaces)
        except (ValueError, xml.etree.ElementTree.ParseError) as e:
            raise SimpleXMLWrapperException(
                'XPath select raised exception. xpath_str="{}" error="{}"'.format(
                    xpath_str, str(e)
                )
            )
238334
@Override
	public Document parseXML(String string) {
		try {
			return loadXML(new ByteArrayInputStream(string.getBytes("UTF-8")));
		} catch (UnsupportedEncodingException e) {
			throw new BugError("JVM with missing support for UTF-8.");
		}
	}
1315490
private function parseXml($xml)
    {
        $priorSetting = libxml_use_internal_errors(true);
        try {
            libxml_clear_errors();
            $xmlPayload = new \SimpleXMLElement($xml);
            if ($error = libxml_get_last_error()) {
                throw new \RuntimeException($error->message);
            }
        } catch (\Exception $e) {
            throw new ParserException("Error parsing XML: {$e->getMessage()}", 0, $e);
        } finally {
            libxml_use_internal_errors($priorSetting);
        }

        return $xmlPayload;
    }
573366
@Pure
	public static Document parseXML(String xmlString) {
		assert xmlString != null : AssertMessages.notNullParameter(0);
		try {
			return readXML(new StringReader(xmlString));
		} catch (Exception e) {
			//
		}
		return null;
	}
1186693
public function formatXmlString($xmlString)
    {
        if(true === $this->isXml($xmlString))
        {
            $dom = new \DOMDocument;
            $dom->preserveWhiteSpace = false;
            $dom->loadXML($xmlString);
            $dom->formatOutput = true;

            return $dom->saveXml();
        }
        else
        {
            throw new InvalidArgumentException('Incorrect XML string');
        }
    }
695361
public function parseXml($xmlString)
    {
        Validate::notNull($xmlString, 'xmlString');
        Validate::isString($xmlString, 'xmlString');
        $atomLinkXml = simplexml_load_string($xmlString);
        $attributes = $atomLinkXml->attributes();

        if (!empty($attributes['href'])) {
            $this->href = (string) $attributes['href'];
        }

        if (!empty($attributes['rel'])) {
            $this->rel = (string) $attributes['rel'];
        }

        if (!empty($attributes['type'])) {
            $this->type = (string) $attributes['type'];
        }

        if (!empty($attributes['hreflang'])) {
            $this->hreflang = (string) $attributes['hreflang'];
        }

        if (!empty($attributes['title'])) {
            $this->title = (string) $attributes['title'];
        }

        if (!empty($attributes['length'])) {
            $this->length = (int) $attributes['length'];
        }

        $undefinedContent = (string) $atomLinkXml;
        if (empty($undefinedContent)) {
            $this->undefinedContent = null;
        } else {
            $this->undefinedContent = (string) $atomLinkXml;
        }
    }
629181
public function parseXml($xmlString)
    {
        Validate::notNull($xmlString, 'xmlString');
        Validate::isString($xmlString, 'xmlString');

        $this->fromXml(simplexml_load_string($xmlString));
    }
936504
public function parseXml($xmlString)
    {
        $feedXml = simplexml_load_string($xmlString);
        $attributes = $feedXml->attributes();
        $feedArray = (array) $feedXml;
        if (!empty($attributes)) {
            $this->attributes = (array) $attributes;
        }

        if (array_key_exists('author', $feedArray)) {
            $this->author = $this->processAuthorNode($feedArray);
        }

        if (array_key_exists('entry', $feedArray)) {
            $this->entry = $this->processEntryNode($feedArray);
        }

        if (array_key_exists('category', $feedArray)) {
            $this->category = $this->processCategoryNode($feedArray);
        }

        if (array_key_exists('contributor', $feedArray)) {
            $this->contributor = $this->processContributorNode($feedArray);
        }

        if (array_key_exists('generator', $feedArray)) {
            $generator = new Generator();
            $generatorValue = $feedArray['generator'];
            if (is_string($generatorValue)) {
                $generator->setText($generatorValue);
            } else {
                $generator->parseXml($generatorValue->asXML());
            }

            $this->generator = $generator;
        }

        if (array_key_exists('icon', $feedArray)) {
            $this->icon = (string) $feedArray['icon'];
        }

        if (array_key_exists('id', $feedArray)) {
            $this->id = (string) $feedArray['id'];
        }

        if (array_key_exists('link', $feedArray)) {
            $this->link = $this->processLinkNode($feedArray);
        }

        if (array_key_exists('logo', $feedArray)) {
            $this->logo = (string) $feedArray['logo'];
        }

        if (array_key_exists('rights', $feedArray)) {
            $this->rights = (string) $feedArray['rights'];
        }

        if (array_key_exists('subtitle', $feedArray)) {
            $this->subtitle = (string) $feedArray['subtitle'];
        }

        if (array_key_exists('title', $feedArray)) {
            $this->title = (string) $feedArray['title'];
        }

        if (array_key_exists('updated', $feedArray)) {
            $this->updated = \DateTime::createFromFormat(
                \DateTime::ATOM,
                (string) $feedArray['updated']
            );
        }
    }
230751
protected function _arrayToXml($array_o, &$xml)
    {
        foreach ($array_o as $key => $value) {
            if (is_array($value)) {
                if (!is_numeric($key)) {
                    $subnode = $xml->addChild("$key");
                    $this->_arrayToXml($value, $subnode);
                } else {
                    $subnode = $xml->addChild("item$key");
                    $this->_arrayToXml($value, $subnode);
                }
            } else {
                $xml->addChild("$key", htmlspecialchars("$value"));
            }
        }
    }
1061440
public function loadXML($xml_data)
    {
        $this->xml_data = $xml_data;
        $this->xml = new \sasco\LibreDTE\XML();
        if (!$this->xml->loadXML($this->xml_data)) {
            return false;
        }
        $this->toArray();
        return $this->xml;
    }
1142842
public function trimXmlString($xmlString)
    {
        $xmlString = preg_replace('/[\r\n]+(?![^(]*\))/', '', $xmlString);
        $xmlString = preg_replace('/[\s]{2,}/', ' ', $xmlString);
        $xmlString = str_replace(["\r\n", "\n"], '', $xmlString);

        return trim($xmlString);
    }
21147
public function parse( $name, $string )
	{
		$root	= new XML_DOM_Node( $name );

		$string	= self::unfoldString( $string );
		$lines = explode( self::$lineBreak, $string );

		while( count( $lines ) )
		{
			$line	= array_shift( $lines );
			$parsed	= self::parseLine( $line );
			if( $parsed['name'] == "BEGIN" )
				self::parseRecursive( $parsed['value'], $root, $lines );
		}
		return $root;
	}
1299985
protected function processReport($xmlString)
    {
        $xml = simplexml_load_string($xmlString);

        if ($xml === false) {
            $this->phpci->log($xmlString);
            throw new \Exception('Could not process PHPMD report XML.');
        }

        $warnings = 0;

        foreach ($xml->file as $file) {
            $fileName = (string)$file['name'];
            $fileName = str_replace($this->phpci->buildPath, '', $fileName);

            foreach ($file->violation as $violation) {
                $warnings++;

                $this->build->reportError(
                    $this->phpci,
                    'php_mess_detector',
                    (string)$violation,
                    PHPCI\Model\BuildError::SEVERITY_HIGH,
                    $fileName,
                    (int)$violation['beginline'],
                    (int)$violation['endline']
                );
            }
        }

        return $warnings;
    }
1054177
public function parseXml($xmlString)
    {
        $personXml = simplexml_load_string($xmlString);
        $personArray = (array) $personXml;

        if (array_key_exists('name', $personArray)) {
            $this->name = (string) $personArray['name'];
        }

        if (array_key_exists('uri', $personArray)) {
            $this->uri = (string) $personArray['uri'];
        }

        if (array_key_exists('email', $personArray)) {
            $this->email = (string) $personArray['email'];
        }
    }
66557
public function parseAddress($xmlString)
    {
        $previousValue = libxml_use_internal_errors(true);
        $xml = simplexml_load_string($xmlString);
        libxml_use_internal_errors($previousValue);

        if ($xml === false) {
            $message = $this->getXmlErrorMessage();
            throw new InvalidArgumentException('Failed to parse supplied XML string: ' . $message);
        }

        return $this->parseSubjectAddress($xml);
    }
549906
public function fromXmlString($xmlstring)
    {
        try {
            libxml_use_internal_errors(true);
            $xmlDoc = new SimpleXMLElement($xmlstring);
        } catch (\Exception $e) {
            throw new InvalidXmlException('XML string could not be parsed');
        }

        return $this->fromXml($xmlDoc);
    }