XML 스키마 튜토리얼login
XML 스키마 튜토리얼
작가:php.cn  업데이트 시간:2022-04-20 14:13:02

XML 스키마 복합 요소


XSD 복합 요소


복합 요소에는 다른 요소 및/또는 속성이 포함됩니다.


h2>복합요소란 무엇인가요?

복합 요소는 다른 요소 및/또는 속성을 포함하는 XML 요소입니다.

복합 요소에는 네 가지 유형이 있습니다.

  • 빈 요소

  • 다른 요소를 포함하는 요소

  • 텍스트만 포함하는 요소

  • 요소와 텍스트를 모두 포함하는 요소

참고: 위의 모든 요소에는 속성이 포함될 수 있습니다!


복합 요소의 예

복합 요소 "product"는 비어 있습니다.

<product pid="1345"/>

복합 요소 "employee"는 다른 요소만 포함합니다.

<직원>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>

복합 XML 요소 "food", 텍스트만 포함:

<food type="dessert">Ice cream</food>

복합 XML 요소인 "설명"에는 요소와 텍스트가 포함됩니다.

<description>
<date lang="norwegian">03.03.99</date>에 발생했습니다. ...
</ 설명>


복합 요소를 어떻게 정의하나요?

다른 요소만 포함된 복합 XML 요소 "employee"를 살펴보세요.

<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>

XML 스키마에는 복합 요소를 정의하는 두 가지 방법이 있습니다.

1 이 요소의 이름을 지정하면 "employee" 요소를 직접 수정할 수 있습니다. , 다음과 같이

<xs:element name="employee">
​ <xs:복합 유형>
​​ <xs:순서>
                        <xs:element name="firstname" type="xs:string"/>
                        <xs:element name="성" type="xs:string"/>
​​ </xs:순서>
​ </xs:복합 유형>
</xs:요소>

위에서 설명한 방법을 사용하면 "직원"만 지정된 복합 유형을 사용할 수 있습니다. 해당 하위 요소인 "firstname" 및 "lastname"은 표시기 <sequence>에 포함되어 있습니다. 이는 하위 요소가 선언된 순서대로 나타나야 함을 의미합니다. XSD 표시기 섹션에서 표시기에 대해 자세히 알아봅니다.

2. "employee" 요소는 사용할 복합 유형의 이름을 참조하는 데 사용되는 유형 속성을 사용할 수 있습니다.

<xs:element name="employee" type="personinfo"/> ;

<xs:complexType name="personinfo">
​ <xs:순서>
​​ <xs:element name="firstname" type="xs:string"/>
​​ <xs:element name="성" type="xs:string"/>
​ </xs:sequence>
</xs:complexType>

위에 설명된 방법을 사용하면 다음과 같이 여러 요소가 동일한 복합 유형을 사용할 수 있습니다.

<xs:element name= "employee" type="personinfo"/>
<xs:element name="student" type="personinfo"/>
<xs:element name="member" type="personinfo"/> ;

<xs:complexType name="personinfo">
​ <xs:순서>
​​ <xs:element name="firstname" type="xs:string"/>
​​ <xs:element name="성" type="xs:string"/>
​ </xs:시퀀스>
</xs:복합 유형>

기존 복합 요소 위에 복합 요소를 기반으로 한 다음 다음과 같이 일부 요소를 추가할 수도 있습니다.

<xs:element name="employee" type="fullpersoninfo"/> :complexType name="personinfo">
​ <xs:순서>
​​ <xs:element name="firstname" type="xs:string"/>
​​ <xs:element name="성" type="xs:string"/>
​ </xs:sequence>
</xs:complexType>

<xs:complexType name="fullpersoninfo">
​ <xs:복잡한 콘텐츠>
​​ <xs:extension base="personinfo">
                        <xs:순서>
                                         <xs:element name="address" type="xs:string"/>
                                  <xs:element name="city" type="xs:string"/>
                                  <xs:element name="country" type="xs:string"/>
                        </xs:순서>
​​ </xs:확장>
​ </xs:complexContent>
</xs:complexType>