1

Is there a way to resolve any xml-file that causes an error?

I cannot find the source file that causes this error (happens on checkout):

Magento\Framework\Config\Dom\ValidationException): Element 'item', attribute 'after': The attribute 'after' is not allowed.
Line: 1439

default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>

    <!-- Removing / Moving -->
    <referenceBlock name="advanced-search-link" remove="true" />
    <referenceBlock name="register-link" remove="true" />
    <referenceBlock name="catalog.compare.link" remove="true" />
    <referenceBlock name="header" remove="true" />
    <referenceBlock name="wish-list-link" remove="true" />

    <move element="minicart" destination="header-wrapper" after="-" />
    <move element="form.subscribe" destination="footer" after="footer.copyright" />


    <!--minicart popup-->


    <referenceContainer name="header-wrapper">
        <container name="header.socialmedia.container" before="logo">
            <block class="Magento\Framework\View\Element\Template" template="Magento_Theme::html/header/socialmedia.phtml" name="header.socialmedia" />
        </container>
    </referenceContainer>

    <referenceBlock name="top.links">
        <block class="Magento\Framework\View\Element\Html\Link\Current" name="header.retailer-link">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">Become Retailer</argument>
                <argument name="path" xsi:type="string">retailer</argument>
            </arguments>
        </block>
        <block class="Magento\Framework\View\Element\Template" template="Magento_Theme::html/header/accountmenu.phtml" name="header.accountmenu" />
    </referenceBlock>


     <!-- Footer -->
    <referenceBlock name="footer_links" remove="true" />
    <referenceBlock name="copyright" remove="true" />
    <referenceBlock name="report.bugs" remove="true" />

    <referenceContainer name="footer">
        <block class="Magento\Framework\View\Element\Template" template="Magento_Theme::html/footer/logo.phtml" name="footer.logo" />
        <block class="Magento\Framework\View\Element\Template" template="Magento_Theme::html/footer/menublocks.phtml" name="footer.menublocks" />
        <block class="Magento\Framework\View\Element\Template" template="Magento_Theme::html/footer/copyright.phtml" name="footer.copyright" />
    </referenceContainer>


    <!-- Removing stuff -->
    <referenceContainer name="sidebar.main">
        <!-- <referenceBlock name="catalogsearch.leftnav" remove="true"/> -->
        <!-- <referenceBlock name="catalog.leftnav" remove="true"/> -->
        <referenceBlock name="catalog.compare.sidebar" remove="true"/>
        <referenceBlock name="wishlist_sidebar" remove="true"/>
        <referenceBlock name="sale.reorder.sidebar" remove="true" />
    </referenceContainer>
</body>

checkout_cart_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>

    <move element="cart.summary" destination="main.content" after="-" />
    <move element="checkout.cart.coupon" destination="main.content" before="checkout.cart.crosssell"/>
    <move element="checkout.cart.crosssell" destination="main.content" after="-" />

    <referenceContainer name="page.wrapper" htmlClass="page-wrapper cart">
    </referenceContainer>

    <referenceContainer name="content">



    </referenceContainer>
    <referenceBlock name="checkout.cart.shipping">
        <arguments>
            <argument name="jsLayout" xsi:type="array">
                <item name="components" xsi:type="array">
                    <item name="block-summary" xsi:type="array">

                        <!-- My custom part: -->
                        <item name="config" xsi:type="array">
                            <item name="componentDisabled" xsi:type="boolean">true</item>
                        </item>

                    </item>
                </item>
            </argument>
        </arguments>
    </referenceBlock>
</body>

checkout_index_index.xml contains no xml changes

  • please share your default.xml code from theme level Magento_Theme. – Rakesh Jesadiya May 24 '18 at 9:21
  • @RakeshJesadiya see updated answer. My error happens on checkout page btw – Bram May 24 '18 at 9:30
  • please share your xml file from checkout module/theme which contains after atttribute – Rakesh Jesadiya May 24 '18 at 9:31
  • @RakeshJesadiya updated answer – Bram May 24 '18 at 9:33
  • @Bram error looks like you have added after attributes in referenceContainer somewhere. Please check it may issue. – Nikunj Vadariya May 24 '18 at 9:53
2

I think the answer is no. :( If you trying to debug the Magento\Framework\Config\Dom class you can see that all data has stored in the memory as a one big file, which leads to unknown place (in my case there was a root directory /var/www/html):

example

So here are some tips:

  1. Try to determine the error location by indirect signs: what modules was setted up before the error comes, which file has %1 node and %2 attribute etc.
  2. Try to search in your project files by keywords %1 and %2 in the xml files.

%1 - 'item'
%2 - 'after'

  1. If you are using the PhpStorm IDE (or similar) you can add the magento .xsd schemas in the settings to enable auto-validation during development:

schemas

As a result you able to see highlighted errors if some of a .xml files has invalid attributes:

result

  1. Good similar tool which does that automatically (for the PhpStorm) is PhpStorm Magento 2 Plugin

How to add the `.xsd` mapping manually in the PhpStorm

Go to the Preferences > Languages & Frameworks > Schemas and DTDs click on the + sign, in the URI field add the xsd path (from the corresponding xml file, could be found as an attribute xsi:noNamespaceSchemaLocation of the root config node in almost each magento xml file:

where schema could be found in xml

then find corresponding schema location from a project schema list:

project schema list

Click OK.


How to use *PhpStorm* code inspector to validate project xml-files

It's pretty simple:

  • Right-click on the project root directory inspect code menu
  • Select Inspect Code...
  • Click on the ... button near Inspection Profile select menu button in the inspection profile
  • In opened window click on the Gear symbol on the right of the profile name and select Duplicate inspection profile settings
  • Type a name, something like XML inspection, uncheck all checkboxes except the XML one (you can use the eraser button on the top of list)
  • Click OK to save the profile (window closing)
  • Click OK to start check
  • Analise the result :) Example of code inspection by XML
  • Ah thanks for the tips! I use phpstorm (editing files remotely, so I need to have it locally first before I can do this). So the xsd validation will go over your whole project? – Bram May 24 '18 at 9:40
  • @Bram yes, it will validate each file where schema exists – Siarhey Uchukhlebau May 24 '18 at 9:42
  • Hi, @SiarheyUchukhlebau, Please explain how to apply this? – kunj May 24 '18 at 10:50
  • @kunj Hi, what exactly you wish to apply? – Siarhey Uchukhlebau May 24 '18 at 10:50
  • How did you add those .xsd in Phpstorm? – kunj May 24 '18 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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