首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“限制”的内容必须匹配

“限制”的内容必须匹配
EN

Stack Overflow用户
提问于 2018-05-16 13:08:05
回答 1查看 142关注 0票数 1

我无法为我的xml文档创建一个有效的.xsd文件。我的XML如下:

代码语言:javascript
复制
<?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:

代码语言:javascript
复制
<?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、FractionDigits、MinLength、MinLength MaxLength、枚举、MinLength、WhiteSpace、*))。从: Element开始发现了一个问题。

请帮帮忙。我做错了什么?

现在我将数据类型编辑为string,但是仍然有一个错误:

代码语言:javascript
复制
<?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、MaxInclusive、FractionDigits、MinLength、MaxLength、WhiteSpace )模式)。从: Element开始发现了一个问题。

EN

回答 1

Stack Overflow用户

发布于 2018-05-16 13:49:14

您当前的问题是,正如诊断所告诉您的那样,不能将xs:element作为xs:restriction的子代。你在那里做什么还不清楚。

您的XML表示您希望yearmonthday成为release的子级。所以,您不需要xs:restriction,而是xs:complexType/xs:sequence,就像您已经为game所做的那样:

代码语言:javascript
复制
          <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>

你会发现,在你解决了眼前的问题后,还会有更多的问题。例如,您还没有在XSD中定义pic。希望你能在摆脱困境后自己解决这些问题。在发布新的问题之前,试着研究并做一些基本的XSD阅读。不要为您所遇到的下一个验证错误发布一系列后续跟踪。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50371834

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档