Magento – What’s your way of debugging xml related exceptions

debuggingmagento2PHPxml

I'm coding with Magento 2 in gvim and I am new to Magento 2.

There were many times i struggled to debug xml-related errors, well, each time with only luck.
But situations like this makes me really upset: you don't know where is the file that is causing this error, and the debugger doesn't tell neither .

Take the following I get this: an xml file is invalid. actually I've create a module which has module.xml, routes.xml, config.xml, {layout}.xml, di.xml under it's etc or view/layout dirs.
Which file's line 12/89/.. is invalid ? the generated /merged one ? I am lost because I find nothing in var/generated, and the commandline stops working .
What's the debugging way to find what this error is.?

Any help is appreciated.

Fatal error: Uncaught Magento\Framework\Exception\LocalizedException: Invalid Document Element 'item': The type definition is abstract.
Line: 12 Element 'item', attribute 'name': The XPath '@name' of a field of key identity-constraint 'itemName' evaluates to a node-set with more than one member.
Line: 89 Element 'item': Not all fields of key identity-constraint 'itemName' evaluate to a node. Line: 89 Element 'item', attribute 'name': The XPath '@name' of a field of key identity-constraint 'itemName' evaluates to a node-set with more than one member. Line: 90 Element 'item': Not all fields of key identity-constraint 'itemName' evaluate to a node.
Line: 90 in /var/www/html/lib/internal/Magento/Framework/Config/Reader/Filesystem.php:160
Stack trace: #0 /var/www/html/lib/internal/Magento/Framework/Config/Reader/Filesystem.php(127): Magento\Framework\Config\Reader\Filesystem->_readFiles(Object(Magento\Framework\Config\FileIterator))
#1/var/www/html/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader.php(69): M in /var/www/html/lib/internal/Magento/Framework/Config/Reader/Filesystem.php on line 160

Best Answer

The exception thrown tells you that you're using an element <item /> where your not allowed to use one. So yeah, your problem is probably XML-related.

The first thing I do to make sure I write valid XML is setup my IDE so it can properly map the XSD-schemes. In PhpStorm you can do this by using the helper-thingy left to the xsi-namespace:

set namespace in PhpStorm

When all is set properly, your IDE will setup code completion for you and warn you if you're doing something that is not allowed:

tooltip 1

tooltip 2

I hope this helps you some.

Related Topic