警告:DOMDocument::loadXML():需要开始标记,“<” 在实体中找不到

Syl*_*ter 2 php xml xslt converters

我们从 .xml 文件导入产品

\n\n

为了正确导入产品,我们首先必须创建一个 .xsl 文件,该文件将 .xml 文件从链接 URL 转换为我们的要求。

\n\n

.xml 文件的链接如下所示:\n https://www.importfilexml.de/restful/export/api/products.xml?acceptedlocales=en_US&output-filetype=xml

\n\n

当我粘贴带有标签的链接时,例如选择一个品牌:\n https://www.importfilexml.de/restful/export/api/products.xml?acceptedlocales=en_US&output-filetype=xml&tag_1=Love+Moschino

\n\n

然后工作正确。但是当我将链接粘贴到完整产品目录时:\n https://www.importfilexml.de/restful/export/api/products.xml?acceptedlocales=en_US&output-filetype=xml

\n\n
Then during validate convert from .xsl to .xml I get issue:\nWarning: DOMDocument::loadXML(): Start tag expected, \'<\' not found in Entity, line: 1 in /home/usr/domains/mywebsite.pl/public_html/vendor/firebear/importexport/Model/Output/Xslt.php on line 34\n
Run Code Online (Sandbox Code Playgroud)\n\n

代码文件.xslt.php:

\n\n
    /**\n     * @param $file\n     * @param $xsl\n     * @return string\n     * @throws \\Magento\\Framework\\Exception\\LocalizedException\n     */\n    public function convert($file, $xsl)\n    {\n        if (!class_exists(\'\\XSLTProcessor\')) {\n            throw new LocalizedException(__(\n                \'The XSLTProcessor class could not be found. This means your PHP installation is missing XSL features.\'\n            ));\n        }\n        $xmlDoc = new \\DOMDocument();\n\n        $xmlDoc->loadXML($file, LIBXML_COMPACT | LIBXML_PARSEHUGE | LIBXML_NOWARNING);\n\n        $xslDoc = new \\DOMDocument();\n        $xslDoc->loadXML($xsl, LIBXML_COMPACT | LIBXML_PARSEHUGE | LIBXML_NOWARNING);\n\n        $proc = new \\XSLTProcessor();\n        $proc->registerPHPFunctions();\n        $proc->importStylesheet($xslDoc);\n        try {\n            $newDom = $proc->transformToDoc($xmlDoc);\n        } catch (\\Exception $e) {\n            throw new LocalizedException(__("Error : " . $e->getMessage()));\n        }\n\n        return $newDom->saveXML();\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

.xml:

\n\n
<?xml version="1.0" encoding="UTF-8"?>\n<Items>\n    <product>\n        <sku>CPW88FXXCD_002_L34_32</sku>\n        <group>106003</group>\n        <product_from_website>brand</product_from_website>\n        <url_key>panasonic-Trousers-Men-MW0MW02349-grey-32</url_key>\n        <name>panasonic Trousers Men MW0MW02349 grey</name>\n        <custom_name>panasonic Trousers Men</custom_name>\n        <description>&lt;div class=\'pdbDescContainer\'&gt;&lt;div class=\'pdbDescSection\'&gt;&lt;span class=\'pdbDescSectionTitle\'&gt;Collection:&lt;/span&gt;&lt;span class=\'pdbDescSectionText\'&gt;Spring/Summer&lt;/span&gt;&lt;/div&gt;&lt;div class=\'pdbDescSection\'&gt;&lt;span class=\'pdbDescSectionTitle\'&gt;Gender:&lt;/span&gt;&lt;span class=\'pdbDescSectionText\'&gt;Man&lt;/span&gt;&lt;/div&gt;&lt;div class=\'pdbDescSection\'&gt;&lt;span class=\'pdbDescSectionTitle\'&gt;Type:&lt;/span&gt;&lt;span class=\'pdbDescSectionText\'&gt;Trousers&lt;/span&gt;&lt;/div&gt;&lt;div class=\'pdbDescSection\'&gt;&lt;span class=\'pdbDescSectionTitle\'&gt;Fastening:&lt;/span&gt;&lt;span class=\'pdbDescSectionText\'&gt;&lt;span class=\'pdbDescSectionList\'&gt;&lt;span class=\'pdbDescSectionItem\'&gt;buttons&lt;/span&gt;&lt;span class=\'pdbDescSectionItem\'&gt;zip&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=\'pdbDescSection\'&gt;&lt;span class=\'pdbDescSectionTitle\'&gt;Pockets:&lt;/span&gt;&lt;span class=\'pdbDescSectionText\'&gt;4&lt;/span&gt;&lt;/div&gt;&lt;div class=\'pdbDescSection\'&gt;&lt;span class=\'pdbDescSectionTitle\'&gt;Material:&lt;/span&gt;&lt;span class=\'pdbDescSectionText\'&gt;&lt;span class=\'pdbDescSectionList\'&gt;&lt;span class=\'pdbDescSectionItem\'&gt;cotton 96%&lt;/span&gt;&lt;span class=\'pdbDescSectionItem\'&gt;elastane 4%&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=\'pdbDescSection\'&gt;&lt;span class=\'pdbDescSectionTitle\'&gt;Pattern:&lt;/span&gt;&lt;span class=\'pdbDescSectionText\'&gt;checkered&lt;/span&gt;&lt;/div&gt;&lt;div class=\'pdbDescSection\'&gt;&lt;span class=\'pdbDescSectionTitle\'&gt;Washing:&lt;/span&gt;&lt;span class=\'pdbDescSectionText\'&gt;&lt;span class=\'pdbDescSectionList\'&gt;&lt;span class=\'pdbDescSectionItem\'&gt;wash at 30\xc2\xb0 C&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=\'pdbDescSection\'&gt;&lt;span class=\'pdbDescSectionTitle\'&gt;Model height, cm:&lt;/span&gt;&lt;span class=\'pdbDescSectionText\'&gt;185&lt;/span&gt;&lt;/div&gt;&lt;div class=\'pdbDescSection\'&gt;&lt;span class=\'pdbDescSectionTitle\'&gt;Model wears a size:&lt;/span&gt;&lt;span class=\'pdbDescSectionText\'&gt;32&lt;/span&gt;&lt;/div&gt;&lt;div class=\'pdbDescSection\'&gt;&lt;span class=\'pdbDescSectionTitle\'&gt;Details:&lt;/span&gt;&lt;span class=\'pdbDescSectionText\'&gt;&lt;span class=\'pdbDescSectionList\'&gt;&lt;span class=\'pdbDescSectionItem\'&gt;visible logo&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description>\n        <qty>3</qty>\n        <price>88.50</price>\n        <special_price>44.50</special_price>\n        <weight />\n        <color>grey</color>\n        <gender />\n        <ean>8719255365841</ean>\n        <brand>panasonic</brand>\n        <length />\n        <size>32</size>\n        <categories>Clothing/Trousers/Men</categories>\n        <product_online>1</product_online>\n        <group>106003</group>\n        <product_websites>base</product_websites>\n        <attribute_set_code>Default</attribute_set_code>\n        <product_type>simple</product_type>\n        <image>https://www.importwebsite.com/prod/stock_product_image_106003_2086033795.jpg</image>\n        <additional_images>https://www.importwebsite.com/prod/stock_product_image_106003_2086033795.jpg,https://www.importwebsite.com/prod/stock_product_image_106003_343223477.jpg,https://www.importwebsite.com/prod/stock_product_image_106003_287457799.jpg,https://www.importwebsite.com/prod/stock_product_image_106003_570760537.jpg</additional_images>\n    </product>\n
Run Code Online (Sandbox Code Playgroud)\n

Mar*_*nen 6

我认为错误不在 XSLT 中,而只是在您使用 PHP DOMDocument API 时,它有两种方法,一种称为“load如果您有要加载的 XML 或 XSLT 的文件名、文件路径或 URI,则应该使用” ,loadXML如果您有一个包含要解析的 XML 或 XSLT 代码的字符串,则应该使用另一个调用。

您收到的错误建议您使用loadXMLXML 或 XSLT 代码,但不要传入 XML 或 XSLT 代码,而是使用 XML 或 XSLT 代码的文件名、路径或 URI。为此,您应该使用该load方法。

请参阅http://sandbox.onlinephpfunctions.com/code/f080d3aedcc93d591018902724b7846eb063d36b,它演示了$doc->loadXML('foo.xml')生成错误DOMDocument::loadXML(): Start tag expected, '&lt;' not found in Entity,同时$doc->loadXML('<root>test</root>');可以正常工作。因此,将您的loadXML调用更改为loadPHP 代码中的调用。