Sitemap Titelbild

After the (supposedly) successful creation of a sitemap in Magento 2 (CE 2.3.5), a Parse Error was displayed when accessing the sitemap. The error: This page contains the following errors: Entity 'iacute' not defined. Below is a rendering of the page up to the first error. The solution offered here by our web agency or the workaround provided is, of course, not limited to the entity "iacute", i.e. "í", which corresponds to the letter "í", but also applies to umlauts and other special characters such as Trademark (™) or similar.

 

The problem here is that, when creating the sitemap, the special characters are converted into non-numeric HTML entities, meaning: "í" is converted to "í" and not to "í". To change this, we modify (yes, directly in the core, as this has been fixed since Magento CE 2.4 :-)) the file

 

/html/ar.for.econcess.de/vendor/magento/module-sitemap/Model/Sitemap.php

 

and extend it by 3 lines with the htmlspecialchars() instruction. Here, setting the entity compatibility is important (ENT_COMPAT); we specify it here as "ENT_HTML401":

 

From the lines

 

            foreach ($images->getCollection() as $image) {

                $row .= '<image:image>';

                $row .= '<image:loc>' . $this->_escaper->escapeUrl($image->getUrl()) . '</image:loc>';

                $row .= '<image:title>' . $this->_escaper->escapeHtml($images->getTitle()) . '</image:title>';

                if ($image->getCaption()) {

                    $row .= '<image:caption>' . $this->_escaper->escapeHtml($image->getCaption()) . '</image:caption>';

                }

                $row .= '</image:image>';

            }

            // Add PageMap image for Google web search

            $row .= '<PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0"><DataObject type="thumbnail">';

            $row .= '<Attribute name="name" value="' . $this->_escaper->escapeHtml($images->getTitle()) . '"/>';

            $row .= '<Attribute name="src" value="' . $this->_escaper->escapeUrl($images->getThumbnail()) . '"/>';

            $row .= '</DataObject></PageMap>';

 

is then replaced with the following:

 

            foreach ($images->getCollection() as $image) {

                $row .= '<image:image>';

                $row .= '<image:loc>' . $this->_escaper->escapeUrl($image->getUrl()) . '</image:loc>';

                $row .= '<image:title>' . $this->_escaper->escapeHtml(htmlspecialchars($images->getTitle(), ENT_HTML401, 'UTF-8')) . '</image:title>';

                if ($image->getCaption()) {

                    $row .= '<image:caption>' . $this->_escaper->escapeHtml(htmlspecialchars($image->getCaption(), ENT_HTML401, 'UTF-8')) . '</image:caption>';

                }

                $row .= '</image:image>';

            }

            // Add PageMap image for Google web search

            $row .= '<PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0"><DataObject type="thumbnail">';

            $row .= '<Attribute name="name" value="' . $this->_escaper->escapeHtml(htmlspecialchars($images->getTitle(), ENT_HTML401, 'UTF-8')) . '"/>';

            $row .= '<Attribute name="src" value="' . $this->_escaper->escapeUrl($images->getThumbnail()) . '"/>';

            $row .= '</DataObject></PageMap>';

 

This now generates the sitemap without errors. Observed at our web agency in an online shop running Magento 2.3.5.