为这个xsd模式文件提供一个简单的xml示例

时间:2013-10-23 06:25:35

标签: xml xsd

大家能否根据这个可以验证的XSD文件给我一个简单的XML示例?或解释它到底应该是什么? 我是XSD的初学者,并不了解这份文件的全部内容!但我想有一个例子来生成一个基于此文件的PHP的XML,可以验证!谢谢
这是XSD文件:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attribute name="id" type="xs:positiveInteger"/>
<xs:complexType name="station">
    <xs:sequence>
        <xs:element name="name" type="xs:string" />
    </xs:sequence>
    <xs:attribute ref="id" use="required"/>
</xs:complexType>
<xs:complexType name="driver">
    <xs:sequence>
        <xs:element name="name" type="xs:string" />
        <xs:element name="birth_date" type="xs:date" />
        <xs:element name="email" type="xs:string" />
        <xs:element name="phone" type="xs:string" />
        <xs:element name="avatar" type="xs:string" />
    </xs:sequence>
    <xs:attribute ref="id" use="required"/>
</xs:complexType>
<xs:element name="lvb_system">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="line" minOccurs="0" maxOccurs="unbounded" >
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="code" type="xs:string" />
                        <xs:element name="type" type="xs:string" />
                        <xs:element name="start_time_operation" type="xs:time" />
                        <xs:element name="end_time_operation" type="xs:time" />
                        <xs:element name="count_vehicles">
                          <xs:simpleType>
                            <xs:restriction base="xs:integer">
                              <xs:minInclusive value="0"/>
                              <xs:maxInclusive value="10"/>
                            </xs:restriction>
                          </xs:simpleType>
                        </xs:element>
                        <xs:element name="map" type="xs:string" />
                        <xs:element name="start_station" type="station" minOccurs="0" maxOccurs="1" />
                        <xs:element name="end_station" type="station" minOccurs="0" maxOccurs="1" />
                        <xs:element name="intermediate_stations" type="station" minOccurs="0" maxOccurs="5" />
                        <xs:element name="vehicles_line" minOccurs="0" maxOccurs="10" >
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="name" type="xs:string" />
                                    <xs:element name="capacity" type="xs:integer" />
                                    <xs:element name="driver" minOccurs="0" maxOccurs="unbounded" type='driver' />
                                </xs:sequence>
                                <xs:attribute ref="id" use="required"/>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                    <xs:attribute ref="id" use="required"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>

2 个答案:

答案 0 :(得分:4)

此处的在线工具:

http://xmlgrid.net/genXml.html

在回答你的问题方面做得非常好。

答案 1 :(得分:2)

您可以使用http://xmlgrid.net/genXml.html从xsd生成xml。使用该服务,您的XSD会产生:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Document created with online XML Editor http://xmlgrid.net 2013/10/23 8:33:18  -->
<lvb_system>
     <line null="test attribute">
           <code>test string</code>
           <type>test string</type>
           <start_time_operation>test string</start_time_operation>
           <end_time_operation>test string</end_time_operation>
           <count_vehicles>test string</count_vehicles>
           <map>test string</map>
           <start_station>
                 <name>test string</name>
           </start_station>
           <end_station>
                 <name>test string</name>
           </end_station>
           <intermediate_stations>
                 <name>test string</name>
           </intermediate_stations>
           <vehicles_line null="test attribute">
                 <name>test string</name>
                 <capacity>9</capacity>
                 <driver>
                       <name>test string</name>
                       <birth_date>2011-01-15</birth_date>
                       <email>test string</email>
                       <phone>test string</phone>
                       <avatar>test string</avatar>
                 </driver>
                 <driver>
                       <name>test string</name>
                       <birth_date>2011-01-15</birth_date>
                       <email>test string</email>
                       <phone>test string</phone>
                       <avatar>test string</avatar>
                 </driver>
                 <driver>
                       <name>test string</name>
                       <birth_date>2011-01-15</birth_date>
                       <email>test string</email>
                       <phone>test string</phone>
                       <avatar>test string</avatar>
                 </driver>
           </vehicles_line>
     </line>
     <line null="test attribute">
           <code>test string</code>
           <type>test string</type>
           <start_time_operation>test string</start_time_operation>
           <end_time_operation>test string</end_time_operation>
           <count_vehicles>test string</count_vehicles>
           <map>test string</map>
           <start_station>
                 <name>test string</name>
           </start_station>
           <end_station>
                 <name>test string</name>
           </end_station>
           <intermediate_stations>
                 <name>test string</name>
           </intermediate_stations>
           <vehicles_line null="test attribute">
                 <name>test string</name>
                 <capacity>9</capacity>
                 <driver>
                       <name>test string</name>
                       <birth_date>2011-01-15</birth_date>
                       <email>test string</email>
                       <phone>test string</phone>
                       <avatar>test string</avatar>
                 </driver>
                 <driver>
                       <name>test string</name>
                       <birth_date>2011-01-15</birth_date>
                       <email>test string</email>
                       <phone>test string</phone>
                       <avatar>test string</avatar>
                 </driver>
                 <driver>
                       <name>test string</name>
                       <birth_date>2011-01-15</birth_date>
                       <email>test string</email>
                       <phone>test string</phone>
                       <avatar>test string</avatar>
                 </driver>
           </vehicles_line>
     </line>
     <line null="test attribute">
           <code>test string</code>
           <type>test string</type>
           <start_time_operation>test string</start_time_operation>
           <end_time_operation>test string</end_time_operation>
           <count_vehicles>test string</count_vehicles>
           <map>test string</map>
           <start_station>
                 <name>test string</name>
           </start_station>
           <end_station>
                 <name>test string</name>
           </end_station>
           <intermediate_stations>
                 <name>test string</name>
           </intermediate_stations>
           <vehicles_line null="test attribute">
                 <name>test string</name>
                 <capacity>9</capacity>
                 <driver>
                       <name>test string</name>
                       <birth_date>2011-01-15</birth_date>
                       <email>test string</email>
                       <phone>test string</phone>
                       <avatar>test string</avatar>
                 </driver>
                 <driver>
                       <name>test string</name>
                       <birth_date>2011-01-15</birth_date>
                       <email>test string</email>
                       <phone>test string</phone>
                       <avatar>test string</avatar>
                 </driver>
                 <driver>
                       <name>test string</name>
                       <birth_date>2011-01-15</birth_date>
                       <email>test string</email>
                       <phone>test string</phone>
                       <avatar>test string</avatar>
                 </driver>
           </vehicles_line>
     </line>
</lvb_system>