XML Schema Resolution in PHP Storm with URNs (Quick Note)

In a recent Magento 2 code drop into the develop branch on GitHub, support was added for allowing Composer installed modules to stay in the ‘vendor’ directory rather than be copied to ‘app/code’. This however caused problems with XSD references in XML files that used relative paths, as the module could be in different directories at different times. To overcome this problem, new URNs have been introduced for referencing XML Schema declarations. These need to be configured in PHP Storm in order for schema validation to work again. This note is a quick note describing how to do these steps. (Official documentation is coming really soon.)

Some examples of XSD URIs that have changed:

  • “../../../../../lib/internal/Magento/Framework/Config/etc/theme.xsd” can now be replaced with “urn:magento:framework:Config/etc/theme.xsd”.
  • “../../../../../Magento/Webapi/etc/webapi.xsd” can now be replaced with “urn:magento:module:Magento_Webapi:etc/webapi.xsd”.

The new URNs no longer care about the path relative to the other module (which gets messed up when you have some modules under ‘vendor’ and some locally developed modules still under ‘app/code’). Relative paths still work, but are not recommended any more.

If you are using PHP Storm however, it by default does not know how to resolve URNs. The URN resolution code is built into Magento directly. Luckily, it’s pretty easy to associate URNs with real files in your local site.

This is what you will see after loading up the new code. Notice the URN is in red because PHP Storm does not know how to resolve it.


Put the cursor in the URN then click on the red light bulb to the left that will appear and select “Manually Setup External Resource” from the list.


Scroll down the list of XSD files that PHP Storm has automatically located, and select the appropriate file. The red URN will now be shown in green, and XML validation is back in effect.


You could go out on a hunt and destroy mission to find all such references in advance – personally I plan to just register URNs incrementally if I start editing a file with a red URN in it. If you are not editing a file, having the URN not be resolved is not really a problem in PHP Storm.

Oct 30, 2015: Stop the presses!  I just did a git pull and noticed a new CLI command “dev:urn-catalog:generate”. (Okay, you can see Eugene pointed it out in comments below!)  You should probably save your current .idea/misc.xml file, but I just ran the following command from my project root directory

bin/magento dev:urn-catalog:generate .idea/misc.xml

I then restarted PHP Storm, and all the URNs started resolving! Cool bananas! (It took a little while to run, but it found all the schema files and worked out URNs for them all – well all the ones I found so far.)


  1. I created an experimental script to make adding the urn to file mapping a bit faster for phpstorm.
    Still needs a bit quality work, but may help some people already.

    Thought it makes sense to link it here🙂

    1. Flyingmana · · Reply

      seems Iam not allowed to post an url here <.<


      1. Great idea! We pushed it forward and generated a URN catalog for PhpStorm. Can you please take a look? http://magento.stackexchange.com/questions/88242/magento-2-xml-validation/88413#88413

      2. Replied to your comment below.

  2. Great idea! We moved it forward and generate complete URN catalog in the PhpStorm format. Can you please take a look? http://magento.stackexchange.com/questions/88242/magento-2-xml-validation/88413#88413

    Also would be helpful to add generation for other IDEs.

  3. Just install https://plugins.jetbrains.com/plugin/8024 go to plugin settings and click “Regenerate urn map” button.
    For feature requests/additional information please refer to https://github.com/dkvashninbay/magento2plugin

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: