Skip to content

Exception: Namespace prefix xsi for type on argument is not defined in Merge.php / Extra content at the end of the document

We are using justbetter/magento2-sentry for catching errors in our Magento 2.4.5-1 shop and have lots of reports of such errors:

Warning: simplexml_load_string(): namespace error : Namespace prefix xsi for type on argument is not defined

Digging down lead us to Framework/View/Model/Layout/Merge.php where a generic exception is caught:

    private function extractHandlers(): void
    {
        foreach ($this->updates as $update) {
            $updateXml = null;

            try {
                $updateXml = is_string($update) ? $this->_loadXmlString($update) : false;
                // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
            } catch (Exception $exception) {
                // ignore invalid
            }

            if ($updateXml && strtolower($updateXml->getName()) == 'update' && isset($updateXml['handle'])) {
                $this->addHandle((string)$updateXml['handle']);
            }
        }
    }

The error is reported lots of times when the layout cache is flushed.

One example $update looks like this:

<body>
   <referenceContainer name="header-wrapper">
      <block class="SmileElasticsuiteCoreBlockSearchFormAutocomplete" name="top.search" as="topSearch" template="Smile_ElasticsuiteCore::search/form.mini.phtml">
         <arguments>
            <argument name="rendererList" xsi:type="array">
               <item name="term" xsi:type="array">
                  <item name="title" translate="true" xsi:type="string">Search terms</item>
                  <item name="template" xsi:type="string">Smile_ElasticsuiteCore/autocomplete/term</item>
               </item>
            </argument>
         </arguments>
      </block>
   </referenceContainer>
   <referenceContainer name="before.body.end">
      <block class="MagentoFrameworkViewElementTemplate" name="elasticsuite_footer" template="Smile_ElasticsuiteCore::footer.phtml"/>
   </referenceContainer>
</body>

What I see is that the namespace definition is missing here – but this content seems to be originally from the elasticsuite module and all looks good here.

  • Did anybody see this error before?
  • What is wrong with the layout update?

So while this is just an warning, it does throw an exception and it looks to me that the layout update might get ignored? So this might be a more serious problem than just spamming sentry?

I also have other errors in the foreach:

Example XML:

<update handle="default_head_blocks"/>
<body>
   <referenceContainer name="after.body.start">



        </referenceContainer>
   <referenceBlock name="top.links">





        </referenceBlock>
   <referenceContainer name="main.content">





        </referenceContainer>
   <referenceContainer name="header.container">
      <container name="header.panel.wrapper" htmlClass="panel wrapper" htmlTag="div" before="-">
         <container name="header.panel" label="Page Header Panel" htmlTag="div" htmlClass="panel header">
















                </container>
      </container>
      <container name="header-wrapper" label="Page Header" as="header-wrapper" htmlTag="div" htmlClass="header content">

            </container>
   </referenceContainer>
   <referenceContainer name="page.top">
      <container name="top.container" as="topContainer" label="After Page Header Top" htmlTag="div" htmlClass="top-container"/>
   </referenceContainer>
   <referenceContainer name="columns.top">
      <container name="page.messages" htmlTag="div" htmlClass="page messages">


            </container>
   </referenceContainer>
   <referenceContainer name="main">
      <container name="content.top" label="Main Content Top">

            </container>
      <container name="content" label="Main Content Area"/>
      <container name="content.aside" label="Main Content Aside"/>
      <container name="content.bottom" label="Main Content Bottom"/>
   </referenceContainer>
   <referenceContainer name="page.bottom.container">
      <container name="page.bottom" label="Before Page Footer" htmlTag="div" htmlClass="content"/>
   </referenceContainer>
   <referenceContainer name="footer-container">
      <container name="footer" as="footer" label="Page Footer" htmlTag="div" htmlClass="footer content">








            </container>
   </referenceContainer>
   <referenceContainer name="before.body.end">

        </referenceContainer>
   <referenceContainer name="content">

        </referenceContainer>
</body>
<update handle="hyva_default_head_blocks"/>

Error:

Warning: simplexml_load_string(): Entity: line 2: parser error : Extra content at the end of the document in vendor/magento/framework/View/Model/Layout/Merge.php on line 564

I doubt that this Magento core code here ever really worked reliably.

extractHandlers function is probably only for code where the update function is in the first root node. But as soon as there is any additional XML, it might just break and be really hard to debug.

Edit2

As for the sentry part, I openend an issue.