xmlxsdschemaxmlschemaset

XML file with custom children nodes


I am actually working with Magento 2 framework which implement XSD schema for his configuration files.
I have a file flow.xml where the developer put his an XML mapping and some configurations.
My goal is making two nodes mandatory mapping and options where the developer can write any XML structure he want.

Here are my actual files :

# File flow.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Dnd_Flow:etc/flow.xsd">
    <mapping>
        // Here can be other nodes on X levels (or simply string = bonus) 
    </mapping>
    <options>
        // Here can be other nodes on X levels (or simply string = bonus) 
    </options>
</config>

My XSD file looks like this :

# File flow.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="config" type="configType" />

    <xs:complexType name="configType">
        <xs:sequence>
            <xs:element type="xs:????" name="mapping" minOccurs="0" />
            <xs:element type="xs:????" name="options" minOccurs="0" />
        </xs:sequence>
    </xs:complexType>
</xs:schema>

I tried mixed values, xs:all, differents element types but no result.

This is maybe a piece of cake but I am new at XSD schemas and I am strugguling to find the solution where that there can be everything in my two nodes.

Thank you,
Matthéo.


Solution

  • The type you want is xsd:anyType, which you can get either by name:

    <xs:element type="xs:anyType" name="mapping" minOccurs="0" />
    <xs:element type="xs:anyType" name="options" minOccurs="0" />
    

    or by omitting the type attribute:

    <xs:element name="mapping" minOccurs="0" />
    <xs:element name="options" minOccurs="0" />