我无法为我的xml文档创建有效的.xsd文件。 我的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>
并且存在错误:内容限制&#39;必须匹配(注释?,(simpleType?,(minExclusive | MinInclusive | MaxExclusive | MaxInclusive | TotalDigits | FractionDigits | Length | MinLength | MaxLength | Enumeration | 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>
内容限制&#39;必须匹配(注释?,(simpleType?,(minExclusive | MinInclusive | MaxExclusive | MaxInclusive | TotalDigits | FractionDigits | Length | MinLength | MaxLength | Enumeration | WhiteSpace | Pattern)*))。从以下问题开始找到问题:元素。
答案 0 :(得分:0)
您的直接问题是,正如诊断所示,您不能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>
你会发现,在你解决了眼前的问题之后,还会有更多问题。例如,您尚未在XSD中定义pic
。希望你能在解开之后自己解决这些问题。在发布更多新问题之前,尝试研究并进行一些基本的XSD阅读。对于您在此问题中遇到的每个下一个验证错误,请不发布一系列跟进。