问题
We import products from an .xml file
To import products correctly, we first had to create an .xsl file that would convert the .xml file to our requirements from link URL.
Link to .xml file looks like: https://www.importfilexml.de/restful/export/api/products.xml?acceptedlocales=en_US&output-filetype=xml
When I paste link with tag, example select one brand: https://www.importfilexml.de/restful/export/api/products.xml?acceptedlocales=en_US&output-filetype=xml&tag_1=Love+Moschino
then work correct. But when I paste link to full products catalog: 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
code file .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>
回答1:
I think the error is not in the XSLT but simply in your use of the PHP DOMDocument API, it has two methods, one called load
you should use if you have a file name or file path or URI to the XML or XSLT you want to load, and another called loadXML
you should use if you have a string with XML or XSLT code you want to parse.
The error you get suggests you use loadXML
but don't pass in XML or XSLT code but the file name or path or URI of the XML or XSLT code. For that you should use the load
method.
See http://sandbox.onlinephpfunctions.com/code/f080d3aedcc93d591018902724b7846eb063d36b which demonstrates that $doc->loadXML('foo.xml')
generates the error DOMDocument::loadXML(): Start tag expected, '<' not found in Entity
while $doc->loadXML('<root>test</root>');
would work fine. So change your loadXML
calls to load
calls in the PHP code.
来源:https://stackoverflow.com/questions/61033708/warning-domdocumentloadxml-start-tag-expected-lt-not-found-in-entity