임성신 e-mail : [email protected] basic xml, dtd & schema

59
임임임 임임임 E-mail : [email protected] E-mail : [email protected] Basic XML, Basic XML, DTD & Schema DTD & Schema

Upload: shannon-cross

Post on 27-Dec-2015

233 views

Category:

Documents


2 download

TRANSCRIPT

임성신임성신

E-mail : [email protected] : [email protected]

Basic XML, Basic XML, DTD & SchemaDTD & Schema

[email protected]@hotmail.com

XMLXML 의 필요성의 필요성 오늘날 문서 데이터의 요구사항오늘날 문서 데이터의 요구사항

사람과 시스템이 모두 읽을 수 있는 형태사람과 시스템이 모두 읽을 수 있는 형태데이터의 내용과 구조를 정의데이터의 내용과 구조를 정의관계설정관계설정자료의 구조와 보여주는 부분의 분리 자료의 구조와 보여주는 부분의 분리 개방성 및 확장성개방성 및 확장성

XMLXML 은 위의 요구사항을 지원한다은 위의 요구사항을 지원한다 !!!!

[email protected]@hotmail.com

XMLXML 태그를 이용한 데이터의 표현태그를 이용한 데이터의 표현 문서는 세가지 요소로 구성됨문서는 세가지 요소로 구성됨

XML XML 문서는 문서의 내용에 대한 구조적인 문서는 문서의 내용에 대한 구조적인 정보를 가지고 있음정보를 가지고 있음

XML XML 문서는 출력에 관한 내용은 정의하지 문서는 출력에 관한 내용은 정의하지 않음않음

구조 출력자료

[email protected]@hotmail.com

XMLXML 의 역사와의 역사와 W3CW3C

XMLXML 은 은 SGMLSGML 의 의 SubsetSubset 형태이다형태이다 ..Standard Generalized Markup LanguageStandard Generalized Markup Language19861986 년에 년에 ISOISO 표준으로 정의표준으로 정의

XMLXML 은 은 World Wide Web Consortium World Wide Web Consortium (W3C)(W3C) 에 의해 표준화에 의해 표준화http://www.w3.orghttp://www.w3.org

[email protected]@hotmail.com

XML(eXtensible Markup Language)XML(eXtensible Markup Language) 웹 상에서 구조화된 문서를 전송하도록 설계된 마크업 웹 상에서 구조화된 문서를 전송하도록 설계된 마크업

언어언어 19961996 년 년 W3C(World Wide Web Consortium)W3C(World Wide Web Consortium) 에서 제안에서 제안 SGMLSGML 에 기반을 둔 단순하고에 기반을 둔 단순하고 , , 매우 유연성 있는 매우 유연성 있는 texttext

형식형식 논리논리 // 내용 구조와 표현을 분리내용 구조와 표현을 분리 사용자 임의의 구조정의사용자 임의의 구조정의 -- 자유로운 자유로운 elementelement 와 와

attributeattribute 정의정의 HTML(HyperText Markup Language)HTML(HyperText Markup Language) 의 단점을 의 단점을

해결하고 해결하고 SGML(Standard Generalized Markup SGML(Standard Generalized Markup Language)Language) 의 복잡함을 해결하기 위한 방안으로 제시의 복잡함을 해결하기 위한 방안으로 제시

19981998 년 년 22 월 월 W3CW3C 에 의해 에 의해 XML1.0XML1.0 에 대한 표준규약 에 대한 표준규약 제정제정

[email protected]@hotmail.com

XMLXML 의 취지의 취지 최근에 들어와서는 정보의 양이 급격히 최근에 들어와서는 정보의 양이 급격히

증가하고 인터넷이 대중화되면서 다음의 증가하고 인터넷이 대중화되면서 다음의 두 가지 성과를 통합할 필요성이 점차 강조 두 가지 성과를 통합할 필요성이 점차 강조 되고 있음되고 있음정보를 표준화된 형태로 저장해 그 활용도를 정보를 표준화된 형태로 저장해 그 활용도를

증대 시키는 것증대 시키는 것이를 웹 환경을 통해 제공함으로써 대중성을 이를 웹 환경을 통해 제공함으로써 대중성을

확보하는 것확보하는 것

[email protected]@hotmail.com

XML XML 표준 제정 동기표준 제정 동기 9090 년 이후 기업간 합병에 따른 저비용 시스템의 년 이후 기업간 합병에 따른 저비용 시스템의

통합의 필요통합의 필요 인터넷 페이지 증가에 따른 인터넷 페이지 증가에 따른 HTMLHTML 의 구조 의 구조

검색의 한계 검색의 한계 SGMLSGML 의 개발 및 사용의 한계 의 개발 및 사용의 한계 OS, H/W OS, H/W 시스템시스템 , , 특정 특정 BandBand 의 문서 포멧에 의 문서 포멧에

대한 국제적인 독립적인 문서 포멧에 대한 요구대한 국제적인 독립적인 문서 포멧에 대한 요구 소프트웨어 개발 용이소프트웨어 개발 용이 , , 문서작성 용이문서작성 용이 , , 저장 저장

용의용의 , , 관리 용이관리 용이 , , 전송 용이전송 용이 , , 인터넷 서비스에 인터넷 서비스에 용이한 문서 필요용이한 문서 필요

다양한 형식으로 변환이 가능한 문서 필요다양한 형식으로 변환이 가능한 문서 필요

[email protected]@hotmail.com

XMLXML 의 특징의 특징

Logical View

Layout View

내용 (Content) 형식 (Style)+

DataData 로서 의미를 지님로서 의미를 지님 다양한 사용자 뷰다양한 사용자 뷰 ((View)View) 제공제공

“XML is a breakthrough technology” - Bill Gates -

[email protected]@hotmail.com

XMLXML 의 특징의 특징eXtensible Markup Language

문서의 내용과 형식의 분리

DTD /XML Schema

XSL

구조화된 문서

태그언어

[email protected]@hotmail.com

XML in Community-SpecificXML in Community-Specific

[email protected]@hotmail.com

XML EverywhereXML Everywhere

[email protected]@hotmail.com

XMLXML 문서 생성문서 생성 Element & AttributeElement & Attribute XML XML 문법문법 XML XML 문서의 구성문서의 구성 XML XML 문서의 구조문서의 구조 Well-Formed XML Well-Formed XML 문서 생성문서 생성 ElementElement 와 와 AttributeAttribute 의 사용의 사용

[email protected]@hotmail.com

Element & AttributeElement & Attribute▣▣ Element(Element( 요소요소 ) ) 하나의 하나의 ElementElement 는 는 Start-Tags/Contents/End-TagsStart-Tags/Contents/End-Tags 로 구성로 구성 ..

<<greeting>greeting> ---------------- ----------------Start-TagsStart-Tags

Hello, XML! ------------Contents(Hello, XML! ------------Contents( 데이터데이터 ))

<<//greeting>greeting> ---------------- ----------------End-TagsEnd-Tags

※ ※ EMPTY Element (EMPTY Element ( 빈요소빈요소 ))

<<tag/>tag/> 로 표시로 표시 . . htmlhtml 에 경우 에 경우 <<br><hr>br><hr> 등등

▣▣ Attribute(Attribute( 속성속성 ) ) <<tag tag attributeattribute==”value””value”>XML >XML 테스트테스트 </</tag>tag>

속성이름 속성이름 = “= “value”value” 로 로 htmlhtml 과 달리 “ ” 나 ‘ ’로 하여야 한다과 달리 “ ” 나 ‘ ’로 하여야 한다 ..

[email protected]@hotmail.com

XML XML 문법문법 XML XML 은 데이터를 설명하기 의해 태그를 은 데이터를 설명하기 의해 태그를

사용사용 정보를 나타내는 기본 요소의 표현 방식정보를 나타내는 기본 요소의 표현 방식

하위요소 포함 가능하위요소 포함 가능

Lars PetersonLars Peterson </name></name>

Element content End tagStart tag

<employee> <name>Lars Peterson</name> <salary>25000</salary></employee>

<employee> <name>Lars Peterson</name> <salary>25000</salary></employee>

<name><name>

[email protected]@hotmail.com

XML XML 문서의 구성문서의 구성

<employee>

</employee>

<employee>

</employee>

<name>Lars Peterson</name>

<!-- This is a comment --><!-- This is a comment -->

<?xml version="1.0"?><?xml version="1.0"?>

<permanent_staff />

<salary> 25000 </salary>

<salary currency="US$"> 25000 </salary>

Comment

Root element Child element

Empty element Attribute

Processinginstruction

[email protected]@hotmail.com

XML XML 문서의 구조문서의 구조 PrologProlog

XML XML 선언선언DTD DTD 또는 또는 XML sXML schemachema ( ( 문법의 정의문법의 정의 ))

상위 상위 element element 는 다른 는 다른 elementelement 를 포함를 포함

<?xml version="1.0"?><!DOCTYPE employees SYSTEM "employees.dtd">

<?xml version="1.0"?><!DOCTYPE employees SYSTEM "employees.dtd">

<employee> <name>Lars Peterson</name> ...</employee>

<employee> <name>Lars Peterson</name> ...</employee>

[email protected]@hotmail.com

Well-Formed XMLWell-Formed XML 문서 생성문서 생성 WWell-formed ell-formed 문서의 요구사항문서의 요구사항

단일단일 , , 유일한 상위유일한 상위 elementelement시작시작 // 끝끝 tagstags 의 일치의 일치대소문자 구분대소문자 구분ElementElement 들간의들간의 올바른 올바른 nestingnestingAttributeAttribute 는 인용부호를 사용는 인용부호를 사용하나의 하나의 elementelement 에서 속성을 반복하여 에서 속성을 반복하여

사용하지 않음 사용하지 않음 ValidValid 문서의 요구사항문서의 요구사항

[email protected]@hotmail.com

XML XML 용어 용어 Style sheets

Document Object Model (DOM)

Validation

Data binding

XML

[email protected]@hotmail.com

XML XML 처리 시스템 구성도처리 시스템 구성도

[email protected]@hotmail.com

XML XML 문서의 유효성문서의 유효성 ValidationValidation 의 필요성의 필요성 Well-Formed Well-Formed 과과 Valid DocumentsValid Documents Validating Validating 기술기술 : DTD: DTD 와와 XML XML

SchemasSchemas

[email protected]@hotmail.com

ValidationValidation 의 필요성의 필요성 ValidationValidation 은 은 XML XML 문서를 원하는 형식에 문서를 원하는 형식에

맞게 작성맞게 작성 // 교환 할 수 있도록 한다교환 할 수 있도록 한다 ..올바른 올바른 elementelement 와 와 attributesattributeselementelement 와 와 attributeattribute 의 관계정의의 관계정의하부 하부 ElementElement 의 숫자와 순서 정의의 숫자와 순서 정의데이터 형식데이터 형식 (XML (XML schemaschema 에서 언급에서 언급 ))

[email protected]@hotmail.com

Well-Formed Well-Formed 와와 Valid Valid 문서문서 Well-Formed Well-Formed XML XML 문서문서

XMLXML 의 기본문법 준수의 기본문법 준수elements/attributeselements/attributes 의 조합으로 구성의 조합으로 구성 ““ 문법문법”” 을 가지고 있음을 가지고 있음

Valid XML Valid XML 문서문서well formed well formed 문서문서Document Type Definition (DDocument Type Definition (DTDTD) )

또는 또는 XML schemaXML schema 로 정의로 정의DTD/XML schemaDTD/XML schema 로 정의 된 문법사용로 정의 된 문법사용

[email protected]@hotmail.com

Validating Validating 기술기술 :DTD:DTD 와와 XML XML SchemaSchema

DTD XML schema

다른 구현 방식

XML 기본 문법

표준으로 정착

Parser 가 지원

제한점

표준으로 정착

기능이 풍부

[email protected]@hotmail.com

DTDDTD(Document Type (Document Type

Definition)Definition)

[email protected]@hotmail.com

DTD DTD 예 예

[email protected]@hotmail.com

<! keyword name content >

1 2 3 4

1. 모 든 DTD 의 시 작 은 markup declaration open delimiter(MDO) 인 '<!' 로 한다 . 2. 마크업 선언 유형에 따라서 ELEMENT, ATTLIST, ENTITY, NOTATION 와 같은 키워드를 선언한다 . 대문자 (uppercase)로 꼭 표기해야 한다 .3. 선언하고자 하는 이름과 내용을 기입한다 . 이름의 정의하는 방법은 XML 문서에서의 요소 (element), 속성 (attribute) 생성 규칙과 동일하다 .4. 모든 DTD 의 끝은 markup declaration close delimiter(MDC) 인 '>' 로 닫아준다 .

마크업 선언마크업 선언 (markup declaration)(markup declaration)

[email protected]@hotmail.com

1. 요소 선언은 <!ELEMENT 로 한다 .2. 요소이름은 XML 요소이름 명명과 같다 .3. 요소 유형을 지정한다 .4. > 로 요소 선언을 종료한다 .

<!ELEMENT 요소이름 요소유형 >

1 2 3 4

요소유형 : Children | EMPTY | MIXED | ANY Children : 자식 요소 (child element) 를 포함한다 . EMPTY : 어떤 자식 요소 (child element) 도 포함할 수 없다 .MIXED : 일반 텍스트형태 (#PCDATA) 와 자식 요소 (child element) 를 포함 .ANY : 어떤 유형의 요소 (element) 도 포함할 수 있다 . 보통 ROOT 에서 사용 .

요소요소 (Element) (Element) 선언 선언

[email protected]@hotmail.com

Connector

 | => 선택적인 자식요소 선언<!ELEMENT choice (one|two)>

<choice><one>Test</one></choice> (O)

<choice><two>Test</two></choice> (O)

 

, => 순차적인 자식요소 선언<!ELEMENT seq (one, two)>

<seq><one>Test-one</one><two>Test-two</two></seq> (O)

<seq><two>Test-two</two><one>Test-one</one></seq> (X)

요소요소 (Element) (Element) 생성 규칙생성 규칙

[email protected]@hotmail.com

Indicator

 ? => 한번 나타나거나 한번도 나타나지 않는 요소 선언 <!ELEMENT choice (option?)>

<choice><option> 선택 </option></choice> (O)

<choice> 선택 </choice> (O)

 

* => 0 회 이상 반복되는 요소 선언 <!ELEMENT mult (no*)>

<!ELEMENT no (#PCDATA)>

<mult><no>1</no><no>2</no></mult> (O)

<mult /> (O)

[email protected]@hotmail.com

 + => 1 회 이상 반복되는 요소 선언 <!ELEMENT mult (no+)>

<!ELEMENT no (#PCDATA)>

<mult><no>1</no><no>2</no></mult> (O)

<mult /> (X)

 

( ) => 자식 요소들의 그룹 지정 <!ELEMENT node ( (A | B), C)>

<!ELEMENT A (#PCDATA)>

<!ELEMENT B (#PCDATA)>

<!ELEMENT C (#PCDATA)>

<node>

<A>1</A><C>2</C>

</node>

[email protected]@hotmail.com

1. 속성 선언은 <!ATTLIST 로 한다 .2. 요소이름은 속성이 부여될 XML 요소이름을 지정 .3. 속성이름을 지정 .4. 속성의 유형을 지정 .5. > 로 속성 선언을 종료 .

▣ 속성 유형 CDATA Enumeration( 나열형식 ) ID IDREF IDREFSENTITY ENTITIES NMTOKEN NMTOKENS NOTATION

>

5

<!ATTLIST 요소이름 속성 유형

1 2 4

속성이름

3

속성속성 (Attribute)(Attribute)

[email protected]@hotmail.com

DTDDTD 의 한계의 한계 제대로 된 제대로 된 DTDDTD 를 만들기가 어렵다를 만들기가 어렵다 .. DTDDTD 는 확장할 수 없다는 확장할 수 없다 .. DTDDTD 는 데이터로서의 는 데이터로서의 XMLXML 을 제대로 기술하지 을 제대로 기술하지

못한다못한다 .. DTDDTD 는 이름공간는 이름공간 (Namespace)(Namespace) 를 제대로 를 제대로

지원하지 못한다지원하지 못한다 .. DTDDTD 는 기술는 기술 (description)(description) 능력에 한계가 있다능력에 한계가 있다 .. DTDDTD 에는 기본 요소 내용에 대한 기능이 없다에는 기본 요소 내용에 대한 기능이 없다 ..

[email protected]@hotmail.com

SchemaSchema

[email protected]@hotmail.com

What is XML Schemas?What is XML Schemas?

Answer: An XML vocabulary for Answer: An XML vocabulary for expressing your data's business rulesexpressing your data's business rules

[email protected]@hotmail.com

Validating your dataValidating your data

<location> <latitude>32.904237</latitude> <longitude>73.620290</longitude> <uncertainty units="meters">2</uncertainty></location>

-check that the latitude is between -90 and +90-check that the longitude is between -180 and +180- check that the fraction digits is 6 for lat and lon...

XML Schema

XML Schemavalidator

Data is ok!

[email protected]@hotmail.com

Purpose of XML Schemas (and Purpose of XML Schemas (and DTDs)DTDs) Specify:Specify:

the the structurestructure of instance documents of instance documents "this element contains these elements, which "this element contains these elements, which

contains these other elements, etc"contains these other elements, etc"

the the datatypedatatype of each element/attribute of each element/attribute "this element shall hold an integer with the "this element shall hold an integer with the

range 0 to 12,000" (DTDs don't do too well with range 0 to 12,000" (DTDs don't do too well with specifying datatypes like this)specifying datatypes like this)

[email protected]@hotmail.com

People are dissatisfied with DTDsPeople are dissatisfied with DTDs It's a different syntaxIt's a different syntax

You write your XML (instance) document using one You write your XML (instance) document using one syntax and the DTD using another syntax --> bad, syntax and the DTD using another syntax --> bad, inconsistentinconsistent

Limited datatype capabilityLimited datatype capability DTDs support a very limited capability for specifying DTDs support a very limited capability for specifying

datatypes. You can't, for example, express "I want datatypes. You can't, for example, express "I want the <elevation> element to hold an integer with a the <elevation> element to hold an integer with a range of 0 to 12,000"range of 0 to 12,000"

Desire a set of datatypes compatible with those Desire a set of datatypes compatible with those found in databasesfound in databases

DTD supports 10 datatypes; XML Schemas DTD supports 10 datatypes; XML Schemas supports 44+ datatypessupports 44+ datatypes

Motivation for XML SchemasMotivation for XML Schemas

[email protected]@hotmail.com

Highlights of XML SchemasHighlights of XML Schemas XML Schemas are a tremendous advancement over DTDs:XML Schemas are a tremendous advancement over DTDs:

Enhanced datatypes Enhanced datatypes 44+ versus 1044+ versus 10 Can create your own datatypesCan create your own datatypes

Written in the same syntax as instance documentsWritten in the same syntax as instance documents less syntax to rememberless syntax to remember

Object-oriented'ishObject-oriented'ish Can extend or restrict a type (derive new type definitions on the basis of old Can extend or restrict a type (derive new type definitions on the basis of old

ones)ones) Can express sets, i.e., can define the child elements to occur in any orderCan express sets, i.e., can define the child elements to occur in any order Can specify element content as being unique (keys on content) and uniqueness Can specify element content as being unique (keys on content) and uniqueness

within a regionwithin a region Can define multiple elements with the same name but different contentCan define multiple elements with the same name but different content Can define elements with nil contentCan define elements with nil content Can define substitutable elements - e.g., the "Book" element is substitutable for Can define substitutable elements - e.g., the "Book" element is substitutable for

the "Publication" element.the "Publication" element.

[email protected]@hotmail.com

Classic use of XML SchemasClassic use of XML Schemas(Trading Partners - B2B)(Trading Partners - B2B)

Supplier Consumer

P.O.

SchemaValidator

P.O.Schema

Softwareto Process

P.O.

"P.O. isokay" P.O.

(Schema at third-party, neutral web site)

[email protected]@hotmail.com

Let's Get Started!Let's Get Started!

Convert the BookStore.dtd (next page) Convert the BookStore.dtd (next page) to the XML Schema syntaxto the XML Schema syntax for this first example we will make a for this first example we will make a

straight, one-to-one conversion, i.e., Title, straight, one-to-one conversion, i.e., Title, Author, Date, ISBN, and Publisher will hold Author, Date, ISBN, and Publisher will hold strings, just like is done in the DTDstrings, just like is done in the DTD

We will gradually modify the XML Schema We will gradually modify the XML Schema to use stronger typesto use stronger types

[email protected]@hotmail.com

BookStore.dtdBookStore.dtd

<!ELEMENT BookStore (Book)+><!ELEMENT Book (Title, Author, Date, ISBN, Publisher)><!ELEMENT Title (#PCDATA)><!ELEMENT Author (#PCDATA)><!ELEMENT Date (#PCDATA)><!ELEMENT ISBN (#PCDATA)><!ELEMENT Publisher (#PCDATA)>

[email protected]@hotmail.com

ATTLISTELEMENT

ID

#PCDATA

NMTOKEN

ENTITY

CDATA

BookStore

BookTitle

Author

Date

ISBNPublisher

This is the vocabulary that DTDs provide to define yournew vocabulary

[email protected]@hotmail.com

elementcomplexType

schema

sequence

http://www.w3.org/2001/XMLSchema

string

integer

boolean

BookStore

BookTitle

Author

Date

ISBNPublisher

http://www.books.org (targetNamespace)

This is the vocabulary that XML Schemas provide to define yournew vocabulary

One difference between XML Schemas and DTDs is that the XML Schema vocabularyis associated with a name (namespace). Likewise, the new vocabulary that you define must be associated with a name (namespace). With DTDs neither set ofvocabulary is associated with a name (namespace) [because DTDs pre-dated namespaces].

[email protected]@hotmail.com

<?xml version="1.0"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="BookStore"> <xsd:complexType> <xsd:sequence> <xsd:element ref="Book" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="Book"> <xsd:complexType> <xsd:sequence> <xsd:element ref="Title" minOccurs="1" maxOccurs="1"/> <xsd:element ref="Author" minOccurs="1" maxOccurs="1"/> <xsd:element ref="Date" minOccurs="1" maxOccurs="1"/> <xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/> <xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="Title" type="xsd:string"/> <xsd:element name="Author" type="xsd:string"/> <xsd:element name="Date" type="xsd:string"/> <xsd:element name="ISBN" type="xsd:string"/> <xsd:element name="Publisher" type="xsd:string"/></xsd:schema>

BookStore.xsd (see example01)xsd = Xml-Schema Definition

(explanations onsucceeding pages)

[email protected]@hotmail.com

<?xml version="1.0"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="BookStore"> <xsd:complexType> <xsd:sequence> <xsd:element ref="Book" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="Book"> <xsd:complexType> <xsd:sequence> <xsd:element ref="Title" minOccurs="1" maxOccurs="1"/> <xsd:element ref="Author" minOccurs="1" maxOccurs="1"/> <xsd:element ref="Date" minOccurs="1" maxOccurs="1"/> <xsd:element ref="ISBN" minOccurs="1" maxOccurs="1"/> <xsd:element ref="Publisher" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="Title" type="xsd:string"/> <xsd:element name="Author" type="xsd:string"/> <xsd:element name="Date" type="xsd:string"/> <xsd:element name="ISBN" type="xsd:string"/> <xsd:element name="Publisher" type="xsd:string"/></xsd:schema>

<!ELEMENT Title (#PCDATA)><!ELEMENT Author (#PCDATA)><!ELEMENT Date (#PCDATA)><!ELEMENT ISBN (#PCDATA)><!ELEMENT Publisher (#PCDATA)>

<!ELEMENT Book (Title, Author, Date, ISBN, Publisher)>

<!ELEMENT BookStore (Book)+>

[email protected]@hotmail.com

Default Value for minOccurs and Default Value for minOccurs and maxOccursmaxOccurs

The default value for minOccurs is "1"The default value for minOccurs is "1" The default value for maxOccurs is "1"The default value for maxOccurs is "1"

<xsd:element ref="Title" minOccurs="1" maxOccurs="1"/>

<xsd:element ref="Title"/>

Equivalent!

Do Lab1

[email protected]@hotmail.com

Anonymous types

<?xml version="1.0"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="BookStore"> <xsd:complexType> <xsd:sequence> <xsd:element name="Book" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="Title" type="xsd:string"/> <xsd:element name="Author" type="xsd:string"/> <xsd:element name="Date" type="xsd:string"/> <xsd:element name="ISBN" type="xsd:string"/> <xsd:element name="Publisher" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element></xsd:schema>

[email protected]@hotmail.com

Using <sequence> and <choice>Using <sequence> and <choice>

<?xml version="1.0"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="life"> <xsd:complexType> <xsd:sequence minOccurs="0" maxOccurs="unbounded"> <xsd:sequence minOccurs="0" maxOccurs="unbounded"> <xsd:element name="work" type="xsd:string"/> <xsd:element name="eat" type="xsd:string"/> </xsd: sequence> <xsd:choice> <xsd:element name="work" type="xsd:string"/> <xsd:element name="play" type="xsd:string"/> </xsd:choice> <xsd:element name="sleep" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element></xsd:schema>

<!ELEMENT life ((work, eat)*, (work | play), sleep)* >DTD:

XML Schema:

[email protected]@hotmail.com

Summary of Declaring Summary of Declaring Elements (two ways to do it)Elements (two ways to do it)<xsd:element name="name" type="type" minOccurs="int" maxOccurs="int"/>

A simple type(e.g., xsd:string)or the name ofa complexType(e.g., BookPublication)

<xsd:element name="name" minOccurs="int" maxOccurs="int"> <xsd:complexType> … </xsd:complexType></xsd:element>

1

2

A nonnegativeinteger

A nonnegativeinteger or "unbounded"

Note: minOccurs and maxOccurs can only be used in nested (local) element declarations.

[email protected]@hotmail.com

Built-in DatatypesBuilt-in Datatypes

Primitive DatatypesPrimitive Datatypes stringstring booleanboolean decimaldecimal floatfloat doubledouble durationduration dateTimedateTime timetime datedate gYearMonthgYearMonth gYeargYear gMonthDaygMonthDay

Atomic, built-inAtomic, built-in ""Hello WorldHello World"" {{truetrue, , falsefalse}} 7.087.08 12.56E312.56E3, , 1212, , 1256012560,, 0 0, , -0-0, , INFINF, , -INF-INF, , NANNAN 12.56E312.56E3, , 1212, , 1256012560,, 0 0, , -0-0, , INFINF, , -INF-INF, , NANNAN P1Y2M3DT10H30M12.3SP1Y2M3DT10H30M12.3S format:format: CCYY-MM-DDThh-mm-ssCCYY-MM-DDThh-mm-ss format:format: hh:mm:ss.ssshh:mm:ss.sss format:format: CCYY-MM-DDCCYY-MM-DD format:format: CCYY-MMCCYY-MM format:format: CCYYCCYY format:format: -- --MM-DDMM-DD

Note: 'T' is the date/time separator INF = infinity NAN = not-a-number

[email protected]@hotmail.com

Built-in Datatypes (cont.)Built-in Datatypes (cont.) Primitive DatatypesPrimitive Datatypes

gDaygDay gMonthgMonth hexBinary hexBinary base64Binarybase64Binary anyURIanyURI QNameQName NOTATIONNOTATION

Atomic, built-inAtomic, built-in format:format: --- ---DD DD (note the 3 dashes)(note the 3 dashes) format:format: -- --MM--MM-- a hex stringa hex string a base64 stringa base64 string http://www.xfront.comhttp://www.xfront.com a namespace qualified namea namespace qualified name a NOTATION from the XML speca NOTATION from the XML spec

[email protected]@hotmail.com

Derived typesDerived types normalizedStringnormalizedString tokentoken languagelanguage IDREFSIDREFS ENTITIESENTITIES NMTOKENNMTOKEN NMTOKENSNMTOKENS NameName NCNameNCName IDID IDREFIDREF ENTITYENTITY integerinteger nonPositiveIntegernonPositiveInteger

Subtype of primitive datatypeSubtype of primitive datatype A string without tabs, line feeds, or carriage returnsA string without tabs, line feeds, or carriage returns

String w/o tabs, l/f, leading/trailing spaces, consecutive spacesString w/o tabs, l/f, leading/trailing spaces, consecutive spaces

any valid xml:lang value, e.g.,any valid xml:lang value, e.g., ENEN, , FRFR, ..., ... must be used only with attributesmust be used only with attributes must be used only with attributesmust be used only with attributes must be used only with attributesmust be used only with attributes must be used only with attributesmust be used only with attributes

partpart (no namespace qualifier)(no namespace qualifier) must be used only with attributesmust be used only with attributes must be used only with attributesmust be used only with attributes must be used only with attributesmust be used only with attributes 456456 negative infinity to 0negative infinity to 0

Built-in Datatypes (cont.)Built-in Datatypes (cont.)

[email protected]@hotmail.com

Built-in Datatypes (cont.)Built-in Datatypes (cont.)

Derived typesDerived types negativeIntegernegativeInteger longlong int int shortshort bytebyte nonNegativeIntegernonNegativeInteger unsignedLongunsignedLong unsignedIntunsignedInt unsignedShortunsignedShort unsignedByteunsignedByte positiveIntegerpositiveInteger

Subtype of primitive datatypeSubtype of primitive datatype negative infinity to -1negative infinity to -1 -9223372036854775808-9223372036854775808 toto 9223372036854775808 9223372036854775808 -2147483648-2147483648 toto 21474836472147483647 -32768-32768 toto 3276732767 -127-127 toto 128128 0 to infinity0 to infinity 00 toto 1844674407370955161518446744073709551615 00 toto 42949672954294967295 00 toto 6553565535 00 toto 255255 1 1 to infinityto infinity

Note: the following types can only be used with attributes (which we will discuss later): ID, IDREF, IDREFS, NMTOKEN, NMTOKENS, ENTITY, and ENTITIES.

[email protected]@hotmail.com

AttributesAttributes

On the next slide I show a version of On the next slide I show a version of the BookStore DTD that uses attributes. the BookStore DTD that uses attributes. Then, on the following slide I show Then, on the following slide I show how this is implemented using XML how this is implemented using XML Schemas.Schemas.

[email protected]@hotmail.com

<!ELEMENT BookStore (Book)+><!ELEMENT Book (Title, Author+, Date, ISBN, Publisher)><!ATTLIST Book Category (autobiography | non-fiction | fiction) #REQUIRED InStock (true | false) "false" Reviewer CDATA " "><!ELEMENT Title (#PCDATA)><!ELEMENT Author (#PCDATA)><!ELEMENT Date (#PCDATA)><!ELEMENT ISBN (#PCDATA)><!ELEMENT Publisher (#PCDATA)><!ELEMENT Month (#PCDATA)><!ELEMENT Year (#PCDATA)>

BookStore.dtd

[email protected]@hotmail.com

<xsd:element name="BookStore"> <xsd:complexType> <xsd:sequence> <xsd:element name="Book" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="Title" type="xsd:string"/> <xsd:element name="Author" type="xsd:string" maxOccurs="unbounded"/> <xsd:element name="Date" type="xsd:string"/> <xsd:element name="ISBN" type="xsd:string"/> <xsd:element name="Publisher" type="xsd:string"/> </xsd:sequence> <xsd:attributeGroup ref="BookAttributes"/> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:attributeGroup name="BookAttributes"> <xsd:attribute name="Category" use="required"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:enumeration value="autobiography"/> <xsd:enumeration value="non-fiction"/> <xsd:enumeration value="fiction"/> </xsd:restriction> </xsd:simpleType> </xsd:attribute> <xsd:attribute name="InStock" type="xsd:boolean" default="false"/> <xsd:attribute name="Reviewer" type="xsd:string" default=" "/> </xsd:attributeGroup>

InStock (true | false) "false"

Reviewer CDATA " "

Category (autobiography | non-fiction | fiction) #REQUIRED

[email protected]@hotmail.com

<xsd:attribute name="Category" use="required"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:enumeration value="autobiography"/> <xsd:enumeration value="non-fiction"/> <xsd:enumeration value="fiction"/> </xsd:restriction> </xsd:simpleType></xsd:attribute>

"Instance documents are required to have the Category attribute(as indicated by use="required"). The value of Category must be either autobiography, non-fiction, or fiction (as specified by theenumeration facets)."

Note: attributes can only have simpleTypes (i.e., attributes cannothave child elements).

[email protected]@hotmail.com

Summary of Declaring Summary of Declaring Attributes (two ways to do it)Attributes (two ways to do it)<xsd:attribute name="name" type="simple-type" use="how-its-used" default/fixed="value"/>

requiredoptionalprohibited

Do not use the "use"attribute if you use eitherdefault or fixed.

xsd:stringxsd:integerxsd:boolean...

<xsd:attribute name="name" use="how-its-used" default/fixed="value"> <xsd:simpleType> <xsd:restriction base="simple-type"> <xsd:facet value="value"/> … </xsd:restriction> </xsd:simpleType></xsd:attribute>

1

2

[email protected]@hotmail.com

MSXML ParserMSXML Parser 를 사용할 경우는 를 사용할 경우는 4.04.0 으로 업그레이드 해야 한다으로 업그레이드 해야 한다 ..그리고 그리고 MSXML2.DOMDocument.4.0 MSXML2.DOMDocument.4.0 객체 생성 후 테스트 해야 함객체 생성 후 테스트 해야 함 ..