警告:DOMDocument :: loadXML():起始标签应为'& lt;'。在实体中找不到 [英] Warning: DOMDocument::loadXML(): Start tag expected, '<' not found in Entity

查看:108
本文介绍了警告:DOMDocument :: loadXML():起始标签应为'& lt;'。在实体中找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们从.xml文件导入产品



要正确导入产品,我们首先必须创建一个.xsl文件,该文件会将.xml文件转换为我们的要求



到.xml文件的链接如下:
https://www.importfilexml.de/restful/export/api/products.xml?acceptedlocales=zh_CN&output-filetype = xml



当我粘贴带有标签的链接时,示例选择一个品牌:
https://www.importfilexml.de/restful/export/api /products.xml?acceptedlocales=zh_CN&output-filetype=xml&tag_1=Love+Moschino



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

 然后在验证期间从.xsl转换为.xml,我得到问题:
警告:DOMDocument :: loadXML():预期的开始标记为& lt;在Entity中找不到,第34行


代码文件.xslt.php:

  / * * 
* @param $ file
* @param $ xsl
* @返回字符串
* @throws \Magento\Framework\Exception\LocalizedException
* /
公共函数convert($ file,$ xsl)
{
if(!class_exists('\XSLTProcessor')){
throw new LocalizedExc eption(__(
’找不到XSLTProcessor类。这意味着您的PHP安装缺少XSL功能。’
));
}
$ 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>品牌< / product_from_website>
< url_key> panasonic-Trousers-Men-MW0MW02349-grey-32< / url_key>
< name> panasonic裤子男士MW0MW02349灰色< / name>
< custom_name>松下长裤男装< / custom_name>
< description>& lt; div class ='pdbDescContainer'& lt; div class ='pdbDescSection'& lt; span class ='pdbDescSectionTitle'& gt;集合:< / span>& lt; span class ='pdbDescSectionText'> Spring / Summer< / span>< / div& gt;& lt; div class ='pdbDescSection'& lt; span class ='pdbDescSectionTitle'& lt; Gender:< / span& lt; span class ='pdbDescSectionText'> Man& < / span& gt;& lt; / div& gt;& lt; div class ='pdbDescSection'& lt; span class ='pdbDescSectionTitle'& lt; Type:& lt; / span& lt; span class ='pdbDescSectionText'>长裤< / span& gt& lt // div& gt;& lt; div class ='pdbDescSection'& gt ;& lt; span class ='pdbDescSectionTitle'& gt;固定:< / span& gt;& lt; span class ='pdbDescSectionText'& lt; span class ='pdbDescSectionList' & lt; span class ='pdbDescSectionItem'& gt;按钮& lt; / sp一个& lt; span class ='pdbDescSectionItem'& gt; zip& lt / span& gt;& lt; / span& lt; / span& gt;& lt // div& lt; div class ='pdbDescSection'& lt; span class ='pdbDescSectionTitle'&Pockets:< / span& gt;& lt; span class = 'pdbDescSectionText'& gt; 4& lt; / span& gt;& lt; / div& gt;& lt; div class ='pdbDescSection'& lt; span class ='pdbDescSectionTitle'& ; gt;材质:< / span& gt;& lt; span class ='pdbDescSectionText'& lt; span class ='pdbDescSectionList'& lt; span class =' pdbDescSectionItem'& gt;棉96%< / span& gt;& lt; span class ='pdbDescSectionItem'>弹性纤维4%< / span>& lt; / span& ;& lt; / span& gt;& lt; / div& gt;& lt; div class ='pdbDescSection'& lt; span class ='pdbDescSectionTitle'> Pattern :< / span& gt;& lt; span class ='pdbDescSectionText'& lt; / span& lt; / div / div& gt; & lt; div class ='pdbDescSection'& lt; span class ='pdbDescSectionTitle'& lt;洗涤:& lt // span>& lt; span class ='pdbDescSectionText'& >< span class ='pdbDescSectionList'& lt; span class ='pdbDescSectionItem'>< span class ='pdbDescSectionItem'& gt;< / span& gt;< / span& < / span>& lt // div& gt;& lt; div class ='pdbDescSection'& lt; span class ='pdbDescSectionTitle'& gt;模型高度,cm:< / span& lt; span class ='pdbDescSectionText'& 185& lt // span& lt< / div& gt;÷ div class ='pdbDescSection'& lt; span class ='pdbDescSectionTitle'& gt;模型具有以下尺寸:< / span>& lt; span class ='pdbDescSectionText'& gt ; 32< / span>& lt // div& gt;& lt; div class ='pdbDescSection'& lt; span class ='pdbDescSectionTitle'& gt;详细信息:& ; lt / span& gt;& lt; span class ='pdbDescSectionText'& gt;< span class ='pdbDescSectionList' < span class ='pdbDescSectionItem'>可见徽标< / span& gt;< / span>< / span>< / div& lt; / div& lt; / description>
< qty> 3< / qty>
< price> 88.50< / price>
< special_price> 44.50< / special_price>
< weight />
< color>灰色< / color>
<性别/>
< ean> 8719255365841< / ean>
< brand" panasonic< / brand>
< length />
< size> 32< / size>
<类别>服装/长裤/男子< / categories>
< product_online> 1< / product_online>
< group> 106003< / group>
< product_websites> base< / product_websites>
< attribute_set_code>默认值< / attribute_set_code>
< product_type>简单< / 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,则应使用要加载,以及另一个名为 loadXML 的字符串,如果您有要解析的带有XML或XSLT代码的字符串,则应该使用。



您收到的错误提示您使用 loadXML ,但不传递XML或XSLT代码,而是传递XML或XSLT代码的文件名或路径或URI。为此,您应该使用 load 方法。



请参见 http://sandbox.onlinephpfunctions.com/code/f080d3aedcc93d591018902724b7846eb063d36b 这说明了 $ doc-> load。 xml')生成错误 DOMDocument :: loadXML():预期的开始标记,在实体中找不到<& lt; c $ c> $ doc-> loadXML('< root> test< / root>'); 可以正常工作。因此,将您的 loadXML 调用更改为PHP代码中的 load 调用。


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, '&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

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>&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>

解决方案

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, '&lt;' 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.

这篇关于警告:DOMDocument :: loadXML():起始标签应为'&amp; lt;'。在实体中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆