带有自定义子节点的XML文件

时间:2016-04-07 12:53:16

标签: xml xsd schema xmlschemaset

我实际上正在使用Magento 2框架,该框架为他的配置文件实现了XSD架构 我有一个文件flow.xml,开发人员在其中提供了XML映射和一些配置 我的目标是使两个节点成为强制mappingoptions,开发人员可以在其中编写任何他想要的XML结构。

以下是我的实际文件:

# 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>

我的XSD文件如下所示:

# 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>

我尝试了mixed个值,xs:all,不同的元素类型但没有结果。

这可能是小菜一碟,但我是XSD架构的新手,我正在努力找到解决方案,在我的两个节点中可以存在所有内容。

谢谢你,
Matthéo。

1 个答案:

答案 0 :(得分:1)

您想要的类型是xsd:anyType,您可以按名称获取该类型:

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

或省略type属性:

<xs:element name="mapping" minOccurs="0" />
<xs:element name="options" minOccurs="0" />
相关问题