1. XML이란? - :: 서비의 다락방

Download Report

Transcript 1. XML이란? - :: 서비의 다락방

XSD
(XML Schema Definition)
XML
XML
XML
XML
Schemas
Schemas
Schemas
Schemas
기초
데이터 형식
Complex Types
simpleTypes
XML Schemas 기초 (1/11)

XML Schemas 출현배경
 DTD의 제한점

작성/이해하기가 어렵다.(XML문서와 다른 문법을 사용함)

확장성이 불가능 함.

Data Type 정의에 제약이 많음.

상속(Inheritance)기능이 없다.

XML 문법과 다름.

XML에 대한 요구상황이 달라졌다. (문서에 대한 프로세싱 요구가
많아짐.)
 DTD보다 더 표현력이 풍부하고, 정확한 자료 구조를 제공하는
새로운 구조 정의 언어가 필요함.
XML Schemas 기초 (2/11)



XML Schemas 종류
다양한 XML-based schema 언어가 출현함.
 학술 단체: RDF(Resource Description Framework)
 B2B관련업체들:
 Commerceone 등: SOX(Schema for Object-oriented XML)
 MS 등 : XML Data, XDR(XML Data Reduced)
 IBM, MS 등: DCD(Document Content Description)
 DDML(Document Definition Markup Language: ‘ XSchema’)
 W3C: XML Schema
스키마들의 차이점.
 스키마 작성 규칙이 다름.
예: 루트 엘리먼트 기술 규칙, Intrinsic data type 등
XML Schemas 기초 (3/11)

XML Schemas


XML 스키마는 하나의 XML 문서 안에 어떤 것들을 담을 수 있는지에 대한
규칙.
XML 스키마의 장점.






XML 구문을 사용
다양한 데이터 형을 지원
네임스페이스를 지원
복잡한 내용 모델을 쉽게 생성.
DTD보다 유연한 XML 문서를 작성하는데 적용.
Data Type 및 엘리먼트 재사용이 가능함.
XML Schemas 기초 (4/11)
DTD와 XML Schemas의 비교
DTD
XML문법을 따르지 않고 독자적인 문
법을 가짐.(SGML의 DTD형식)

다양한 종류의 데이터 타입을 지원하
지 않음.
XSD

XSD는 XML 문법을 따름.

XSD는 풍부한 데이터형을 제공.

XSD는 데이터의 제약 조건을 세밀하
게 정의 함.

http://www.w3.org/XML/Schema
XML Schemas 기초 (5/11)
DTD와 XML Schemas의 비교
DTD
XSD
<!ELEMENT .. >
<element ... > .. </element>
<!ATTLIST .. >
<attribute .. />
,
<sequence> .. </sequence>
|
<choice> .. </choice>
?
minOccurs="0" maxOccurs="1"
+
minOccurs="1" maxOccurs="unbounded"
*
minOccurs="0" maxOccurs="unbounded"
XML Schemas 기초 (6/11)
XML Schemas 문서의 선언문
<접두어:schema xmlns:namespace 접두어 = “namespace 이름”>
<xsd:schema xmlns:xsd=“http://www.w3.org/2001/XMLSchema”>

Namespace(이름공간)이란?
 어떤 이름이 통용되는 범위를 말하는 것.
XML Schemas 기초 (7/11)
XSD 문서의 전체 구조
<?xml version=“1.0” encoding=“EUC-KR”?>
<xsd:schema xmlns:xsd=“http://www.w3.org/2001/XMLSchema”>
<!– 이곳에 XSD 정의 문장이 위치합니다. -->
</xsd:schema>
<?xml version=“1.0” encoding=“EUC-KR”?>
<schema xmlns=“http://www.w3.org/2001/XMLSchema”>
<!– 이곳에 XSD 정의 문장이 위치합니다. -->
</schema>
XML Schemas 기초 (8/11)
엘리먼트 선언하기
<xsd:element name=“도서목록” type=“xsd:string”>
접두사
<element>태그
엘리먼트 이름
엘리먼트 데이터형
<?xml version=“1.0” encoding=“EUC-KR”?>
<xsd:schema xmlns:xsd=“http://www.w3.org/2001/XMLSchema”>
<xsd:element name=“도서목록” type=“xsd:string”>
</xsd:element>
</xsd:schema>
XML Schemas 기초 (9/11)
XML 문서와 XML Schemas의 결합


XML 문서에 XML 스키마 문서에 대한 참조를 포함.
schemaLocation 속성은 유효성 검증에 필요한 XML 스키마를 찾을 수 있는 위치를
알려 줌.
<도서목록 xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:noNamespaceSchemaLocation=“name04.xsd”>
<도서목록 xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://www.e-xml.net name04.xsd”>
XML Schemas 기초 (10/11)
XML 문서와 XML Schemas의 결합 예제
<?xml version=“1.0” encoding=“EUC-KR”?>
<도서목록 xmlns:xsi=“http://www.w3.org/2001/XMLSchemainstance”
xsi:noNamespaceSchemaLocation=“name04.xsd">
<도서>
<분류>컴퓨터</분류>
<제목>XML 무작정 따라하기</제목>
<출판사>길벗</출판사>
<저자>박준서</저자>
</도서>
</도서목록>
XML Schemas 기초 (11/11)

XSD 문서 유효성 검사


MSXML 파서의 경우 버전 4.0 에서부터 XSD라고 불리는 W3C 표준 스키
마를 지원 합니다.
따라서 이 예제들을 실행해 보려면 실습 컴퓨터에 MSXML 파서 4.0 이상의
버전이 설치되어 있어야 합니다.
또한, 최신 MSXML 4.0 파서를 설치하려면 먼저 실습 컴퓨터에 Windows
Installer가 설치되어 있어야 합니다.
MSXML 4.0 파서와 Windows Installer 를 설치하신 후, XSD 문서 유효성
검사기를 설치 하세요
XML Schemas 데이터 형식(1/5)

미리 정의된 데이터 타입

데이터 타입 분류
 XML 스키마에서 미리 정의된 데이터 타입(built-in datatype)
 사용자가 정의하는 타입(user-derived datatype)
기본형
미리 정의된 타입
단순 타입
유도형
단순 타입
사용자가 정의하는 타입
restriction
restriction
복합 타입
extension
XML Schemas 데이터 형식(2/5)
1) 기본 데이터형
데이터형
설
명
String
문자열을 의미.
Boolean
부울값을 의미, ‘True’ 또는 ‘False’값을 가짐.
Decimal
숫자를 의미.
Float
32비트 부동 소수점 수를 의미.
Double
64비트 부동 소수점 수를 의미.
Duration
날짜와 시간을 의미.
anyURI
URI를 의미
QName
정규화된 이름을 의미.
NOTATION
Qnames 집합.
XML Schemas 데이터 형식(3/5)
2) 유도 데이터형
데이터형
설
명
DateTime
날짜와 시간을 의미.
Time
시간을 의미.
Date
달력 날짜를 의미.
gYearMonth
그레고리오력 달을 의미.
gYear
그레고리오력 해를 의미.
gMonthDay
일 년 중 특정한 날에 되풀이 되는 그레고리오력 날짜를 의미.
gDay
월 중 특정한 날에 되풀이 되는 그레고리오력 일을 의미.
gMonth
매년 되풀이되는 그레고리오력 달을 의미.
hexBinary
16진수로 인코딩한 임의의 2진 데이터를 의미.
base64Binary
Base64로 인코딩한 임의의 2진 데이터를 의미.
XML Schemas 데이터 형식(4/5)
미리 정의된 데이터 타입들의 상속 관계
XML Schemas 데이터 형식(5/5)
사용자 정의 데이터 타입


Complex Types
 Allow element children
 Attributes allowed
Simple Types
 No element children
 No attributes
엘리먼트의 선언:Complex Type(1/10)

Sequence
엘리먼트들이 스키마에 나타난 순서대로 나타나야 함을 지정

choice
엘리먼트나 엘리먼트 그룹 사이에서 하나를 선택 하고자 할때 사용.

all
엘리먼트들이 순서에 얽매이지 않고 올 수 있음을 지정.
엘리먼트의 선언:Complex Type(2/10)
<sequence> 태그
<도서목록>
<도서>
<분류>컴퓨터</분류>
<제목>XML 무작정 따라하기</제목>
<출판사>길벗</출판사>
<저자>박준서</저자>
</도서>
</도서목록>
<!DOCTYPE 도서목록[
<!ELEMENT 도서목록 (도서)>
<!ELEMENT 도서 (분류, 제목, 출판사, 저
자>
<!ELEMENT 분류 (#PCDATA)>
<!ELEMENT 제목 (#PCDATA)>
<!ELEMENT 출판사 (#PCDATA)>
<!ELEMENT 저자 (#PCDATA)>
]>
엘리먼트의 선언:Complex
Type(3/10)
Complex Type (member.xsd)
<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="member">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string" />
<xsd:element name="phone_no" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
엘리먼트의 선언:Complex
Type(4/10)
Complex Type (member.xml)
<?xml version="1.0" encoding="euc-kr"?>
<member xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:noNamespaceSchemaLocation=“member.xsd">
<name>홍길동</name>
<phone_no>031-111-2323</phone_no>
</member>
엘리먼트의 선언:Complex
Type(5/10)
<?xml version="1.0" encoding="EUC-KR"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="도서목록">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="도서">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="분류" type="xsd:string" />
<xsd:element name="제목" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
엘리먼트의 선언:Complex
Type(6/10)
디폴트 네임스페이스
<?xml version="1.0" encoding="EUC-KR"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="도서목록">
<complexType>
<sequence>
<element name="도서">
<complexType>
<sequence>
<element name="분류" type="string" />
<element name="제목" type="string" />
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
<Choice> 태그
도서목록09.xsd
도서목록10.xml
<?xml version="1.0" encoding="EUC-KR"?>
<?xml version="1.0" encoding="EUC-KR"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="도서목록">
<complexType>
<sequence>
<element name="도서">
<complexType>
<choice>
<element name="분류" type="string" />
<element name="제목" type="string" />
<element name="출판사" type="string" />
<element name="저자" type="string" />
</choice>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
<도서목록 xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xsi:noNamespaceSchemaLocation="도서목록09.xsd">
<도서>
<제목>XML 무작정 따라하기</제목>
<저자>김은희</저자>
</도서>
</도서목록>
수정하시오!
<all> 태그
도서목록11.xsd
도서목록12.xml
<?xml version="1.0" encoding="EUC-KR"?>
<?xml version="1.0" encoding="EUC-KR"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="도서목록">
<complexType>
<sequence>
<element name="도서">
<complexType>
<all>
<element name="분류" type="string" />
<element name="제목" type="string" />
<element name="출판사" type="string" />
<element name="저자" type="string" />
</all>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
<도서목록 xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xsi:noNamespaceSchemaLocation="도서목록09.xsd">
<도서>
<제목>XML 무작정 따라하기</제목>
<분류>컴퓨터</분류>
<저자>김은희</저자>
<출판사>길벗</출판사>
</도서>
</도서목록>
분류,제목,출판사,저자
-> 순서를 바꿔 보세요.
엘리먼트의 선언:Complex
Type(7/10)

minOccurs와 maxOccurs



하위 엘리먼트의 반복 횟수를 정의.
minOccurs
 최소 반복 횟수 정의
 기본값 = 1
 minOccurs=0 엘리먼트 생략 가능.
 minOccurs=1
반드시 엘리먼트 정의.
maxOccurs
 최대 반복 횟수 정의
 기본값 = 1
 maxOccurs=1 무조건 한번만 정의.
 maxOccurs=unbounded 반복 횟수에 제한을 받지 않고 사용.
엘리먼트의 선언:Complex
Type(8/10)

minOccurs와 maxOccurs 어트리뷰트
 반복 횟수
 minOccurs : 0 or 1 or unbounded (Default : 1)
 maxOccurs : 0 or 1 or unbounded (Default : 1)
DTD 연산자
minOccurs
maxOccurs
출연횟수
1
1
1번
?
0
1
0번 또는 1번
*
0
unbounded
0번 이상
+
1
unbounded
1번 이상

파일명 : 도서목록13.xsd
<?xml version="1.0" encoding="EUC-KR"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="도서목록">
<complexType>
<sequence>
<element name="도서" minOccurs="1" maxOccurs="unbounded">
<complexType>
<sequence>
<element name="분류" type="string" minOccurs="1" maxOccurs="1" />
<element name="제목" type="string" minOccurs="0" maxOccurs="1" />
<element name="출판사" type="string" minOccurs="0"
maxOccurs="unbounded" />
<element name="저자" type="string" minOccurs="1" maxOccurs="2" />
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>

다음을 수정하시오!
<?xml version="1.0" encoding="EUC-KR"?>
<도서목록 xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xsi:noNamespaceSchemaLocation="도서목록13.xsd">
<도서>
<분류>컴퓨터</분류>
<제목>XML 무작정 따라하기</제목>
<출판사>길벗</출판사>
<저자>박준서</저자>
<저자>최배근</저자>
<저자>김은희</저자>
</도서>
<도서>
<분류>컴퓨터</분류>
<제목>알기쉬운 xml</제목>
</도서>
</도서목록>
엘리먼트의 선언:Complex
Type(9/10)
Default와 fixed 속성


Default
 엘리먼트 값이 default 값이거나 아니거나 상관없음.
Fixed
 엘리먼트에 정의되는 값이 반드시 ‘fixed’로 정의된 값이
어야 함.

파일명:도서목록15.xsd
<?xml version="1.0" encoding="EUC-KR"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="도서목록">
<complexType>
<sequence>
<element name="도서" minOccurs="1" maxOccurs="unbounded">
<complexType>
<sequence>
<element name="분류" type="string" default="컴퓨터" />
<element name="제목" type="string" fixed="XML 무작정 따라하기" />
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>


파일명:도서목록15.xml
다음을 수정하시오!
<?xml version="1.0" encoding="EUC-KR"?>
<도서목록 xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xsi:noNamespaceSchemaLocation="도서목록15.xsd">
<도서>
<분류>노트북</분류>
<제목>NEW 알기쉬운 xml</제목>
</도서>
</도서목록>
엘리먼트의 선언:Complex Type(10/10)
<group> 선언


재사용 가능한 엘리먼트들의 그룹 생성
반복되는 엘리먼트의 그룹을 <group>태그로 묶은 후
XSD에서 필요할때 사용.

파일명 : 도서목록17.xsd
<?xml version="1.0" encoding="EUC-KR" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:group name="myItem">
<xsd:sequence>
<xsd:element name="분류" type="xsd:string" />
<xsd:element name="제목" type="xsd:string" />
<xsd:element name="출판사" type="xsd:string" />
<xsd:element name="저자" type="xsd:string" />
</xsd:sequence>
</xsd:group>
<xsd:element name="도서목록">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="도서">
<xsd:complexType>
<xsd:sequence>
<xsd:group ref="myItem" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
엘리먼트 선언:simpleType(1/27)

사용자가 정의하는 단순 타입(simpleType)
1)
2)
3)
4)
restriction
list
union
simpleType 원소를 이용.
엘리먼트 선언:simpleType(2/27)
제한(restriction)을 통한 단순 타입 정의




값의 범위를 제한 함.
제한을 통해서 새로운 타입을 정의하기 위해서는 restriction 원
소를 사용하고, 바탕이 되는 기존 단순 타입(base) 속성을 이용
해서 기술한다.
기존의 데이터 타입(기본 타입)으로부터 새로운 데이터 타입을
생성할 수 있음
하나 이상의 facet를 통해 값을 제어할 수 있음
엘리먼트 선언:simpleType(3/27)
패싯(facet)


값의 범위(value space)를 한 관점(single aspect)에서 정의하는 것.
예: 값의 범위를 지정하는 패싯
<xsd:simpleType name="ScoreType">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
엘리먼트 선언:simpleType(4/27)
패싯(facet)의 종류

length

minLength / maxLength

pattern

enumeration

whiteSpace

minInclusive / maxInclusive

minExclusive / maxExclusive

totalDigits / fractionDigits
엘리먼트 선언:simpleType(5/27)

패싯(facet)의 종류(1)

length – 길이
<simpleType name=‘productCode’>
<restriction base=‘NMTOKEN’>
<length value=‘8’/>
</restriction>
</simpleType>
엘리먼트 선언:simpleType(6/27)

패싯(facet)의 종류(2)

minLength – 최소 길이
<simpleType name=‘non-empty-string’>
<restriction base=‘string’>
<minLength value=‘1’/>
</restriction>
</simpleType>
엘리먼트 선언:simpleType(7/27)

패싯(facet)의 종류(3)

maxLength – 최대 길이
<simpleType name=‘form-input’>
<restriction base=‘string’>
<maxLength value=‘50’/>
</restriction>
</simpleType>

Ex. <length>,<minLength>,<maxLength>-도서목록29.xsd
<?xml version="1.0" encoding="EUC-KR"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="도서목록">
<complexType>
<sequence>
<element name="도서" maxOccurs="unbounded">
<complexType>
<attribute name="분류">
<simpleType>
<restriction base="string">
<length value="3" />
</restriction>
</simpleType>
</attribute>
<attribute name="제목">
<simpleType>
</complexType>
<restriction base="string">
</element>
<minLength value="1" />
</sequence>
<maxLength value="6" />
</complexType>
</restriction>
</simpleType>
</attribute>
</element>
</schema>

유효한 XML 문서를 완성하시오!
<?xml version="1.0" encoding="EUC-KR"?>
<도서목록 xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xsi:noNamespaceSchemaLocation="도서목록29.xsd">
<도서 분류=“ ” 제목="XML" />
<도서 분류="소설1” 제목="소설
무작정" />
</도서목록>
엘리먼트 선언:simpleType(8/27)

패싯(facet)의 종류(4)

pattern – 패턴
<simpleType name=‘isbnType’>
<restriction base=‘string’>
<pattern value=‘\d{10}’/>
</restriction>
</simpleType>
엘리먼트 선언:simpleType(9/27)

Ex.pattern – 우편번호 데이터 타입
<?xml version="1.0" encoding="euc-kr"?>
<member>
<name>을지문덕</name>
<phone_no>031-123-3333</phone_no>
<zipcode>462-710</zipcode>
<address>경기도 성남시 ...</address>
</member>

Ex.pattern – 우편번호 데이터 타입
<?xml version="1.0" encoding="euc-kr" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- 루트요소 선언 -->
<xsd:element name="member">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string" />
<xsd:element name="phone_no" type="xsd:string" />
<xsd:element name="zipcode" type="zipType" />
<xsd:element name="address" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- zipType 선언 -->
<xsd:simpleType name='zipType'>
<xsd:restriction base='xsd:string'>
<xsd:pattern value='\d{3}(-\d{3})?'/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

Ex.pattern – 우편번호 데이터 타입
<?xml version="1.0" encoding="euc-kr" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- 루트요소 선언 -->
<xsd:element name="member">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string" />
<xsd:element name="phone_no" type="xsd:string" />
<xsd:element name="zipcode">
<xsd:simpleType>
<xsd:restriction base='xsd:string'>
<xsd:pattern value='\d{3}(-\d{3})?'/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="address" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
엘리먼트 선
언:simpleType(10/27)

패싯(facet)의 종류(5)
 enumeration – 유효한 값의 리스트
<simpleType name=‘season’>
<restriction base=‘string’>
<enumeration value=‘봄’/>
<enumeration value=‘여름’/>
<enumeration value=‘가을’/>
<enumeration value=‘겨울’/>
</restriction>
</simpleType>

Ex.enumeration - 도서목록27.xsd
<?xml version="1.0" encoding="EUC-KR"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="도서목록">
<complexType>
<sequence>
<element name="도서" maxOccurs="unbounded">
<complexType>
<attribute name="분류">
<simpleType>
<restriction base="string">
<enumeration value="컴퓨터" />
<enumeration value="소설" />
<enumeration value="만화" />
</restriction>
</simpleType>
</attribute>
<attribute name="제목" type="string" />
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>

Ex. 유효한 XML 문서를 완성하시오!
<?xml version="1.0" encoding="EUC-KR"?>
<도서목록 xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance“ xsi:noNamespaceSchemaLocation="도서목록
27.xsd">
<도서 분류="노트북” 제목="XML 무작정 따라하기" />
<도서 분류="소설 만화” 제목="소설 무작정 따라하기" />
</도서목록>
엘리먼트 선
언:simpleType(12/27)

패싯(facet)의 종류(6)
 whiteSpace – 값의 공백 처리를 제어한다.



preserve : 변경없음
replace : 탭, CR, LF 문자를 공백으로 변경
collapse : replace를 적용하고 추가적으로 연속 공
백, 시작 공백, 후행 공백을 제거
엘리먼트 선
언:simpleType(11/27)

패싯(facet)의 종류(6)

whiteSpace – 값의 공백 처리를 제어한다.
<simpleType name=‘token’>
<restriction base=‘normalizedString’>
<whiteSpace value=‘collapse’/>
</restriction>
</simpleType>
엘리먼트 선
언:simpleType(13/27)

패싯(facet)의 종류(8)

minInclusive – 최소값
<simpleType name=‘one-more’>
<restriction base=‘integer’>
<minInclusive value=‘1’/>
</restriction>
</simpleType>
엘리먼트 선
언:simpleType(14/27)

패싯(facet)의 종류(7)
 maxInclusive – 최대값
<simpleType name=‘one-hundred’>
<restriction base=‘integer’>
<maxInclusive value=‘100’/>
</restriction>
</simpleType>

Ex. minInclusive와 maxInclusive – 도서목록31.xsd
<?xml version="1.0" encoding="EUC-KR"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="도서목록">
<complexType>
<sequence>
<element name="도서" maxOccurs="unbounded">
<complexType>
<attribute name="수량">
<simpleType>
<restriction base="integer">
<minInclusive value=“1" />
<maxInclusive value="10" />
</restriction>
</simpleType>
</attribute>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>

Ex. 유효한 XML 문서를 완성하시오!
<?xml version="1.0" encoding="EUC-KR"?>
<도서목록 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="도서목록31.xsd">
<도서 수량="11" />
</도서목록>

Q:조건에 맞는 XSD를 완성 하시오!

지정되어야 하는 실내 온도가 20도에서 28도 사이
라면 integer 타입을 사용하여 <simpleType>으로
지정하고 제한을 줄 수 있다.
엘리먼트 선
언:simpleType(15/27)

패싯(facet)의 종류(9)

minExclusive – 입력 불가능한 값 중 최소값
<simpleType name=‘more-than-ninety-nine’>
<restriction base=‘integer’>
<minExclusive value=‘99’/>
</restriction>
</simpleType>
엘리먼트 선
언:simpleType(16/27)

패싯(facet)의 종류(9)

maxExclusive – 입력 불가능한 값 중 최대값
<simpleType name=‘one-hundred-and-more’>
<restriction base=‘integer’>
<maxExclusive value=‘101’/>
</restriction>
</simpleType>
엘리먼트 선
언:simpleType(17/27)

패싯(facet)의 종류(11)

totalDigits – 숫자 최대 자릿수(소수점 이하포함)
<simpleType name=‘amount’>
<restriction base=‘decimal’>
<totalDigits value=‘8’/>
<fractionDigits value=‘2’/>
</restriction>
</simpleType>
엘리먼트 선
언:simpleType(18/27)

패싯(facet)의 종류(12)
 fractionDigits – 소수점 이하 최대 자릿수
<simpleType name=‘amount’>
<restriction base=‘decimal’>
<totalDigits value=‘4’/>
<fractionDigits value=‘1’/>
<minInclusinve value=‘36.4’/>
<maxInclusinve value=‘40.5’/>
</restriction>
</simpleType>
엘리먼트 선
언:simpleType(19/27)

리스트(list)를 이용한 단순 타입 확장


단순 타입
 단일 타입 - XML 스키마 관점에서 더 이상 나눌 수 없는 값
 리스트 타입 - 단일 타입 값들의 연속으로 이루어진 것을 의미.
 유니온 타입 – 주어진 값 중에서 하나 선택
예: 리스트 타입 정의
<xsd:simpleType name="authors">
<xsd:list itemType="author"/>
</xsd:simpleType>
공백으로 분리된 여러 데이터를 가지는 심플 타입 정의
c6_1205.xsd
c6_1205.xml
엘리먼트 선
언:simpleType(20/27)

리스트(list)
<xsd:simpleType name=“nameType">
<xsd:list itemType=“xsd:string”/>
</xsd:simpleType>
nameType이 가질 수 있는 값
-> 강감찬 을지문덕 이순신 권율

nameType 데이터 개수를
지정하는 것. 문자열
길이를 지정하는 것이
아님
11명의 축구팀 멤버 이름을 저장하는 타입 선언
->
<xsd:simpleType name=“soccerMemberNameType">
<xsd:restriction base=“nameType”>
<xsd:length value=“11”/>
</xsd:restriction>
</xsd:simpleType>

엘리먼트 선
언:simpleType(21/27)

유니온(union)을 이용한 단순 타입 확장



주어진 여러 개의 단일 타입이나 리스트 타입 중에서 한 타입을 지정
해서 사용하는 방법.
예: 유니온 타입 정의
<xsd:simpleType name="writer">
<xsd:union
memberTypes="xsd:positiveInteger
authors"/>
</xsd:simpleType>
예: 유니온 타입의 사용
<writer>123</writer>
<writer>홍길동 김개똥 허준</writer>
여러 개의 심플 타입을 결합한 심플 타입 정의
c6_1206.xsd
c6_1206.xml
엘리먼트 선
언:simpleType(22/27)

복합 타입 확장
 extension을 이용한 복합 타입 확장
 복합 타입은 simpleContent와 complexContent 원소의
extension 자식 원소를 이용해서 새로운 복합 타입을 정
의.
 simpleContent - 단순타입을 복합타입으로 변환할 때 사용.
 예) string 데이터 타입을 갖는 원소에 속성을 추가해야 하
는 경우에 simpleContent를 사용한다. 속성을 갖기 위해
서는 복합 타입으로 선언되어야 함.
 complexContent - 복합 타입을 바탕으로 새로운 복합 타입
을 정의할 때 사용.
엘리먼트 선
언:simpleType(23/27)

simpleContent 사용

자식 요소없이 문자 데이터와 속성만 가지는 간단한 내용 모델을 구현.
<xsd:element name=“member”>
<xsd:complexType>
<xsd:simpelContent>
<xsd:extension base=“xsd:string”>
<xsd:attribute name="name" type="xsd:string" use=“required”/>
</xsd:extension>
</xsd:simpelContent >
</xsd:complexType>
</xsd:element>

<member name=“홍길동”>동명정보</member>
엘리먼트 선
언:simpleType(24/27)

simpleContent 사용

내부에 restriction과 extension을 포함

예: 가격을 위한 XML 문서
<price currency="USD">500.25</price>
<price currency="WON">25000</price>
예: PriceType 정의
<xsd:complexType name="PriceType">
<xsd:simpleContent>
<xsd:extension base="xsd:float">
<xsd:attribute name="currency" type="xsd:NMTOKEN/>
</xsd:extension>
<xsd:simpleContent>
</xsd:complexType>

c6_1305.xsd
c6_1305.xml
엘리먼트 선
언:simpleType(25/27)

complexContent – extenstion 사용

복합 타입을 바탕으로 새로운 복합 타입을 정의할 때 사용.

내부에 restriction과 extension을 포함하는 두가지 방법.

예: extension을 사용하는 방법
<xsd:complexType name="ManagerType">
<xsd:complexContent>
<xsd:extension base="EmployeeType">
<xsd:sequence>
<xsd:element name="subordinates“ type="xsd:NMTOKENS"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="manager" type="ManagerType"/>
엘리먼트 선
언:simpleType(26/27)

complexContent – restriction 사용
 예: restriction을 사용하면 기존의 <complexType>을 제한할 수
있다.
<xsd:complexType name="TopManagerType">
<xsd:complexContent>
<xsd:restriction base="EmployeeType">
<xsd:sequence>
……
<xsd:element
name="dept"
type="xsd:string"
minOccurs="0" maxOccurs="0"/>
……
<xsd:attribute name="id" type="IdType"/>
……
엘리먼트 선
언:simpleType(27/27)

restriction을 이용한 복합 타입 확장

restriction은 기존 데이터 타입에 제약 사항들을 기술.

예: 전화 번호를 위한 타입
<xsd:complexType name="PhoneType">
<xsd:simpleContent>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{3}-\d{4}"/>
<xsd:attribute name="where" type="HomeOffice"/>
</xsd:restriction>
<xsd:simpleContent>
</xsd:complexType>