XSD <anyAttribute> 요소
<anyAttribute> 요소를 사용하면 스키마에서 지정하지 않은 속성으로 XML 문서를 확장할 수 있습니다!
<anyAttribute> 요소
<anyAttribute> 요소를 사용하면 스키마에서 지정하지 않은 속성으로 XML 문서를 확장할 수 있습니다.
다음 예는 "family.xsd"라는 XML 스키마의 단편입니다. "person" 요소에 대한 선언을 보여줍니다. <anyAttribute> 요소를 사용하여 "person" 요소에 속성을 원하는 만큼 추가할 수 있습니다.
<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>
이제 "eyecolor" 속성으로 "person" 요소를 확장하려고 합니다. 이 경우 위의 스키마 작성자가 "eyecolor" 속성을 선언한 적이 없더라도 그렇게 할 수 있습니다.
"attribute.xsd"라고 하는 이 스키마 파일을 보십시오.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com"
xmlns="https://www.w3schools.com"
elementFormDefault="qualified">
<xs:attribute name="eyecolor">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="blue|brown|green|grey"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:schema>
아래의 XML 파일("Myfamily.xml"이라고 함)은 두 가지 다른 스키마의 구성 요소를 사용합니다. "family.xsd" 및 "attribute.xsd":
<?xml version="1.0" encoding="UTF-8"?>
<persons xmlns="http://www.microsoft.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:SchemaLocation="http://www.microsoft.com family.xsd
https://www.w3schools.com attribute.xsd">
<person eyecolor="green">
<firstname>Hege</firstname>
<lastname>Refsnes</lastname>
</person>
<person eyecolor="blue">
<firstname>Stale</firstname>
<lastname>Refsnes</lastname>
</person>
</persons>
위의 XML 파일은 "family.xsd" 스키마를 통해 "person" 요소에 속성을 추가할 수 있기 때문에 유효합니다.
<any> 및 <anyAttribute> 요소는 확장 가능한 문서를 만드는 데 사용됩니다! 기본 XML 스키마에 선언되지 않은 추가 요소를 문서에 포함할 수 있습니다.