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 스키마에 대한 설명을 포함하고 있지 않은 문서를 만들 수있는 능력을 가지고있다.