Magento 2 has a lot of XSD to define XML structures like config or routers.
Here is a tool which convert XSD to a sample XML, usefull to visualize the structure of the file.

Go to : http://xsd2xml.com/

We will take this XSD :
/lib/internal/Magento/Framework/App/etc/routes.xsd

Here is it’s content :

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * This schema should be applied for validation of separate router.xml files
 *
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="config">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="router" minOccurs="1" maxOccurs="unbounded">
                    <xs:annotation>
                        <xs:documentation>
                            Router collects routes, parses request and performs matching of request to route.
                        </xs:documentation>
                    </xs:annotation>
                    <xs:complexType>
                        <xs:sequence>
                            <xs:choice>
                                <xs:element name="route" minOccurs="1" maxOccurs="unbounded" type="routeType">
                                    <xs:unique name="uniqueModuleName">
                                        <xs:annotation>
                                            <xs:documentation>Module name should be unique for route</xs:documentation>
                                        </xs:annotation>
                                        <xs:selector xpath="module" />
                                        <xs:field xpath="@name" />
                                    </xs:unique>
                                </xs:element>
                            </xs:choice>
                        </xs:sequence>
                        <xs:attribute name="id" use="required" type="routerIdType" />
                    </xs:complexType>
                    <xs:unique name="uniqueRouteId">
                        <xs:annotation>
                            <xs:documentation>Route id should be unique</xs:documentation>
                        </xs:annotation>
                        <xs:selector xpath="route" />
                        <xs:field xpath="@id" />
                    </xs:unique>
                    <xs:unique name="uniqueRouteFrontName">
                        <xs:annotation>
                            <xs:documentation>Route front name should be unique</xs:documentation>
                        </xs:annotation>
                        <xs:selector xpath="route" />
                        <xs:field xpath="@frontName" />
                    </xs:unique>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
        <xs:unique name="uniqueRouterId">
            <xs:annotation>
                <xs:documentation>Router id should be unique in file</xs:documentation>
            </xs:annotation>
            <xs:selector xpath="router" />
            <xs:field xpath="@id" />
        </xs:unique>
    </xs:element>

    <xs:simpleType name="routerIdType">
        <xs:annotation>
            <xs:documentation>
                Unique router identifier.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Za-z0-9\-_]{3,}" />
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="routeType">
        <xs:annotation>
            <xs:documentation>
                Route declares requests to process with desired priority and points a module to perform it.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:choice>
                <xs:element name="module" minOccurs="1" maxOccurs="unbounded" type="moduleType" />
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="id" use="required" type="routeIdType" />
        <xs:attribute name="frontName" use="optional" type="routeFrontNameType" />
    </xs:complexType>

    <xs:simpleType name="routeIdType">
        <xs:annotation>
            <xs:documentation>
                Unique route identifier.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Za-z0-9_]{3,}" />
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="moduleType">
        <xs:annotation>
            <xs:documentation>
                Module is subscribed to process request with corresponding route front name.
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="name" use="required" type="moduleNameType" />
        <xs:attribute name="before" use="optional" type="beforeAfterType" />
        <xs:attribute name="after" use="optional" type="beforeAfterType" />
    </xs:complexType>

    <xs:simpleType name="moduleNameType">
        <xs:annotation>
            <xs:documentation>
                Module name. For example, Magento_User.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Za-z0-9_]{3,}" />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="beforeAfterType">
        <xs:annotation>
            <xs:documentation>
                Attributes "before" and "after" help you to  specify a priority of routes matching.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Za-z0-9_]{3,}" />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="routeFrontNameType">
        <xs:annotation>
            <xs:documentation>
                URL part associated with route.
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
            <xs:pattern value="[A-Za-z0-9_\-]{3,}" />
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

And the generated XML :

<?xml version="1.0" encoding="utf-8"?>
<config>
  <router id="str1234">
    <route id="str1234" frontName="str1234">
      <module name="str1234" before="str1234" after="str1234" />
    </route>
  </router>
</config>
Generate sample XML from XSD
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *

We use cookies to ensure that we give you the best experience on our website.
Ok