XSD <any> 요소
- 이전 페이지 XSD 지시자
- 다음 페이지 XSD <anyAttribute>
<any> 요소는 schema가 정의하지 않은 요소를 통해 XML 문서를 확장할 수 있는 능력을 주십니다!
<any> 요소
<any> 요소는 schema가 정의하지 않은 요소를 통해 XML 문서를 확장할 수 있는 능력을 주십니다!
이 예제는 "family.xsd"라는 이름의 XML schema에서 인용된 부분입니다. 이는 "person" 요소에 대한 선언을 보여줍니다. <any> 요소를 사용하여, <lastname> 다음의 어떤 요소(로)든 "person"의 내용을 확장할 수 있습니다:
<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" 요소를 사용하여 "person" 요소를 확장하고자 합니다. 이 경우 이렇게 할 수 있습니다. 이 schema의 작성자가 "children" 요소를 어떻게 선언했든지 관계없습니다.
이 스키마 파일을 보세요. 이름 "children.xsd"입니다:
<?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.codew3c.com" xmlns="http://www.codew3c.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="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.codew3c.com children.xsd"> <person> <firstname>David</firstname> <lastname>Smith</lastname> <children> <childname>mike</childname> </children> </person> <person> <firstname>Tony</firstname> <lastname>Smith</lastname> </person> </persons>
위의 XML 파일은 유효합니다. "family.xsd" 스키마가 "lastname" 요소 뒤의 선택적인 요소를 통해 "person" 요소를 확장할 수 있도록 허용하기 때문입니다.
<any>와 <anyAttribute>는 모두 확장 가능한 문서를 만들기 위해 사용될 수 있습니다! 이들은 문서가 주 XML schema에서 선언되지 않은 추가 요소를 포함할 수 있게 합니다.
- 이전 페이지 XSD 지시자
- 다음 페이지 XSD <anyAttribute>