2

If we see and module.xml file or any .xml file there is config tag with some xml code declaration what does it mean? is it required? How it works with Magento 2?

for Ex :

If you see module.xml file we can see

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="..`/../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">`

if we see any modules's default.xml file we can see

<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

Also I have seen register.php file for module and it has something like this

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Mage_Blog',
__DIR__

);

in short there are so many XML related config tag and all have diffrent values as per file so what is the use of that?

And if we create custom module then what and How we can use it?

1

Magento 2 does XML schema validation by .XSD (Magento/Framework/Module/etc/module.xsd).

The extra information provided there specifies the schema instance used and the URN to the corresponding xsd file. In our case we point out that our xml must follow the rules presented in the file: vendor/magento/framework/Module/etc/module.xsd. The URN is a type of URI that is location-independent (unlike the URL).

Remember the days when your module didn’t work and you had to look for hours through xmls to find the typo? Those days should be over now because IDEs (like PhpStorm) can validate instantly your xml against the specified xsd.

In most cases s we have

for module declaration: <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
for routers: <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
for layouts: <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
for DI: <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

We can write custom xml schema validation based on our needs. reference

Hope this Helps.

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.