XSD <any> 要素
- 前のページ XSD インデクサ
- 次のページ XSD <anyAttribute>
<any> 元素は、schema で指定されていない要素を使用して XML 文書を拡張する能力を私たちに与えます!
<any> 元素
<any> 元素は、schema で指定されていない要素を使用して XML 文書を拡張する能力を私たちに与えます!
以下の例は "family.xsd" という名前の XML schema から引用されたスライスです。これは "person" 元素に関する宣言を示しています。 <any> 元素を使用することで、<lastname> の後ろの任意の要素を通じて "person" の内容を拡張することができます:
<xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:any minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element>
現在、私たちは "children" 元素を使用して "person" 元素を拡張したいと考えています。この場合、この schema の作者が "children" 元素を宣言していない場合でもこれを行うことができます。
この schema ファイルを見てください、"children.xsd" という名前です:
<?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.codew3c.com" xmlns="http://www.codew3c.com" elementFormDefault="qualified"> <xs:element name="children"> <xs:complexType> <xs:sequence> <xs:element name="childname" type="xs:string" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
以下のこの XML ファイル("Myfamily.xml" という名前)は、二つの異なる schema、"family.xsd" と "children.xsd" から構成されています:
<?xml version="1.0" encoding="ISO-8859-1"?> <persons xmlns="http://www.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:SchemaLocation="http://www.microsoft.com family.xsd http://www.codew3c.com children.xsd"> <person> <firstname>David</firstname> <lastname>Smith</lastname> <children> <childname>mike</childname> </children> </person> <person> <firstname>Tony</firstname> <lastname>Smith</lastname> </person> </persons>
この XML ファイルは有効です。schema "family.xsd" が "person" 要素を拡張するために "lastname" 要素の後のオプション要素を許可しているためです。
<any> と <anyAttribute> は拡張可能なドキュメントを作成するために使用できます!これにより、メインの XML schema で宣言されていない追加の要素をドキュメントに含めることができます。
- 前のページ XSD インデクサ
- 次のページ XSD <anyAttribute>