Latest web development tutorials

XMLスキーマanyAttributeは要素

<anyAttributeは>要素は、XMLドキュメントのプロパティがスキーマによって指定されていない拡張することを可能に!


<anyAttributeは>要素は、XMLドキュメントのプロパティがスキーマによって指定されていない拡張することを可能に!

次の例は、「family.xsd」という名前のXMLスキーマからのフラグメントです。 それは私たちに「人」の要素に対する声明を示しています。 <anyAttributeは>要素を使用することにより、私たちは「人」の要素に任意の数の属性を追加することができます。

<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
<xs:anyAttribute/>
</xs:complexType>
</xs:element>

今、私たちは、「性別」を通じて「人」の要素を拡張する属性ことを願っています。 ここでは、上記のスキーマの作者は任意の「性別」の属性を宣言したことがない場合であっても、そうすることができます。

「attribute.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:attribute name="gender">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="male|female"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>

</xs:schema>

(「Myfamily.xml」と呼ばれる)は、以下のXML、異なるスキーマの、「family.xsd」と「attribute.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 attribute.xsd">

<person gender="female">
<firstname>Hege</firstname>
<lastname>Refsnes</lastname>
</person>

<person gender="male">
<firstname>Stale</firstname>
<lastname>Refsnes</lastname>
</person>

</persons>

スキーマ "family.xsdは「私たちは「人」の要素に属性を追加することを可能にするため、上記のこのXMLファイルには有効です。

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