如何创建所有可能的XML?

时间:2018-03-05 07:42:32

标签: java xml algorithm xsd combinations

如何创建这些XSD的所有可能的XML:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns="http://beep2000/client/beep.de" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://beep2000/client/beep.de">
    <xsd:complexType name="TextType">
        <xsd:sequence>
            <xsd:element name="Text" minOccurs=1">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:maxLength value="255"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="StreetType">
        <xsd:sequence>
            <xsd:element name="Street" type="xsd:string" minOccurs="1"/>
            <xsd:element name="HouseNumber" type="xsd:int" minOccurs="1"/>
            <xsd:element name="Suffix" type="xsd:string" minOccurs="1">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:maxLength value="1"/>
                        <xsd:enumeration value="A"/>
                        <xsd:enumeration value="B"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="BodyType">
        <xsd:sequence>
            <xsd:element name="FirstPart" type="TextType" minOccurs="1"/>
            <xsd:element name="SecondPart" type="TextType" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="AdressType">
        <xsd:sequence>
            <xsd:element name="Street" type="StreetType" minOccurs="0">
            <xsd:element name="PostalCode" minOccurs="0">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:maxLength value="5"/>
                    <xsd:pattern value="[0-9]{5}"/>
                </xsd:restriction>
            </xsd:simpleType>
            <xsd:element name="City" type="xsd:string" minOccurs="1"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="RequestEnvelope">
        <xsd:sequence>
            <xsd:element name="Title" type="xsd:string" minOccurs="0"/>
            <xsd:element name="Forename" type="xsd:string" minOccurs="1"/>
            <xsd:element name="Surname" type="xsd:string" minOccurs="0"/>
            <xsd:element name="PersonalID" minOccurs="0">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:maxLength value="20"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="Adress" type="AdressType" minOccurs="0"/>
            <xsd:element name="Body" type="BodyType" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="ResponseEnvelope">
        <xsd:sequence>
            <xsd:element name="Result" minOccurs="1">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:maxLength value="3"/>
                        <xsd:enumeration value="OK"/>
                        <xsd:enumeration value="NOK"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="Errorcode" type="xsd:integer" minOccurs="0"/>
            <xsd:element name="Errortext" minOccurs="0">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:maxLength value="255"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="Comment" type="TextType" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="MsgResponse" type="ResponseEnvelope"/>
    <xsd:element name="MsgRequest" type="RequestEnvelope"/>
</xsd:schema>

有些字段是可选的,某些字段是必填字段。所以有各种各样的XML。如何找到所有可能的XML结构?

我期待的是:

XML No.1:

  • 字段1 - &gt;强制性
  • 字段2 - &gt;强制性
  • 字段3 - &gt;可选的
  • ......

XML No.2。:

  • 字段1 - &gt;强制
  • 字段2 - &gt;强制
  • 字段4 - &gt;强制
  • .....

1 个答案:

答案 0 :(得分:0)

生成符合此模式的所有可能的XML文件将花费无限的时间,并且它们将占用无限的空间。

但是,您可以使用如下所述的工具生成一系列示例文档:

How to generate sample XML documents from their DTD or XSD?