XSD <any> 要素
- 前のページ XSD インデクサ
- 次のページ XSD <anyAttribute>
<any>要素により、スキーマで指定されていない要素を使用して XML ドキュメントを拡張することができます!
<any>要素
<any>要素により、スキーマで指定されていない要素を使用して XML ドキュメントを拡張することができます!
以下の例は「family.xsd」という名前の XML モードルシェーマから引用された部分です。それは「person」要素の宣言を示しています。<any>要素を使用することで、「person」の内容を(<lastname>の後の)どの要素でも拡張することができます:
<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」)は、2つの異なる 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" が "lastname" 要素の後のオプション要素を通じて "person" 要素を拡張することを許可しているためです。
<any> と <anyAttribute> はすべて拡張可能なドキュメントを作成するために使用できます!これにより、メインの XML schema で宣言されていない追加要素をドキュメントに含めることができます。
- 前のページ XSD インデクサ
- 次のページ XSD <anyAttribute>