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\nThen 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\nRun 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}\nRun 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><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\xc2\xb0 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>\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>\nRun Code Online (Sandbox Code Playgroud)\n
我认为错误不在 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, '<' not found in Entity,同时$doc->loadXML('<root>test</root>');可以正常工作。因此,将您的loadXML调用更改为loadPHP 代码中的调用。