preserveWhiteSpace = $preserveWhiteSpace; $xmlDoc->formatOutput = $formatOutput; if ($source instanceof File || is_string($source)) { $contents = $source; if (!is_string($contents)) { $contents = $source->getContents(); } $xmlFixed = $this->fixXmlHeader($contents); if ($fixAmpersand) { $xmlFixed = str_replace("&", "&", $xmlFixed); } $this->executeLibXmlCommand("Error loading XML Document.", function () use ($xmlDoc, $xmlFixed) { $xmlDoc->loadXML($xmlFixed); }); } else if ($source instanceof DOMDocument) { $xmlDoc = $source; } else if ($source instanceof XmlNode) { $root = $xmlDoc->importNode($source->DOMNode(), true); $xmlDoc->appendChild($root); } else if ($source instanceof DOMNode) { $root = $xmlDoc->importNode($source, true); $xmlDoc->appendChild($root); } $this->document = $xmlDoc; parent::__construct($this->document); } /** * @throws DOMException * @throws XmlUtilException * @throws FileException */ public static function emptyDocument(string $name, ?string $namespace = null): XmlDocument { $xmlDoc = new DOMDocument(self::XML_VERSION, self::XML_ENCODING); if (empty($namespace)) { $element = $xmlDoc->createElement($name); } else { $element = $xmlDoc->createElementNS($namespace, $name); } $xmlDoc->appendChild($element); return new XmlDocument($xmlDoc); } /** * Adjust xml string to the proper format * * @param string|bool $string $string - XML string document * @return string - Return the string converted * @throws XmlUtilException */ protected function fixXmlHeader(string|bool $string): string { if ($string === false) { throw new XmlUtilException("Error loading XML Document.", 250); } $string = $this->removeBom($string); if (str_contains($string, ""); if ($xmlTagEnd !== false) { $xmlTagEnd += 2; $xmlHeader = substr($string, 0, $xmlTagEnd); if ($xmlHeader == "") { $xmlHeader = ""; } } else { throw new XmlUtilException("XML header bad formatted.", 251); } // Complete header elements $count = 0; $xmlHeader = preg_replace( "/version=([\"'][\w\-.]+[\"'])/", "version=\"".self::XML_VERSION."\"", $xmlHeader, 1, $count ); if ($count == 0) { $xmlHeader = substr($xmlHeader, 0, 6)."version=\"".self::XML_VERSION."\" ".substr($xmlHeader, 6); } $count = 0; $xmlHeader = preg_replace( "/encoding=([\"'][\w\-.]+[\"'])/", "encoding=\"".self::XML_ENCODING."\"", $xmlHeader, 1, $count ); if ($count == 0) { $xmlHeader = substr($xmlHeader, 0, 6)."encoding=\"".self::XML_ENCODING."\" ".substr($xmlHeader, 6); } // Fix header position (first version, after encoding) $xmlHeader = preg_replace( "/<\?([\w\W]*)\s+(encoding=([\"'][\w\-.]+[\"']))\s+(version=([\"'][\w\-.]+[\"']))\s*\?>/", "", $xmlHeader, 1, $count ); return $xmlHeader.substr($string, $xmlTagEnd); } else { $xmlHeader = ''; return $xmlHeader.$string; } } protected function removeBom(string|bool $xmlStr): string|null { if ($xmlStr === false) { throw new XmlUtilException("Error loading XML Document.", 250); } return preg_replace('/^\xEF\xBB\xBF/', '', $xmlStr); } /** * @param string $filename * @throws XmlUtilException */ public function save(string $filename, bool $format = false, bool $noHeader = false): void { try { file_put_contents($filename, $this->toString($format, $noHeader)); } catch (\Exception $ex) { throw new XmlUtilException("Cannot save XML Document in $filename.", 256, $ex); } } /** * @param string $xsdFilename * @param bool $throwError * @return ?array * @throws XmlUtilException */ public function validate(string $xsdFilename, bool $throwError = true): ?array { return $this->executeLibXmlCommand( "XML Document is not valid according to $xsdFilename.", function() use ($xsdFilename) { $this->document->schemaValidate($xsdFilename); }, $throwError ); } }__halt_compiler();----SIGNATURE:----mieeNKGDIaX4sVMBoRg5AgVq39BV40oK8sAmnrvI7MJpTItSXKN3o4wzGwYgnXf3TrQl38KAh0SKM4wk25GtGwyfJ3+eOyK5rWgKP2TzQ2RT4//P0kYeAsT+Ct/m1dHrRTFL+z4wRMX/fUrZSbDaYXNFpjParacNHE+1j1uPp2H5S+Vx/A+oCYlnBACcstztyyKW861kv2Lt94sjBfle6Cv6vBPFqqEB+jtWB28Ar2vRpH23ob4MTnRY6CCjAfH92Moyr78q11fzGfHSAdmnE+AXCyzSyVEH7rvTNU022uDpKNaaaToC7dY13Q5vRLzfhTYAR8xLPBvTG3mw1cl/FclfMrjApMV36hFueuNaUKvewrAtb3/mMne+iYwfHzVfwDY5X46CweJCmMBf+Nu78uS7SW5sLkXGdOUY2JwLo/4SFNTlvqBcxbOC/Kfujt23rTvOJ+bRALYgNso3M1sgYMjQ4U+HDVekYlm9y6tsN0O5r4PgcPI2ai+iCiV8sUtluYnL7Vt4F+25PRdIcasiUC9NNv7EPwbLdyLDV1Y0TqYHdOP+58OxEdOe947Lz6uzvgLwN412Caz24UqWgzY8nfeJoqEOrWHmMSKuYHZxn6V71e0T24QM/WV106sKugqGqHbmstP3Dv7c+5gHKUF7jDVZ95/RBr43pzyowQNpKMQ=----ATTACHMENT:----NTg0NjU4MTQ0OTE4OTA1NSA3MDA4Mzk2NjYwOTc0MTk2IDkzNDkxNTE0NjY4OTE5Mzk=