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

XML 스키마 표시기


XSD Indicators


표시기를 사용하면 문서에서 요소가 사용되는 방식을 제어할 수 있습니다.


표시기

7가지 유형의 표시기가 있습니다.

순서 표시기:

  • All

  • Choice

  • Sequence

발생 표시기:

  • maxOccurs

  • minOccurs

그룹 표시기:

  • 그룹 이름

  • attributeGroup name


순서 표시기

순서 표시기는 요소의 순서를 정의하는 데 사용됩니다.

모든 표시

<all> 표시는 하위 요소가 어떤 순서로든 나타날 수 있으며 각 하위 요소는 한 번만 표시되어야 함을 규정합니다.

<xs:element name="person">
<xs:복합 유형>
<xs:모두>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="성" type="xs:string"/>
</xs:모두>
</xs:complexType>
</xs:element>

참고: <all> 표시기를 사용하는 경우 <minOccurs> 표시기를 0 또는 1로 설정할 수 있습니다. 는 1로 설정됩니다(에 대해서는 나중에 설명합니다).

Choice 표시기

<choice> 표시기는 특정 하위 요소가 나타날 수 있는지 또는 다른 하위 요소가 나타날 수 있는지 지정합니다(이것 또는 저것):

<xs:element name="person">
<xs:복합 유형>
<xs:선택>
<xs:element name="employee" type="employee"/>
  <xs:element name="member" type="member"/>
</xs:선택>
</xs:복합 유형>
</xs:요소>

순서 표시기

<sequence>는 하위 요소가 특정 순서로 표시되어야 함을 지정합니다.

<xs:element name="person">
<xs:복합 유형>
<xs:순서>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="성" type="xs:string"/>
</xs:순서>
</xs:complexType>
</xs:element>


발생 표시기

발생 표시기는 요소의 발생 빈도를 정의하는 데 사용됩니다.

참고: 모든 "순서" 및 "그룹" 표시기(모든, 모두, 선택, 순서, 그룹 이름 및 그룹 참조)의 경우 maxOccurs 및 minOccurs의 기본값은 1입니다.

maxOccurs 표시기

<maxOccurs> 표시기는 요소가 나타날 수 있는 최대 횟수를 지정할 수 있습니다:

<xs:element name="person">
<xs:복합 유형>
<xs:순서>
<xs:element name="full_name" type="xs:string"/>
  <xs:element name="child_name" type="xs:string" maxOccurs="10"/>
</xs:순서>
</xs:complexType>
</xs:element>

위의 예에서는 하위 요소 "child_name"이 "person" 요소에 한 번 이상 나타날 수 있음을 보여줍니다(minOccurs의 기본값은 1입니다). 그리고 많아야 10번.

minOccurs 표시기

<minOccurs> 표시기는 요소가 나타날 수 있는 최소 횟수를 지정할 수 있습니다:

<xs:element name="person">
<xs:복합 유형>
<xs:순서>
<xs:element name="full_name" type="xs:string"/>
  <xs:element name="child_name" type="xs:string"
  maxOccurs="10" minOccurs="0"/>
</xs:순서>
</xs:복합 유형>
</xs:요소>

위 예에서는 하위 요소 "child_name"이 "person" 요소에 최소 0회, 최대 10회 나타날 수 있음을 보여줍니다.

팁: 요소의 발생 횟수를 무제한으로 설정하려면 maxOccurs="unbounded" 문을 사용하세요.

실용적 예:

"Myfamily.xml"이라는 XML 파일:

<?xml version="1.0" 인코딩="ISO-8859-1"?>

<persons xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi :noNamespaceSchemaLocation="family.xsd">

<사람>
<full_name>헤게 참조</full_name>
<child_name>Cecilie</child_name>
</person>

<person>
<full_name>Tove Refsnes</full_name>
<child_name>헤게</child_name>
<child_name>오래된</child_name>

<child_name>보르게</child_name>
</person>

<person>
<full_name>오래된 참조</full_name>
</person>

</persons>

위 XML 파일에는 "persons"라는 루트 요소가 포함되어 있습니다. 이 루트 요소 안에는 세 개의 "person" 요소를 정의합니다. 각 "person" 요소는 "full_name" 요소를 포함해야 하며 최대 5개의 "child_name" 요소를 포함할 수 있습니다.

스키마 파일 "family.xsd"입니다:

<?xml version="1.0" 인코딩="ISO-8859-1"?>
<xs:schema xmlns:xs="http: / /www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">

<xs:element name="persons">
<xs:복합 유형>
<xs:순서>
<xs:요소 이름="사람" maxOccurs="무제한">
  <xs:복합 유형>
<xs:순서>
             <xs:element name="full_name" type="xs:string"/>
          <xs:element name="child_name" type="xs:string"
          minOccurs="0" maxOccurs="5"/>
</xs:순서>
</xs:복합 유형>
</xs:요소>
</xs:순서>
</xs:complexType>
</xs:element>

</xs:schema>


그룹 표시기

그룹 표시기는 관련 요소 배치를 정의하는 데 사용됩니다.

요소 그룹

요소 그룹은 그룹 선언을 통해 정의됩니다.

< 전체, 선택 또는 순서 요소를 정의합니다. 다음 예에서는 정확한 순서로 표시되어야 하는 요소 집합을 정의하는 "persongroup"이라는 그룹을 정의합니다.

<xs:group name="persongroup">
<xs:순서>

<xs:element name="firstname" type="xs:string"/>

<xs:element name="성" type="xs:string"/>
<xs:element name="생일" type="xs:date"/>
</xs:순서>
</xs:그룹>

그룹을 정의한 후 다른 정의에서 참조할 수 있습니다:

<xs:group name="persongroup">
<xs:순서>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="성" type="xs:string"/>
<xs:element name="생일" type="xs:date"/>
</xs:sequence>
</xs:group>

<xs:element name="person" type="personinfo"/>

<xs:complexType name="personinfo">
<xs:순서>
<xs:group ref="persongroup"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>

속성 그룹

속성 그룹은 attributeGroup 선언을 통해 정의됩니다.

<xs:attributeGroup name="groupname">
...
</xs:attributeGroup>

다음 예에서는 "personattrgroup"이라는 속성 그룹을 정의합니다.

<xs:attributeGroup name="personattrgroup">
<xs:속성 이름="이름" type="xs:string"/>
<xs:속성 이름="성" 유형="xs:string"/>
<xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>

속성 그룹을 정의한 후 다음과 같이 다른 정의에서 이를 참조할 수 있습니다.

<xs:attributeGroup name="personattrgroup">
<xs:속성 이름="이름" type="xs:string"/>
<xs:속성 이름="성" 유형="xs:string"/>
<xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>

<xs:element name="person">
<xs:복합 유형>
<xs:attributeGroup ref="personattrgroup"/>
</xs:복합 유형>
</xs:요소>