Convert XML string to object

@param $fileContents

@return \SimpleXMLElement
346752
private function xmlToObj($fileContents)
  {
    $fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
    $fileContents = trim(str_replace('"', "'", $fileContents));
    $simpleXml    = simplexml_load_string($fileContents, null, LIBXML_NOCDATA);

    return $simpleXml;
  }
1017261
private function parseFileToDOM($file)
    {
        try {
            $dom = XmlUtils::loadFile($file, array($this, 'validateSchema'));
        } catch (\InvalidArgumentException $e) {
            throw new InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e);
        }

        $this->validateExtensions($dom, $file);

        return $dom;
    }
590598
public static function fromContents(string $contents): self
    {
        $handle = fopen('php://memory', 'r+');
        fwrite($handle, $contents);
        rewind($handle);
        return new static($handle);
    }
905845
public function xml()
    {
        foreach ($this->_filecontent as $machine) {
            $xmlmach = $this->xml->addChild("Machine");
            $xmlmach->addAttribute("Name", $machine[0]);
            $xmlmach->addAttribute("State", $machine[1]);
        }

        return $this->xml->getSimpleXmlElement();
    }
497931
public function parseAnnotations($fileContents)
    {
        $ret = array();
        if (preg_match('/^#\s*@(\w+)[:=]?\s+([\'"])?(.*)\2\s*$/m', $fileContents, $m)) {
            $ret[$m[1]] = $m[3];
        }
        return $ret;
    }
921323
public function buildBodyXml($contents)
    {
        $this->contextDataType   = self::CONTENT_TYPE_XML;
        $this->contextDataExists = (bool) (strlen($contents) > 0);
        $this->contextDataValue  = simplexml_load_string($contents);

        if ($this->contextDataValue === false) {
            $this->contextDataEmpty   = true;
            $this->contextDataValue   = null;
            $this->contextDecodeError = array();

            foreach (libxml_get_errors() as $error) {
                $this->contextDecodeError[] = array('code' => $error->$code, 'message' => $error->message);
            }
        }
        else {
            $this->contextDataValue = \SwaggerValidator\Common\Collection::jsonEncode($this->getDataValue());

            if (json_last_error() !== JSON_ERROR_NONE) {
                $this->contextDataEmpty = true;
                $this->contextDataValue = null;
                if (function_exists('json_last_error_msg')) {
                    $this->contextDecodeError[] = array('code' => json_last_error(), 'message' => json_last_error_msg());
                }
                else {
                    $this->contextDecodeError[] = array('code' => json_last_error(), 'message' => null);
                }
            }
            else {
                $this->contextDataValue = json_decode($this->getDataValue(), false);

                if (json_last_error() !== JSON_ERROR_NONE) {
                    $this->contextDataEmpty = true;
                    $this->contextDataValue = null;
                    if (function_exists('json_last_error_msg')) {
                        $this->contextDecodeError[] = array('code' => json_last_error(), 'message' => json_last_error_msg());
                    }
                    else {
                        $this->contextDecodeError[] = array('code' => json_last_error(), 'message' => null);
                    }
                }
                else {
                    $this->checkDataIsEmpty();
                }
            }
        }
    }
240175
private function getFileContents($files)
	{
		$content = '';
		$basePath = $this->basePath;

		array_walk($files,function(&$value, $key) use(&$content, $basePath){
			if(file_exists($basePath.$value))
			$content .= file_get_contents($basePath.$value);
		});
		return $content;
	}
571375
public function setContentLanguages($contentLanguages)
    {
        $fileVersion = $this->getFileVersion();

        foreach ($contentLanguages as $locale) {
            $contentLanguage = new FileVersionContentLanguage();
            $contentLanguage->setFileVersion($fileVersion);
            $contentLanguage->setLocale($locale);
            if (!$fileVersion->getContentLanguages()->contains($contentLanguage)) {
                $fileVersion->addContentLanguage($contentLanguage);
            }
        }

        return $this;
    }
338106
public function FromXML($xml)
	{
		$sxo = new SimpleXMLElement($xml);
		
		if($sxo->encoding == "base64")
		{
			$this->Data = base64_decode($sxo->data);
		}
		else
		{
			$this->Data = $sxo->data;
		}
		
		$this->Name = $attachment->name;
		$this->Type = $attachment->type;
		$this->Size = $attachment->size;
		$this->Extension = $attachment->extension;
	}
216155
function objectAttributeContent( $contentObjectAttribute )
    {
        $xmlText = $contentObjectAttribute->attribute( 'data_text' );
        if ( trim( $xmlText ) == '' )
        {
            $objectAttributeContent = $this->defaultObjectAttributeContent();
            return $objectAttributeContent;
        }
        $doc = $this->parseXML( $xmlText );
        $content = $this->createObjectContentStructure( $doc );

        return $content;
    }
1222396
public static function getMediaTypeFromFileContent(string $fileContent): string
    {
        $fileInfo = new \finfo(FILEINFO_MIME);
        $mediaType = self::trimMediaType($fileInfo->buffer($fileContent));
        return isset(self::$mediaTypeToFileExtension[$mediaType]) ? $mediaType : 'application/octet-stream';
    }
1182859
public static function fromFile(string $file) : DOMDocument
    {
        if (!is_file($file)) {
            throw new InvalidArgumentException(sprintf('Path "%s" is not a file', $file));
        }

        if (!is_readable($file)) {
            throw new InvalidArgumentException(sprintf('File "%s" is not readable', $file));
        }

        // libxml_disable_entity_loader(true) disables \DOMDocument::load() method
        // so we need to read the content and use \DOMDocument::loadXML()
        $xml = file_get_contents($file);
        if ($xml === false) {
            throw new RuntimeException(sprintf(
                'Contents of readable file "%s" could not be gotten',
                $file
            ));
        }

        if (trim($xml) === '') {
            throw new RuntimeException(sprintf('File "%s" does not have content', $file));
        }

        return static::fromString($xml);
    }
476918
private function loadXml($file)
    {
        $internal = libxml_use_internal_errors(true);

        $doc = new DOMDocument();
        $doc->preserveWhiteSpace = false;
        $doc->validateOnParse = true;

        if (!@$doc->load($file)) {
            $errors = libxml_get_errors();

            libxml_use_internal_errors($internal);

            throw XmlException::createUsingErrors($errors);
        }

        libxml_use_internal_errors($internal);

        return new DOMXPath($doc);
    }
676700
private static function _arr2xml($data, $content = '')
    {
        foreach ($data as $key => $val) {
            is_numeric($key) && $key = 'item';
            $content .= "<{$key}>";
            if (is_array($val) || is_object($val)) {
                $content .= self::_arr2xml($val);
            } elseif (is_string($val)) {
                $content .= '<![CDATA[' . preg_replace("/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]/", '', $val) . ']]>';
            } else {
                $content .= $val;
            }
            $content .= "</{$key}>";
        }
        return $content;
    }
813961
protected function loadXmlFile(string $xmlFile): SimpleXMLElement
    {
        $xmlContent = (new FileReader($xmlFile))->read();
        $xml = simplexml_load_string($xmlContent);

        if (!($xml instanceof SimpleXMLElement)) {
            $message = "Error loading XML file: $xmlFile";
            $this->log($message, Project::MSG_ERR);
            throw new BuildException($message);
        }

        return $xml;
    }
427146
public function toContent($contents, $format, $options = array())
	{
		if (!($contents instanceof Registry))
		{
			$contents = new Registry($contents);
		}

		return $contents->toString($format, $options);
	}
418543
public static function createFromInline($fileContents)
    {
        // '//# sourceMappingURL=data:application/json;charset:utf-8;base64,
        // '//# sourceMappingURL=data:application/json;base64,'
        $pos = strrpos($fileContents, "\n//# sourceMappingURL=");
        $isCss = false;
        if ($pos === false) {
            $pos = strrpos($fileContents, "\n/*# sourceMappingURL=");
            if ($pos === false) {
                throw new Exception("No sourceMappingURL found");
            }
            $isCss = true;
        }
        $url = substr($fileContents, $pos + 22);
        $url = rtrim($url);
        if ($isCss) {
            if (substr($url, -2) != '*/') {
                throw new Exception("sourceMappingURL isn't wrapped with closing */");
            }
            $url = substr($url, 0, -2); //remove "*/"
            $url = rtrim($url);
        }

        if (substr($url, 0, 29) == 'data:application/json;base64,') {
            $map = substr($url, 29);
        } else if (substr($url, 0, 29 + 14) == 'data:application/json;charset:utf-8;base64,') {
            $map = substr($url, 29 + 14);
        } else if (substr($url, 0, 29 + 14) == 'data:application/json;charset=utf-8;base64,') {
            $map = substr($url, 29 + 14);
        } else {
            throw new Exception("Unsupported sourceMappingURL");
        }
        $map = base64_decode($map);
        $map = json_decode($map);
        $fileContents = substr($fileContents, 0, $pos);
        $ret = new self($map, $fileContents);
        $ret->setMimeType($isCss ? 'text/css' : 'text/javascript');
        return $ret;
    }