Magento 2 custom xml schema validation

The question:

This is a follow up of Magento 2 xml validation:
I understood how to map xsi:noNamespaceSchemaLocation in my IDE so I will get real time validation of my xmls.
But what if I have to create my own config file with it’s own validation schema?
What value should I put for xsi:noNamespaceSchemaLocation ?

Right now I have this in class.xml:

<?xml version="1.0"?>
<classes xmlns:xsi="" xsi:noNamespaceSchemaLocation="class.xsd">

This works nicely, because class.xsd is in the same folder as my class.xml.
But I plan to make my module extensible and actually composed from multiple modules.
Now I use in the additional modules a relative path to the class.xsd file and this seams a bit wrong.

<?xml version="1.0"?>
<classes xmlns:xsi="" xsi:noNamespaceSchemaLocation="../../../Base/etc/umc/class.xsd">

Obviously I cannot use urn:magento:framework... because my module is not in the framework, and I also cannot use urn:magento:module... because mine is not a core module. Or can I use the latter?
Or should I use a custom urn?
And (last one) if I use a custom urn will this be picked up automatically by the command bin/magento dev:urn-catalog:generate or should I dos something special?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

It should be urn:magento:module:<Vendor_Module>:<path>
The command will work since it filters out urns that begin with urn:magento

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment