DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> XML學習教程 >> XML基礎 >> Schema初學者進階(2)
Schema初學者進階(2)
編輯:XML基礎     

 

簡化Schema的設計

在我們上次的練習中,設計Schema所使用的方法是極其簡單的。由於使用層層嵌套的的定義方法,當文檔非常復雜時,由於嵌套層次過深,文檔將不易閱讀並且難以維護。同時這種方法和過去DTD的設計結構有非常大的差異,這使得人或者機器想把DTD轉換成XML Schema時會有困難。

因此,這裡我們介紹另外一種非層次的設計方法,以上一章文檔為例,我們首先定義文檔中最基本的元素,然後在復雜元素中引用我們已經定義的基本元素的,這樣使得我們的設計非常的簡潔易懂。

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">
<!-- definition of simple type elements -->
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="author" type="xsd:string"/>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="friend-of" type="xsd:string"/>
<xsd:element name="since" type="xsd:date"/>
<xsd:element name="qualification" type="xsd:string"/>
<!-- definition of attributes -->
<xsd:attribute name="isbn" type="xsd:string"/>
<!-- definition of complex type elements -->
<xsd:element name="character">
<xsd:complexType>
<xsd:sequence>
<!-- the simple type elements are referenced using the "ref" attribute -->
<xsd:element ref="name"/>
<!-- the definition of the cardinality is done when the elements are referenced -->
<xsd:element ref="friend-of" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="since"/>
<xsd:element ref="qualification"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="book">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="title"/>
<xsd:element ref="author"/>
<xsd:element ref="character" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute ref="isbn"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>

 

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved