2012-05-24 33 views
1

我想問一下.XSD文件。我無法找到有關創建我自己的類型,例如什麼:XSD我的數據類型

<?xml version="1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

    <xs:complexType name="Client"> 
     <xs:sequence> 
      <xs:element name="FirstName" type="string"/> 
      <xs:element name="SecondName" type="string"/> 
    </xs:sequence> 
    </xs:complexType> 

    <xs:complexType name="Contact"> 
     <xs:sequence> 
      <xs:element name="contacts" type="Client" minOccurs="1"/> 
     </xs:sequence> 
    </xs:complexType> 
</xsd:schema> 

而且我想知道的是,正確的方式來定義自己的類型的接觸?

+2

看起來很好 - 我唯一要改變的是交換'Contact'和'contacts'元素名稱,因爲你的複雜類型是聯繫人列表,而你的'Client'類型的元素是單個聯繫人。 – Filburt

+0

非常感謝這是我的第一次體驗,所以我不確定。 – RMachnik

回答

2

有幾點不完全正確。

  • 的XSD:在關閉模式標記命名空間別名應該只是XS:

  • 的原始字符串類型需要有資格的類型,即XS:字符串。

  • 從樣式的角度來看ComplexTypes應該結束Type。

  • 如果你想使用模式(大概通過聯繫人),那麼你需要聲明一個根元素。

Graphical representation of an XML Schema

<?xml version="1.0" encoding="utf-8" ?> 
<!--Created with Liquid XML Studio 2012 Developer Edition (Trial) 10.0.1.3941 (http://www.liquid-technologies.com)--> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:complexType name="ClientType"> 
     <xs:sequence> 
      <xs:element name="FirstName" type="xs:string" /> 
      <xs:element name="SecondName" type="xs:string" /> 
     </xs:sequence> 
    </xs:complexType> 
    <xs:complexType name="ContactType"> 
     <xs:sequence> 
      <xs:element name="contacts" type="ClientType" minOccurs="1" /> 
     </xs:sequence> 
    </xs:complexType> 
    <xs:element name="Client" type="ClientType" /> 
</xs:schema> 

基本上XML模式是複雜的東西不使用工具來寫。我會認真考慮成爲一名優秀的模式設計師,我推薦Liquid XML Studio