警告:DOMDocument::loadXML():需要开始标记,在实体中找不到“<”
Warning: DOMDocument::loadXML(): Start tag expected, '<' 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, '<' 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><div class='pdbDescContainer'><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Collection:</span><span class='pdbDescSectionText'>Spring/Summer</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Gender:</span><span class='pdbDescSectionText'>Man</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Type:</span><span class='pdbDescSectionText'>Trousers</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Fastening:</span><span class='pdbDescSectionText'><span class='pdbDescSectionList'><span class='pdbDescSectionItem'>buttons</span><span class='pdbDescSectionItem'>zip</span></span></span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Pockets:</span><span class='pdbDescSectionText'>4</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Material:</span><span class='pdbDescSectionText'><span class='pdbDescSectionList'><span class='pdbDescSectionItem'>cotton 96%</span><span class='pdbDescSectionItem'>elastane 4%</span></span></span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Pattern:</span><span class='pdbDescSectionText'>checkered</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Washing:</span><span class='pdbDescSectionText'><span class='pdbDescSectionList'><span class='pdbDescSectionItem'>wash at 30° C</span></span></span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Model height, cm:</span><span class='pdbDescSectionText'>185</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Model wears a size:</span><span class='pdbDescSectionText'>32</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Details:</span><span class='pdbDescSectionText'><span class='pdbDescSectionList'><span class='pdbDescSectionItem'>visible logo</span></span></span></div></div></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, '<' not found in Entity
而 $doc->loadXML('<root>test</root>');
可以正常工作。因此,将 loadXML
调用更改为 PHP 代码中的 load
调用。
我们从 .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, '<' 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><div class='pdbDescContainer'><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Collection:</span><span class='pdbDescSectionText'>Spring/Summer</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Gender:</span><span class='pdbDescSectionText'>Man</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Type:</span><span class='pdbDescSectionText'>Trousers</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Fastening:</span><span class='pdbDescSectionText'><span class='pdbDescSectionList'><span class='pdbDescSectionItem'>buttons</span><span class='pdbDescSectionItem'>zip</span></span></span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Pockets:</span><span class='pdbDescSectionText'>4</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Material:</span><span class='pdbDescSectionText'><span class='pdbDescSectionList'><span class='pdbDescSectionItem'>cotton 96%</span><span class='pdbDescSectionItem'>elastane 4%</span></span></span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Pattern:</span><span class='pdbDescSectionText'>checkered</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Washing:</span><span class='pdbDescSectionText'><span class='pdbDescSectionList'><span class='pdbDescSectionItem'>wash at 30° C</span></span></span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Model height, cm:</span><span class='pdbDescSectionText'>185</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Model wears a size:</span><span class='pdbDescSectionText'>32</span></div><div class='pdbDescSection'><span class='pdbDescSectionTitle'>Details:</span><span class='pdbDescSectionText'><span class='pdbDescSectionList'><span class='pdbDescSectionItem'>visible logo</span></span></span></div></div></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, '<' not found in Entity
而 $doc->loadXML('<root>test</root>');
可以正常工作。因此,将 loadXML
调用更改为 PHP 代码中的 load
调用。