Section 01 XML DTD XML students student xml

































- Slides: 33






Section 01 XML 스키마 개요 DTD와 XML 스키마 예제 비교 <students> student. xml <student> <sno> s 100</sno> <name> 고소영 </name> <age> 26 </age> <phone>02 -123 -8989</phone> <address> 서울 한남동</address> </student> </students> student. dtd <!ELEMENT students (student)*> <!ELEMENT student (sno, name, age, phone, address) > <!ELEMENT sno (#PCDATA)> <!ELEMENT name (#PCDATA)> <!ELEMENT age (#PCDATA)> <!ELEMENT phone (#PCDATA)> <!ELEMENT address (#PCDATA)> <xsd: schema xmlns: xsd="http: //www. w 3. org/2001/XMLSchema"> <xsd: element name="student"> <xsd: complex. Type> <xsd: sequence> <xsd: element name="sno" type="xsd: string"/> <xsd: element name="name" type="xsd: string"/> <xsd: element name="age" type="xsd: string"/> <xsd: element name="phone" type="xsd: string"/> <xsd: element name="address" type="xsd: string"/> </xsd: sequence> </xsd: complex. Type> </xsd: element> </xsd: schema> student. xsd 6

Section 01 XML 스키마 개요 DTD를 XML 스키마로 변환 DTD XML 스키마 <!ELEMENT> <element/> <!ATTLIST> <attribute/> , <sequence>. . . </sequence> | <choice>. . . <choice> + min. Occurs ="1" max. Occurs="unbounded" ? min. Occurs ="0" max. Occurs="1" * min. Occurs ="0" max. Occurs="unbounded" 7







Section 02 XML 스키마 사용법 XML 스키마 선언 XML 스키마의 네임스페이스 속성을 설정하고 사용하기 위해서 선언 형식 <xsd: schema xmlns: xsd="http: //www. w 3. org/2001/XMLSchema">① target. Namespace="http: //www. dankook. ac. kr"② xmlns="http: //www. mysite. com"③ element. Form. Default="qualified"④ attribute. Form. Default="qualified">⑤. . . </xsd: schema> XML 스키마 선언은 <xsd: schema> 요소로 시작 최상위 요소는 항상 schema 14


Section 02 XML 스키마 사용법 기본 네임스페이스로 XML 스키마 선언 XML 스키마와 관련된 요소에는 ”xsd"라는 접두사를 사용하지 않 아도 된다. <schema xmlns="http: //www. w 3. org/2001/XMLSchema" target. Namespace="http: //www. dankook. ac. kr" xmlns: std="http: //www. mysite. com" element. Form. Default="qualified" attribute. Form. Default="qualified">. . . </schema> 16

Section 02 XML 스키마 사용법 요소 선언과 요소 타입 정의 요소 정의 <element abstract = boolean : false block = (#all | List of (extension | restriction | substitution)) default = string final = (#all | List of (extension | restriction)) fixed = string form = (qualified | unqualified) id = ID max. Occurs = (non. Negative. Integer | unbounded) : 1 min. Occurs = non. Negative. Integer : 1 name = NCName nillable = boolean : false ref = QName substitution. Group = QName type = QName {any attributes with non-schema namespace. . . }> Content: (annotation? , ((simple. Type | complex. Type)? , (unique | keyref)*)) </element> 17


Section 02 XML 스키마 사용법 단순 데이터 타입 <simple. Type> 요소 사용해서 정의 XML 스키마에서 정의한 다른 단순 데이터 타입을 이용해서 정의 가능 내부에 다른 요소나 속성을 포함할 수는 없다. restriction, list, union 이용해서 확장 가능 simple. Type 요소 정의 형식 <simple. Type final = (#all | (list | union | restriction)) id = ID name = NCName {any attributes with non-schema namespace. . . }> Content: (annotation? , (restriction | list | union)) </simple. Type> 19

Section 02 XML 스키마 사용법 제한 요소 정의와 사용 새로운 단순 데이터 타입은 기존의 단순 데이터 타입이 가질 수 있 는 값의 범위를 제한해서 정의할 수 있다. restriction 요소 정의 형식 <restriction base = QName id = ID {any attributes with non-schema namespace. . . }> Content: (annotation? , (simple. Type? , (min. Exclusive | min. Inclusive | max. Exclusive | max. Inclusive | total. Digits | fraction. Digits | length | min. Length | max. Length | enumeration | white. Space | pattern)*)) </restriction> 20



Section 02 XML 스키마 사용법 복합 데이터 타입 요소를 정의하고 사용기 위해서 기본적으로 복합 데이터 타입 (complex. Type)을 정의해서 사용 자식 요소나 속성을 필요로 하는 요소를 정의하기 위해서는 복합 데이터 타입으로 정의한다. 형식 <complex. Type abstract = boolean : false block = (#all | List of (extension | restriction)) final = (#all | List of (extension | restriction)) id = ID mixed = boolean : false name = NCName {any attributes with non-schema namespace. . . }> Content: (annotation? , (simple. Content | complex. Content | ((group | all | choice | sequence)? , ((attribute | attribute. Group)*, any. Attribute? )))) </complex. Type> 23

Section 02 XML 스키마 사용법 순차 요소 정의와 사용 DTD의 컴마(, ) 연산자에 해당 자식 요소들이 순서대로 나타나야 하는 경우 사용 • <sequence> 요소: 발생 횟수 표현, "max. Occurs" 와 "min. Occurs" 속성을 가지고 있다. 만일, 이 속성들을 정해주지 않을 경우에는 기본값 1로 사용 형식 <sequence id = ID max. Occurs = (non. Negative. Integer | unbounded) : 1 min. Occurs = non. Negative. Integer : 1 {any attributes with non-schema namespace. . . }> Content: (annotation? , (element | group | choice | sequence | any)*) </sequence> 24

Section 02 XML 스키마 사용법 선택 요소 정의와 사용 choice은 여러 개의 자식 요소중에서 선택적으로 요소를 정의하는 것 자식 요소의 발생 횟수를 지정하기 위해서 "max. Occurs" 와 "min. Occurs" 속성을 가지고 있다. 형식 <choice id = ID max. Occurs = (non. Negative. Integer | unbounded) : 1 min. Occurs = non. Negative. Integer : 1 {any attributes with non-schema namespace. . . }> Content: (annotation? , (element | group | choice | sequence | any)*) </choice> 25



Section 02 XML 스키마 사용법 속성 선언 속성은 어떤 자식 정보 항목도 포함할 수 없다. 즉, 복합 데이터 타 입으로 정의할 수 없다. 속성은 순서가 없다. 형식 <attribute default = string fixed = string form = (qualified | unqualified) id = ID name = NCName ref = QName type = QName use = (optional | prohibited | required) : optional {any attributes with non-schema namespace. . . }> Content: (annotation? , (simple. Type? )) </attribute> 28

Section 02 XML 스키마 사용법 속성 그룹 정의 속성 선언들을 그룹으로 묶어서 이름을 지정해 주는 것 여러 요소가 동일한 속성 집합을 지니고 있을 때 유용 형식 <attribute. Group id = ID name = NCName ref = QName {any attributes with non-schema namespace. . . }> Content: (annotation? , ((attribute | attribute. Group)*, any. Attribute? )) </attribute. Group> 속성 그룹은 반드시 <attribute. Group> 요소를 사용하여 전역으로 정의해야 함 29


Section 02 XML 스키마 사용법 XML 스키마 주석 형식 <annotation id = ID {any attributes with non-schema namespace. . . }> Content: (appinfo | documentation)* </annotation> <appinfo source = any. URI> Content: ({any})* </appinfo> <documentation source = any. URI xml: lang = language> Content: ({any})* </documentation> 31


Thank you