11

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

  • 1
    Banging my head against the wall... – tjons Nov 26 '16 at 1:06
  • the way to "debug" those really is to use the provided xsd's (also it this means to use phpstorm) or just trial and error. You could maybe write an own xsd checking script – David Verholen Dec 23 '16 at 0:32
4

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.

  • Thanks. I read introduction about xsd support on devdocs which says right now only the phpstorm are supported (because of its unique namespace stlye ?). Due to phpstorm consumes too much memory on my fedora desktop, I resolve to gvim which i am used to. Though i upgrade to vim 8, the xml xsd still doesn't support mage2' way. – robertshare Dec 3 '16 at 15:44
  • 1
    use bin/magento dev:urn:generate .idea/misc.xml to generate xsd mapping for PHPStorm. It will be able to resolve all urn paths from xmls. – Sergey Ivashchenko Dec 23 '16 at 9:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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