2

I've seen for a while now that inside the arguments tag in di.xml or in the layout files the attribute xsi:type is used.
I took it for granted and used it like that, but I don't understand why the need for the xsi namespace. What does it mean?
The name attribute does not have a namespace.

Here is a random example.

 <arguments>
    <argument name="configurationsMap" xsi:type="array">
        <item name="default_message_identifier" xsi:type="array">
            <item name="renderer" xsi:type="const">\Magento\Framework\View\Element\Message\Renderer\EscapeRenderer::CODE</item>
        </item>
    </argument>
</arguments>

I know what the value of the xsi:type attribute means, but not why the need for the namespace.
This is not impeding my work, but it bugs me a lot.

1 Answer 1

1

Magento dev team wants to use the attribute named type which is deferred from XML Shema Interface. That's why they use xsi:type="blablabla", not type="blablabla". I don't find they declare an attribute named type. So, if you change the xsi:type="blablabla" to type="blablabla", the XML validation will throws an error.

Here is an example of default catalog_product_view.xml XML: catalog_product_view.xml

I have reconstructed the XML Schema Definition based on xsi:noNamespaceSchemaLocation path of the XML itself: page_configuration.xsd

You won't see any definition of type attribute in element named argument. Therefore, if you use <argument type="string">, the XML becomes invalid.

You may try the validation result of those XML and XSD here: W3C XML Schema (XSD) Validation online. Try to change the thing you asked, let's say, <argument xsi:type="string"> to <argument type="string"> and validate the XML, you'll see an error.

2
  • 1
    Thanks for the link. I knew that. But my question is "why is that needed? couldn't just be type and that's it?"
    – Marius
    Commented Feb 3, 2017 at 9:19
  • I have updated the answer and attached an example of page layout XML, and reconstructed the XML Schema Definition of it based on tag ` xsi:noNamespaceSchemaLocation`. Commented Feb 3, 2017 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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