XML 튜토리얼

XML 홈 XML 소개 XML 사용 방법 XML 트리 XML 구문 XML 요소 XML 속성 XML 네임스페이스 XML 표시 XML HttpRequest XML 파서 XML DOM XML XPath XML XSLT XML XQuery XML XLink XML 유효성 검사기 XML DTD XML 스키마 XML 서버 XML 예제 XML 퀴즈 XML 인증서

XML AJAX

AJAX 소개 AJAX XMLHttp AJAX 요청 AJAX 응답 AJAX XML 파일 AJAX PHP AJAX ASP AJAX 데이터베이스 AJAX 애플리케이션 AJAX 예제

XML DOM

DOM 소개 DOM 노드 DOM 액세스 DOM 노드 정보 DOM 노드 목록 DOM 순회 DOM 탐색 DOM 값 가져오기 DOM 변경 노드 DOM 제거 노드 DOM 교체 노드 DOM 생성 노드 DOM 추가 노드 DOM 복제 노드 DOM 예제

XPath 튜토리얼

XPath 소개 XPath 노드 XPath 구문 XPath 축 XPath 연산자 XPath 예제

XSLT 튜토리얼

XSLT 소개 XSL 언어 XSLT 변환 XSLT <템플릿> XSLT <값> XSLT <각각> XSLT <정렬> XSLT <만약> XSLT <선택> XSLT 적용 클라이언트의 XSLT 서버의 XSLT XSLT XML 편집 XSLT 예

XQuery 튜토리얼

XQuery 소개 XQuery 예제 XQuery FLWOR 엑스쿼리 HTML XQuery 용어 XQuery 구문 XQuery 추가 XQuery 선택 XQuery 함수

XML DTD

DTD 소개 DTD 빌딩 블록 DTD 요소 DTD 속성 DTD 요소 대 속성 DTD 엔터티 DTD 예

XSD 스키마

XSD 소개 XSD 방법 XSD <스키마> XSD 요소 XSD 속성 XSD 제한 사항

XSD 컴플렉스

XSD 요소 XSD 비어 있음 XSD 요소만 XSD 텍스트만 XSD 혼합 XSD 지표 XSD <모든> XSD <모든 속성> XSD 대체 XSD 예

XSD 데이터

XSD 문자열 XSD 날짜 XSD 숫자 XSD 기타 XSD 참조

서비스

XML 서비스 XML WSDL XML SOAP XML RDF XML RSS

참고문헌

DOM 노드 유형 DOM 노드 DOM 노드 목록 DOM NamedNodeMap DOM 문서 DOM 요소 DOM 속성 DOM 텍스트 DOM CDATA DOM 주석 DOM XMLHttpRequest DOM 파서 XSLT 요소 XSLT/XPath 함수

XSD 제한 사항/측면


제한 사항은 XML 요소 또는 속성에 대해 허용되는 값을 정의하는 데 사용됩니다. XML 요소에 대한 제한을 패싯이라고 합니다.


값에 대한 제한

다음 예제는 제한이 있는 "age"라는 요소를 정의합니다. age 값은 0보다 작거나 120보다 클 수 없습니다.

<xs:element name="age">
  <xs:simpleType>
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="0"/>
      <xs:maxInclusive value="120"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

값 집합에 대한 제한 사항

XML 요소의 내용을 허용 가능한 값 집합으로 제한하려면 열거 제약 조건을 사용합니다.

아래 예제는 제한이 있는 "car"라는 요소를 정의합니다. 허용되는 값은 Audi, Golf, BMW뿐입니다.

<xs:element name="car">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:enumeration value="Audi"/>
      <xs:enumeration value="Golf"/>
      <xs:enumeration value="BMW"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

위의 예는 다음과 같이 작성할 수도 있습니다.

<xs:element name="car" type="carType"/>

<xs:simpleType name="carType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="Audi"/>
    <xs:enumeration value="Golf"/>
    <xs:enumeration value="BMW"/>
  </xs:restriction>
</xs:simpleType>

참고: 이 경우 "carType" 유형은 "car" 요소의 일부가 아니기 때문에 다른 요소에서 사용할 수 있습니다.



일련의 값에 대한 제한 사항

사용할 수 있는 일련의 숫자 또는 문자를 정의하기 위해 XML 요소의 내용을 제한하려면 패턴 제약 조건을 사용합니다.

아래 예는 제한이 있는 "문자"라는 요소를 정의합니다. 허용되는 유일한 값은 a에서 z까지의 소문자 중 하나입니다.

<xs:element name="letter">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-z]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

다음 예제는 제한이 있는 "initials"라는 요소를 정의합니다. 허용되는 유일한 값은 a에서 z까지의 대문자 중 3개입니다.

<xs:element name="initials">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[A-Z][A-Z][A-Z]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

다음 예제에서는 제한이 있는 "이니셜"이라는 요소도 정의합니다. 허용되는 유일한 값은 a에서 z까지의 소문자 또는 대문자 중 3개입니다.

<xs:element name="initials">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-zA-Z][a-zA-Z][a-zA-Z]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

다음 예는 제한이 있는 "choice"라는 요소를 정의합니다. 허용되는 유일한 값은 x, y, 또는 z 문자 중 하나입니다.

<xs:element name="choice">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[xyz]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

다음 예는 제한이 있는 "prodid"라는 요소를 정의합니다. 유일하게 허용되는 값은 시퀀스의 5자리 숫자이며 각 숫자는 0에서 9 사이의 범위에 있어야 합니다.

<xs:element name="prodid">
  <xs:simpleType>
    <xs:restriction base="xs:integer">
      <xs:pattern value="[0-9][0-9][0-9][0-9][0-9]"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

일련의 값에 대한 기타 제한 사항

아래 예는 제한이 있는 "문자"라는 요소를 정의합니다. 허용되는 값은 a에서 z까지의 소문자가 0개 이상 발생하는 것입니다.

<xs:element name="letter">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="([a-z])*"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

다음 예제에서는 제한이 있는 "문자"라는 요소도 정의합니다. 허용되는 값은 하나 이상의 문자 쌍이며, 각 쌍은 소문자와 대문자로 구성됩니다. 예를 들어 "sToP"는 이 패턴으로 검증되지만 "Stop", "STOP" 또는 "stop"은 검증되지 않습니다.

<xs:element name="letter">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="([a-z][A-Z])+"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

다음 예는 제한이 있는 "gender"라는 요소를 정의합니다. 허용되는 유일한 값은 남성 또는 여성입니다.

<xs:element name="gender">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="male|female"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

다음 예는 제한이 있는 "password"라는 요소를 정의합니다. 한 행에 정확히 8개의 문자가 있어야 하며 해당 문자는 a에서 z까지의 소문자 또는 대문자이거나 0에서 9까지의 숫자여야 합니다.

<xs:element name="password">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="[a-zA-Z0-9]{8}"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

공백 문자에 대한 제한 사항

공백 문자를 처리하는 방법을 지정하려면 공백 제약 조건을 사용합니다.

이 예제는 제한이 있는 "address"라는 요소를 정의합니다. whiteSpace 제약 조건은 "preserve"로 설정되며, 이는 XML 프로세서가 공백 문자를 제거하지 않음을 의미합니다.

<xs:element name="address">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:whiteSpace value="preserve"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

이 예제는 또한 제한이 있는 "address"라는 요소를 정의합니다. whiteSpace 제약 조건은 "replace"로 설정되며, 이는 XML 프로세서가 모든 공백 문자(줄 바꿈, 탭, 공백 및 캐리지 리턴)를 공백으로 대체함을 의미합니다.

<xs:element name="address">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:whiteSpace value="replace"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

이 예제는 또한 제한이 있는 "address"라는 요소를 정의합니다. 공백 제약 조건이 "축소"로 설정되어 있습니다. 즉, XML 프로세서가 모든 공백 문자를 제거합니다(줄 바꿈, 탭, 공백, 캐리지 리턴은 공백으로 대체되고, 선행 및 후행 공백은 제거되고, 여러 공백은 다음으로 축소됩니다. 단일 공백):

<xs:element name="address">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:whiteSpace value="collapse"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

길이 제한

요소에서 값의 길이를 제한하려면 길이, maxLength 및 minLength 제약 조건을 사용합니다.

이 예에서는 제한이 있는 "password"라는 요소를 정의합니다. 값은 정확히 8자여야 합니다.

<xs:element name="password">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:length value="8"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

이 예에서는 제한이 있는 "password"라는 또 다른 요소를 정의합니다. 값은 최소 5자에서 최대 8자여야 합니다.

<xs:element name="password">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:minLength value="5"/>
      <xs:maxLength value="8"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

데이터 유형에 대한 제한 사항

Constraint Description
enumeration Defines a list of acceptable values
fractionDigits Specifies the maximum number of decimal places allowed. Must be equal to or greater than zero
length Specifies the exact number of characters or list items allowed. Must be equal to or greater than zero
maxExclusive Specifies the upper bounds for numeric values (the value must be less than this value)
maxInclusive Specifies the upper bounds for numeric values (the value must be less than or equal to this value)
maxLength Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero
minExclusive Specifies the lower bounds for numeric values (the value must be greater than this value)
minInclusive Specifies the lower bounds for numeric values (the value must be greater than or equal to this value)
minLength Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero
pattern Defines the exact sequence of characters that are acceptable
totalDigits Specifies the exact number of digits allowed. Must be greater than zero
whiteSpace Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled