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

Warning: DOMDocument::loadXML(): Start tag expected, '&lt;' not found in Entity

我们从 .xml 文件导入产品

要正确导入产品,我们首先必须创建一个 .xsl 文件,将 .xml 文件转换为我们从 link URL.

的要求

Link 到 .xml 文件看起来像: https://www.importfilexml.de/restful/export/api/products.xml?acceptedlocales=en_US&output-filetype=xml

当我用标签粘贴 link 时,例如 select 一个品牌: https://www.importfilexml.de/restful/export/api/products.xml?acceptedlocales=en_US&output-filetype=xml&tag_1=Love+Moschino

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

Then during validate convert from .xsl to .xml I get issue:
Warning: DOMDocument::loadXML(): Start tag expected, '&lt;' not found in Entity, line: 1 in /home/usr/domains/mywebsite.pl/public_html/vendor/firebear/importexport/Model/Output/Xslt.php on line 34

代码文件 .xslt.php:

    /**
     * @param $file
     * @param $xsl
     * @return string
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function convert($file, $xsl)
    {
        if (!class_exists('\XSLTProcessor')) {
            throw new LocalizedException(__(
                'The XSLTProcessor class could not be found. This means your PHP installation is missing XSL features.'
            ));
        }
        $xmlDoc = new \DOMDocument();

        $xmlDoc->loadXML($file, LIBXML_COMPACT | LIBXML_PARSEHUGE | LIBXML_NOWARNING);

        $xslDoc = new \DOMDocument();
        $xslDoc->loadXML($xsl, LIBXML_COMPACT | LIBXML_PARSEHUGE | LIBXML_NOWARNING);

        $proc = new \XSLTProcessor();
        $proc->registerPHPFunctions();
        $proc->importStylesheet($xslDoc);
        try {
            $newDom = $proc->transformToDoc($xmlDoc);
        } catch (\Exception $e) {
            throw new LocalizedException(__("Error : " . $e->getMessage()));
        }

        return $newDom->saveXML();
    }
}

.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Items>
    <product>
        <sku>CPW88FXXCD_002_L34_32</sku>
        <group>106003</group>
        <product_from_website>brand</product_from_website>
        <url_key>panasonic-Trousers-Men-MW0MW02349-grey-32</url_key>
        <name>panasonic Trousers Men MW0MW02349 grey</name>
        <custom_name>panasonic Trousers Men</custom_name>
        <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° 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>
        <qty>3</qty>
        <price>88.50</price>
        <special_price>44.50</special_price>
        <weight />
        <color>grey</color>
        <gender />
        <ean>8719255365841</ean>
        <brand>panasonic</brand>
        <length />
        <size>32</size>
        <categories>Clothing/Trousers/Men</categories>
        <product_online>1</product_online>
        <group>106003</group>
        <product_websites>base</product_websites>
        <attribute_set_code>Default</attribute_set_code>
        <product_type>simple</product_type>
        <image>https://www.importwebsite.com/prod/stock_product_image_106003_2086033795.jpg</image>
        <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>
    </product>

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

您得到的错误建议您使用 loadXML 但不要传入 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 调用更改为 PHP 代码中的 load 调用。