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:----UcZasCK4lfgy1HhO3RUnOJ8fpCtqq5fLFXc/NRGhgCk4SSD0DmgzTACd8QXdYSoynr8UYWGceTJdB+Yd4esjsPIGhLAcs81jHHy38ivKNAq/43amvM9g/ny2MxWJfwzEH1QVqeHTVxBjDpFk0rBMD9Zx/5W8OwcWRaKiX5NqELSbXX7BaJzcXyT6SidGJlBucMOEldRpm1etnwGbxQhsDCOOeYQkdcKMBEzM7wvsTWcLQg31rY4k+f+PNmBf2HbJyJHo84CVW3w2K+ndNs91+Vc/fnrEjCb2l4Sa2BsU+w0DPC5SCcsD6r8VpJmUN27y3KN+ref8c6/RciQBegCxTmqWTL13nLnNH1gJo3APE3x+/Cz5piV95ywFhxfFqfC1hPhTSwUx7PCnba44M+5CTZeuv0g+HwsT4ATkLddTtAccJpMrbDyhi9dNmpPgVevwDRyGdPU1S2n+XBAmsUOEGMCeofkC1DpGbW9OUSveSDr489ZiRfEDkk2kzPxtg0FPOL/mKCMlBnQhkSl9a1wVAcshFIIqgi/DW8gvLpXCUG2CZCWnglCOAIGqn4QHSPEPEXjY3tqqTBS8RvrK6MzR/rNxxFPj6hpNygy8ohhNozjSDOGyL7eVpbAqynyg5udjBg/nbw+gmOazJfIfrqSJPSeKwl0LTbc5kyNd7ChSs+k=----ATTACHMENT:----Mjg0OTYzMTA5NTk1NzkzNiAzNjExNjIzMzcyODMzMzE4IDMzMjA1ODk1MDQ4MjAyODk=