XSD <모든> 요소
<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>
이제 "person" 요소를 "children" 요소로 확장하려고 합니다. 이 경우 위의 스키마 작성자가 "자식" 요소를 선언한 적이 없더라도 그렇게 할 수 있습니다.
"children.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: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"이라고 함)은 두 가지 다른 스키마의 구성 요소를 사용합니다. "family.xsd" 및 "children.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 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" 스키마가 "lastname" 요소 뒤에 선택적 요소를 사용하여 "person" 요소를 확장할 수 있기 때문에 유효합니다.
<any> 및 <anyAttribute> 요소는 확장 가능한 문서를 만드는 데 사용됩니다! 기본 XML 스키마에 선언되지 않은 추가 요소를 문서에 포함할 수 있습니다.