2013-10-23 122 views
1

您好任何人都可以給我一個簡單的XML示例基於這個可以驗證的XSD文件?或解釋究竟應該是什麼?
我是初學者到XSD,並不理解整個這個文檔!但我想有一個例子來生成一個基於這個文件,可以驗證的PHP的XML!謝謝
這是XSD文件:給這個xsd模式文件一個簡單的xml示例

<?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> 
+0

模塊E:D,祝您好運MR Alireza –

回答

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> 
+0

本文檔未能根據給定的模式進行驗證。 – crooveck

+0

不太可能,這幾乎是一個定局,即在使用xmlgrid.net用於構建文檔的xml庫時,該文檔將根據模式進行驗證。另外,簡單地說它失敗是相當模糊的。什麼具體失敗?你使用哪個庫來驗證它? – CamW

+0

'xmllint --noout --schema example.xsd example.xml' 有很多錯誤和最終消息驗證失敗。 Xmllint使用libxml2庫來解析和驗證xml。 – crooveck

相關問題