Latest web development tutorials

XMLスキーマのいずれかの要素

要素によって> <任意>要素は、拡大する機能は、XML文書のスキーマによって指定されていない私たちを与えます!


H2> <任意の>要素

素子による<すべて>要素は私たちに、XML文書のスキーマによって指定されていません拡大することができます!

次の例は、「family.xsd」と呼ばれるXMLスキーマからの断片を引用されています。 それは、「人」の要素の宣言を示しています。 <任意の>要素を使用することにより、我々は、拡張された「人」の要素の後(<姓>内)の任意の要素を使用することができます。

<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.xsd "という名前のこのスキーマファイルを見てください:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.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>

、(「Myfamily.xml」という名前の)次のXMLファイルには、2つの異なるスキーマの成分、「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.w3schools.com children.xsd">

<person>
<firstname>Hege</firstname>
<lastname>Refsnes</lastname>
<children>
<childname>Cecilie</childname>
</children>
</person>

<person>
<firstname>Stale</firstname>
<lastname>Refsnes</lastname>
</person>

</persons>

XMLファイルの上に「family.xsd「私たちは、「人」の要素を展開する「姓」の要素の任意の要素の後に許可されたスキーマが原因である、有効です。

<すべて>と<anyAttributeは>スケーラブルな文書を作成するために使用することができます! 彼らは追加の要素を介してメインXMLスキーマのステートメントが含まれていませんでした文書を作る能力を持っています。