1

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="Smile\ElasticsuiteCore\Block\Search\Form\Autocomplete" 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="Magento\Framework\View\Element\Template" 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.

1 Answer 1

0

XML files follow a precise specification. This specification is defined in a dtd file.

This error says that the xsi:type is not allowed for the tag type argument.

So probably all you want is just removing the xsi:type and it will work

Your xml file that you provided in not complete, but it has to define a dtd configuration that give you all the available rules of the xml...digging into this should give you the reason of why xsi:type is not working.

If I dig into my vendor files I find this:

<xs:element name="argument" type="argumentType" minOccurs="1" maxOccurs="unbounded">
    <xs:key name="argumentConfigurableObjectName">
        <xs:selector xpath="argument"/>
        <xs:field xpath="@name"/>
    </xs:key>
</xs:element>

This seems to say that the argument should only have a path field and no type field.

On the other hand i see almost all files using xsi:type so...there might have something else playing there that is escaping my understanding...sorry for not being much more useful.

4
  • Which link is broken?
    – Alex
    Mar 6, 2023 at 16:16
  • @Alex None actually; probably just a github disruption of the service when i've been checking last time. It works now :)
    – Claims
    Mar 6, 2023 at 16:26
  • 2
    A quick argument name="[a-zA-Z0-9]+" xsi:type="array" search in one of my Magento projects gives 100+ results, so you would think giving the argument a type is valid, right? :/
    – bdbdbd
    Mar 20, 2023 at 11:55
  • 1
    It seems that the way Magento extracts the XML string looses the namespace definition making simple xml throw a warning
    – Alex
    Mar 24, 2023 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.