【发布时间】:2020-07-16 21:51:59
【问题描述】:
我们从 .xml 文件导入产品
为了正确导入产品,我们首先必须创建一个 .xsl 文件,它将 .xml 文件从链接 URL 转换为我们的要求。
.xml 文件的链接如下所示: https://www.importfilexml.de/restful/export/api/products.xml?acceptedlocales=en_US&output-filetype=xml
当我粘贴带有标签的链接时,例如选择一个品牌: https://www.importfilexml.de/restful/export/api/products.xml?acceptedlocales=en_US&output-filetype=xml&tag_1=Love+Moschino
然后正确工作。但是当我将链接粘贴到完整的产品目录时: 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>
【问题讨论】:
-
那么你将
$file和/或$xsl传递给loadXML是什么?带有 XML 或 XSLT 代码的字符串?还是文件名/路径?使用load方法,而不是loadXML方法。或者向我们展示一个最小但完整的示例来重现错误,即使用参数调用convert。 -
如果我们从加载中删除 XML 则不可能打开链接,因为产品只能每 20m 导入一次。现在我遇到问题:警告:DOMDocument::load(): I/O 警告:无法加载外部实体 "/home/user/domains/domain.com/public_html/pub/您最多允许每次完全导出20 分钟,最多每分钟一个差异请求在 /home/user/domains/gerris.com/public_html/vendor/firebear/importexport/Model/Output/Xslt.php 第 34 行
-
这是 PHP 吗?请标记调用 XSLT 的通用语言。此外,您的任何链接都不起作用。请将 XML 和 XSLT 示例发布到帖子正文中。
-
@Parfait 根据您的建议,我添加了 .xsl 文件代码和生成的 .xml 文件
-
那么你作为
$file和$xsl传递给convert函数的参数是什么,这些字符串是带有XML代码和XSLT代码的吗?
标签: php xml xslt converters