1

嗨,谁能给我一个基于此 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>
4

2 回答 2

4

这里的在线工具:

http://xmlgrid.net/genXml.html

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

于 2013-10-23T06:38:00.570 回答
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>
于 2013-10-23T06:38:07.467 回答