Xsd-syntax
提供:Dev Guides
XSD-構文
XML XSDは別のドキュメントに保持され、ドキュメントをXMLドキュメントにリンクして使用できます。
構文
XSDの基本的な構文は次のとおりです-
<?xml version = "1.0"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
targetNamespace = "http://www.finddevguides.com"
xmlns = "http://www.finddevguides.com" elementFormDefault = "qualified">
<xs:element name = 'class'>
<xs:complexType>
<xs:sequence>
<xs:element name = 'student' type = 'StudentType' minOccurs = '0'
maxOccurs = 'unbounded'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name = "StudentType">
<xs:sequence>
<xs:element name = "firstname" type = "xs:string"/>
<xs:element name = "lastname" type = "xs:string"/>
<xs:element name = "nickname" type = "xs:string"/>
<xs:element name = "marks" type = "xs:positiveInteger"/>
</xs:sequence>
<xs:attribute name = 'rollno' type = 'xs:positiveInteger'/>
</xs:complexType>
</xs:schema>
<Schema>要素
スキーマはXSDのルート要素であり、常に必要です。
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
上記のフラグメントは、スキーマで使用される要素とデータ型がhttp://www.w3.org/2001/XMLSchema名前空間で定義され、これらの要素/データ型の前に xs を付けることを指定しています。 常に必要です。
targetNamespace = "http://www.finddevguides.com"
上記のフラグメントは、このスキーマで使用される要素がhttp://www.finddevguides.com名前空間で定義されることを指定しています。 オプションです。
xmlns = "http://www.finddevguides.com"
上記のフラグメントは、デフォルトの名前空間がhttp://www.finddevguides.comであることを指定しています。
elementFormDefault = "qualified"
上記のフラグメントは、このスキーマで宣言された要素は、XMLドキュメントで使用する前に名前空間で修飾する必要があることを示しています。これはオプションです。
スキーマの参照
次の参照スキーマを見てください-
<?xml version = "1.0"?>
<class xmlns = "http://www.finddevguides.com"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.finddevguides.com student.xsd">
<student rollno = "393">
<firstname>Dinkar</firstname>
<lastname>Kad</lastname>
<nickname>Dinkar</nickname>
<marks>85</marks>
</student>
<student rollno = "493">
<firstname>Vaneet</firstname>
<lastname>Gupta</lastname>
<nickname>Vinni</nickname>
<marks>95</marks>
</student>
<student rollno = "593">
<firstname>Jasvir</firstname>
<lastname>Singh</lastname>
<nickname>Jazz</nickname>
<marks>90</marks>
</student>
</class>
xmlns = "http://www.finddevguides.com"
上記のフラグメントは、デフォルトの名前空間宣言を指定しています。 この名前空間は、すべての要素がこの名前空間の一部であることを確認するスキーマ検証ツールによって使用されます。 オプションです。
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.finddevguides.com student.xsd">
XMLSchema-instance xsiを定義したら、 schemaLocation 属性を使用します。 この属性には、名前空間とXMLスキーマの場所の2つの値があり、スペースで区切って使用します。 オプションです。