4

As we all know that Magento 2 uses XSD schema files to validate the contents of all module configuration files.

But at that point, I have one question in my mind. How does Magento validate XSD schema?

Is this validated by w3.org ? And, if yes, then what happens when w3.org server goes down ?

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Magento_Customer" setup_version="2.0.7">
        <sequence>
            <module name="Magento_Eav"/>
            <module name="Magento_Directory"/>
        </sequence>
    </module>
</config>
3

taken from here

Note: The namespace URI is not used by the parser to look up information.

The purpose of using an URI is to give the namespace a unique name.

However, companies often use the namespace as a pointer to a web page containing namespace information.

So I guess you are safe. If www.w3.org goes offline, your magento will still work.

3

No Magento 2 does not use w3 to validate XML over XSD schema.

The framework validates the config files when it reads the XML file.

The code is located under Magento\Framework\Config\Reader\Filesystem in the _readFiles method:

    if ($this->validationState->isValidationRequired()) {
        $errors = [];
        if ($configMerger && !$configMerger->validate($this->_schemaFile, $errors)) {
            $message = "Invalid Document \n";
            throw new \Magento\Framework\Exception\LocalizedException(
                new \Magento\Framework\Phrase($message . implode("\n", $errors))
            );
        }
    }

And the validate method is located in Magento\Framework\Config\Dom :

public function validate($schemaFileName, &$errors = [])
{
    if ($this->validationState->isValidationRequired()) {
        $errors = $this->validateDomDocument($this->dom, $schemaFileName, $this->errorFormat);
        return !count($errors);
    }
    return true;
}

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.