Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example custom XML configuration files for the Mage2Katas episode 9: The Custom Config File Kata.
<?xml version="1.0"?>
<conversion_map xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Mage2Kata_DiConfig:etc/unit_conversion.xsd">
<unit id="mg" type="weight">
<conversion to="g" factor="0.001000"/>
<conversion to="kg" factor="0.000001"/>
<conversion to="lbs" factor="0.00000220462257811"/>
</unit>
<unit id="g" type="weight">
<conversion to="mg" factor="1000"/>
<conversion to="kg" factor="0.001"/>
<conversion to="lbs" factor="0.00220462257811"/>
</unit>
<unit id="lbs" type="weight">
<conversion to="mg" factor="453592.379"/>
<conversion to="g" factor="453.592379"/>
<conversion to="kg" factor="0.453592379"/>
</unit>
<unit id="kg" type="weight">
<conversion to="mg" factor="1000000"/>
<conversion to="g" factor="1000"/>
<conversion to="lbs" factor="2.20462257811"/>
</unit>
<unit id="ml" type="fluid">
<conversion to="l" factor="0.001"/>
</unit>
<unit id="l" type="fluid">
<conversion to="ml" factor="1000"/>
</unit>
<unit id="mm" type="distance">
<conversion to="cm" factor="0.1"/>
<conversion to="in" factor="0.0393700787402"/>
<conversion to="m" factor="0.001"/>
</unit>
<unit id="cm" type="distance">
<conversion to="mm" factor="10"/>
<conversion to="in" factor="0.393700787402"/>
<conversion to="m" factor="0.01"/>
</unit>
<unit id="in" type="distance">
<conversion to="mm" factor="25.4"/>
<conversion to="cm" factor="2.54"/>
<conversion to="m" factor="0.0254"/>
</unit>
<unit id="m" type="distance">
<conversion to="mm" factor="1000"/>
<conversion to="cm" factor="100"/>
<conversion to="in" factor="39.3700787402"/>
</unit>
</conversion_map>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="conversion_map" type="conversion_mapType">
<xs:unique name="uniqueUnit">
<xs:selector xpath="unit" />
<xs:field xpath="@id" />
</xs:unique>
</xs:element>
<xs:complexType name="conversion_mapType">
<xs:sequence>
<xs:element type="unitType" name="unit" maxOccurs="unbounded" minOccurs="0">
<xs:unique name="uniqueTargetUnit">
<xs:selector xpath="conversion" />
<xs:field xpath="@to" />
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="unitType">
<xs:sequence>
<xs:element type="conversionType" name="conversion" maxOccurs="unbounded" minOccurs="1"/>
</xs:sequence>
<xs:attribute type="unitId" name="id" use="required"/>
<xs:attribute type="measurementType" name="type" use="required"/>
</xs:complexType>
<xs:complexType name="conversionType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="targetUnitType" name="to" use="required"/>
<xs:attribute type="factorType" name="factor" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="unitId">
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]+" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="targetUnitType">
<xs:restriction base="xs:string">
<xs:pattern value="[a-z]+" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="measurementType">
<xs:restriction base="xs:string">
<xs:enumeration value="weight"/>
<xs:enumeration value="fluid"/>
<xs:enumeration value="distance"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="factorType">
<xs:annotation>
<xs:documentation>
Factor to convert base unit to target unit
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:decimal">
<xs:minExclusive value="0"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment