Содержание «ограничения» должно совпадать - PullRequest
0 голосов
/ 16 мая 2018

Я не могу создать действительный файл .xsd для моего XML-документа. Мой XML выглядит следующим образом:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="styles.xsl" type="text/xsl" ?>

<Information
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="schema.xsd"
>

    <game>
        <pic></pic>
        <number>1</number>
        <title id="1">Tetris</title>
        <developer>Elektronorgtechnica</developer>
        <publisher>Spectrum HoloByte</publisher>
        <release>
            <year>1984</year>
            <month>June</month>
            <day>19</day>
        </release>
        <platform>Multi-platform</platform>
    </game>
    <game>
        <pic></pic>
        <number>2</number>
        <title id="2">Minecraft</title>
        <developer>Mojang</developer>
        <publisher>Mojang</publisher>
        <release>
            <year>2011</year>
            <month>November</month>
            <day>18</day>
        </release>
        <platform>Multi-platform</platform>
    </game>
    <game>
        <pic></pic>
        <number>3</number>
        <title id="3">Grand Theft Auto</title>
        <developer>Rockstar North</developer>
        <publisher>Rockstar Games</publisher>
        <release>
            <year>2013</year>
            <month>September</month>
            <day>17</day>
        </release>
        <platform>Multi-platform</platform>
    </game>
    <game>
        <pic></pic>
        <number>4</number>
        <title id="4">Wii Sports</title>
        <developer>Nintendo EAD</developer>
        <publisher>Nintendo</publisher>
        <release>
            <year>2006</year>
            <month>November</month>
            <day>19</day>
        </release>
        <platform>Wii</platform>
    </game>
    <game>
        <pic></pic>
        <number>5</number>
        <title id="5">Super Mario Bros.</title>
        <developer>Nintendo</developer>
        <publisher>Nintendo</publisher>
        <release>
            <year>1985</year>
            <month>September</month>
            <day>13</day>
        </release>
        <platform>NES</platform>
    </game>
    <game>
        <pic></pic>
        <number>6</number>
        <title id="6">PlayerUnknown's Battlegrounds</title>
        <developer>PUBG Corporation</developer>
        <publisher>PUBG Corporation</publisher>
        <release>
            <year>2017</year>
            <month>December</month>
            <day>20</day>
        </release>
        <platform>Multi-platform</platform>
    </game>
    <game>
        <pic></pic>
        <number>7</number>
        <title id="7">Mario Kart Wii</title>
        <developer>Nintendo EAD</developer>
        <publisher>Nintendo</publisher>
        <release>
            <year>2008</year>
            <month>April</month>
            <day>10</day>
        </release>
        <platform>Wii</platform>
    </game>
    <game>
        <pic></pic>
        <number>8</number>
        <title id="8">Wii Sports Resort</title>
        <developer>Nintendo EAD</developer>
        <publisher>Nintendo</publisher>
        <release>
            <year>2009</year>
            <month>June</month>
            <day>25</day>
        </release>
        <platform>Wii</platform>
    </game>
    <game>
        <pic></pic>
        <number>9</number>
        <title id="9">Pokémon Red and Blue</title>
        <developer>Game Freak</developer>
        <publisher>Nintendo</publisher>
        <release>
            <year>1996</year>
            <month>February</month>
            <day>27</day>
        </release>
        <platform>Game Boy</platform>
    </game>
    <game>
        <pic></pic>
        <number>10</number>
        <title id="10">New Super Mario Bros.</title>
        <developer>Nintendo EAD</developer>
        <publisher>Nintendo</publisher>
        <release>
            <year>2006</year>
            <month>May</month>
            <day>15</day>
        </release>
        <platform>Multi-platform</platform>
    </game>
    <game>
        <pic></pic>
        <number>11</number>
        <title id="11">The Elder Scrolls V: Skyrim</title>
        <developer>Bethesda Game Studios</developer>
        <publisher>Bethesda Softworks</publisher>
        <release>
            <year>2011</year>
            <month>November</month>
            <day>11</day>
        </release>
        <platform>Multi-platform</platform>
    </game>
    <game>
        <pic></pic>
        <number>12</number>
        <title id="12">Grand Theft Auto: San Andreas</title>
        <developer>Rockstar North</developer>
        <publisher>Rockstar Games</publisher>
        <release>
            <year>2004</year>
            <month>Octover</month>
            <day>26</day>
        </release>
        <platform>Multi-platform</platform>
    </game>
    <game>
        <pic></pic>
        <number>13</number>
        <title id="13">Call of Duty: Modern Warfare 3</title>
        <developer>Infinity Ward Sledgehammer Games</developer>
        <publisher>Activision</publisher>
        <release>
            <year>2011</year>
            <month>November</month>
            <day>8</day>
        </release>
        <platform>Multi-platform</platform>
    </game>
    <game>
        <pic></pic>
        <number>14</number>
        <title id="14">The Sims</title>
        <developer>Maxis</developer>
        <publisher>Electronic Arts</publisher>
        <release>
            <year>2000</year>
            <month>January</month>
            <day>31</day>
        </release>
        <platform>Multi-platform</platform>
    </game>
    <game>
        <pic></pic>
        <number>15</number>
        <title id="15">Need for Speed: Most Wanted</title>
        <developer>EA Black Box</developer>
        <publisher>Electronic Arts</publisher>
        <release>
            <year>2005</year>
            <month>November</month>
            <day>11</day>
        </release>
        <platform>Multi-platform</platform>
    </game>
    <game>
        <pic></pic>
        <number>16</number>
        <title id="16">Battlefield 3</title>
        <developer>EA DICE</developer>
        <publisher>Electronic Arts</publisher>
        <release>
            <year>2011</year>
            <month>October</month>
            <day>25</day>
        </release>
        <platform>Multi-platform</platform>
    </game>
</Information>

и мой xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.bdo.com.ph/RemitAPI">
<xs:element name="Information">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="game" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="number" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="title" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="developer" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="publisher" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="release" type="xs:string" minOccurs="0" maxOccurs="unbounded">
                            <xs:simpleType>
                                <xs:restriction base="xs:integer">
                                    <xs:element name="year" maxOccurs="unbounded"/>
                                    <xs:element name="month" maxOccurs="unbounded"/>
                                    <xs:element name="day" maxOccurs="unbounded"/>
                                </xs:restriction>
                            </xs:simpleType>
                        </xs:element>
                        <xs:element name="platform" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="id" type="xs:integer"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>

И есть ошибка: Содержимое «ограничения» должно соответствовать (аннотация ?, (simpleType ?, (minExclusive | MinInclusive | MaxExclusive | MaxInclusive | TotalDigits | FractionDigits | Длина | MinLength | MaxLength | Перечисление | WhiteSpace | Pattern) *)). Обнаружена проблема, начиная с: Элемент.

Помогите пожалуйста. Что я делаю не так?

P.S. И теперь я отредактировал тип данных в строку, но все еще есть ошибка:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.bdo.com.ph/RemitAPI">

<xs:element name="Information">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="game" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="number" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="title" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="developer" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="publisher" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="release" type="xs:string" minOccurs="0" maxOccurs="unbounded">
                            <xs:simpleType>
                                <xs:restriction base="xs:string">
                                    <xs:element name="year" maxOccurs="unbounded"/>
                                    <xs:element name="month" maxOccurs="unbounded"/>
                                    <xs:element name="day" maxOccurs="unbounded"/>
                                </xs:restriction>
                            </xs:simpleType>
                        </xs:element>
                        <xs:element name="platform" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="id" type="xs:integer"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

</xs:schema>

Содержимое «ограничения» должно совпадать (аннотация ?, (simpleType ?, (minExclusive | MinInclusive | MaxExclusive | MaxInclusive | TotalDigits | FractionDigits | Length | MinLength | MaxLength | Enumeration | WhiteSpace | Pattern) *)). Проблема была найдена начиная с: Элемент.

1 Ответ

0 голосов
/ 16 мая 2018

Ваша непосредственная проблема заключается в том, что, как говорит диагностика, вы не можете иметь xs:element в качестве ребенка xs:restriction. Даже не понятно, что ты там пытаешься сделать.

Ваш XML указывает, что вы хотите, чтобы year, month и day были дочерними элементами release. Итак, вы не хотите xs:restriction, но xs:complexType/xs:sequence, как вы уже сделали для game:

          <xs:element name="release" minOccurs="0" maxOccurs="unbounded">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="year" maxOccurs="unbounded"/>
                <xs:element name="month" maxOccurs="unbounded"/>
                <xs:element name="day" maxOccurs="unbounded"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>

Вы обнаружите, что после того, как вы исправите свою непосредственную проблему, останется еще много. Например, вы еще не определили pic в своем XSD. Надеюсь, вы сможете решить их самостоятельно, отклеившись. Попытайтесь исследовать и немного прочесть XSD, прежде чем публиковать новые вопросы. не опубликуйте серию проверок для каждой следующей ошибки проверки, с которой вы столкнулись в этом вопросе.

...