Basic XML, DTD & Schema.

Slides:



Advertisements
Similar presentations
17 Apr 2002 XML Syntax: DTDs Andy Clark. Validation of XML Documents XML documents must be well-formed XML documents may be valid – Validation verifies.
Advertisements

4 XML Schema.
1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
XML 6.5 XML Schema (XSD) 6. What is XML Schema? The origin of schema  XML Schema documents are used to define and validate the content and structure.
1 XML DTD & XML Schema Monica Farrow G30
SDPL 2003Notes 2: Document Instances and Grammars1 2.5 XML Schemas n A quick introduction to XML Schema –W3C Recommendation, May 2, 2001: »XML Schema Part.
An Introduction to XML Schema CSCI 7818 by Ming Rutar.
CSE 636 Data Integration XML Schema. 2 XML Schemas W3C Recommendation: Generalizes DTDs Uses XML syntax Two documents: structure.
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
XML Schemas Lecture 10, 07/10/02. Acknowledgements A great portion of this presentation has been borrowed from Roger Costello’s excellent presentation.
XML Simple Types CSPP51038 shortcourse. Simple Types Recall that simple types are composed of text-only values. All attributes are of simple type Elements.
1 XML Schemas Marco Mesiti This Presentation has been extracted from Roger L. Costello (XML Technologies Course)
XML Schemas and Namespaces Lecture 11, 07/10/02. BookStore.dtd.
ΑΝΑΠΑΡΑΣΤΑΣΗ ΓΝΩΣΗΣ ΣΤΟΝ ΠΑΓΚΟΣΜΙΟ ΙΣΤΟ XML Schema
XML Schema Notes Lecture 13, 07/16/02. (see example05)
XML Verification Well-formed XML document  conforms to basic XML syntax  contains only built-in character entities Validated XML document  conforms.
Document Type Definitions. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
Introduction to XML: Part I By Sandeep Jangity CS 157B, Section 2 Dr. Lee.
17 Apr 2002 XML Schema Andy Clark. What is it? A grammar definition language – Like DTDs but better Uses XML syntax – Defined by W3C Primary features.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
Why XML ? Problems with HTML HTML design - HTML is intended for presentation of information as Web pages. - HTML contains a fixed set of markup tags. This.
XML Schema Vinod Kumar Kayartaya. What is XML Schema?  XML Schema is an XML based alternative to DTD  An XML schema describes the structure of an XML.
XML Open Computing Institute, Inc. 1 eXtensible Markup Language (XML)
1 XML Schemas. 2 Useful Links Schema tutorial links:

Dr. Azeddine Chikh IS446: Internet Software Development.
Copyright © [2001]. Roger L. Costello. All Rights Reserved. 1 XML Schemas (Primer)
Neminath Simmachandran
XML CPSC 315 – Programming Studio Fall 2008 Project 3, Lecture 1.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
MIS 315 Bsharah An Introduction to XML 1MIS Bsharah.
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
XML Syntax - Writing XML and Designing DTD's
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
1 Dr Alexiei Dingli XML Technologies X-Schema. 2 XML-based alternative to DTD Describes the structure of an XML document Also referred to as XML Schema.
Ceng 520 XML Schemas IntroductionXML Schemas 2 Part 0: Introduction Why XML Schema?
Session IV Chapter 9 – XML Schemas
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
1 Chapter 10: XML What is XML What is XML Basic Components of XML Basic Components of XML XPath XPath XQuery XQuery.
Of 33 lecture 3: xml and xml schema. of 33 XML, RDF, RDF Schema overview XML – simple introduction and XML Schema RDF – basics, language RDF Schema –
SDPL 2005Notes 2.5: XML Schemas1 2.5 XML Schemas n Short introduction to XML Schema –W3C Recommendation, 1 st Ed. May, 2001; 2 nd Ed. Oct, 2004: »XML Schema.
1 XML Schemas. 2 Topics What are Schemas? NameSpaces Elements Attributes Data Types Derivations Keys.
XML. 2 XML- Some Links XML Tutorials – Some Links me=htmlhttp://
Lecture 16 Introduction to XML Boriana Koleva Room: C54
XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the.
1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 5 XML Schema (Based on Møller and Schwartzbach,
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
COS 381 Day 14. Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
XML Validation II Schemas Robin Burke ECT 360. Outline Namespaces Documents  Data types XML Schemas Elements Attributes Derived data types RELAX NG.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
Introduction to XML Schema John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel: (x2073)
XML Validation II Advanced DTDs + Schemas Robin Burke ECT 360.
Lecture 0 W3C XML Schema. Topics Status Motivation Simple type vs. complex type.
Agenda 1.WSDL & XML Schema Astronomicko-geofyzikálne observatórium, Modra An Order.
XML Schema – Simple Type Web site:
CITA 330 Section 2 DTD. Defining XML Dialects “Well-formedness” is the minimal requirement for an XML document; all XML parsers can check it Any useful.
1 XML and XML in DLESE Katy Ginger November 2003.
Extensible Markup Language (XML) Pat Morin COMP 2405.
XML QUESTIONS AND ANSWERS
CSCE 315 – Programming Studio Spring 2013
THE DATATYPES OF XML SCHEMA A Practical Introduction
Presentation transcript:

Basic XML, DTD & Schema

XML의 필요성 오늘날 문서 데이터의 요구사항 XML은 위의 요구사항을 지원한다!! 사람과 시스템이 모두 읽을 수 있는 형태 데이터의 내용과 구조를 정의 관계설정 자료의 구조와 보여주는 부분의 분리 개방성 및 확장성 XML은 위의 요구사항을 지원한다!!

XML태그를 이용한 데이터의 표현 문서는 세가지 요소로 구성됨 XML 문서는 문서의 내용에 대한 구조적인 정보를 가지고 있음 자료 구조 출력

XML의 역사와 W3C XML은 SGML의 Subset형태이다. Standard Generalized Markup Language 1986년에 ISO 표준으로 정의 XML은 World Wide Web Consortium (W3C)에 의해 표준화 http://www.w3.org

XML(eXtensible Markup Language) 웹 상에서 구조화된 문서를 전송하도록 설계된 마크업 언어 1996년 W3C(World Wide Web Consortium)에서 제안 SGML에 기반을 둔 단순하고, 매우 유연성 있는 text형식 논리/내용 구조와 표현을 분리 사용자 임의의 구조정의-자유로운 element와 attribute정의 HTML(HyperText Markup Language)의 단점을 해결하고 SGML(Standard Generalized Markup Language)의 복잡함을 해결하기 위한 방안으로 제시 1998년 2월 W3C에 의해 XML1.0에 대한 표준규약 제정

XML의 취지 최근에 들어와서는 정보의 양이 급격히 증가하고 인터넷이 대중화되면서 다음의 두 가지 성과를 통합할 필요성이 점차 강조 되고 있음 정보를 표준화된 형태로 저장해 그 활용도를 증대 시키는 것 이를 웹 환경을 통해 제공함으로써 대중성을 확보하는 것

XML 표준 제정 동기 90년 이후 기업간 합병에 따른 저비용 시스템의 통합의 필요 인터넷 페이지 증가에 따른 HTML의 구조 검색의 한계 SGML의 개발 및 사용의 한계 OS, H/W 시스템, 특정 Band의 문서 포멧에 대한 국제적인 독립적인 문서 포멧에 대한 요구 소프트웨어 개발 용이, 문서작성 용이, 저장 용의, 관리 용이, 전송 용이, 인터넷 서비스에 용이한 문서 필요 다양한 형식으로 변환이 가능한 문서 필요

“XML is a breakthrough technology” - Bill Gates - Logical View Layout 내용(Content) 형식(Style) + Data로서 의미를 지님 다양한 사용자 뷰(View)제공 “XML is a breakthrough technology” - Bill Gates -

XML의 특징 eXtensible Markup Language DTD / XML Schema XSL 구조화된 문서 태그언어 구조화된 문서 문서의 내용과 형식의 분리 DTD / XML Schema XSL

XML in Community-Specific

XML Everywhere

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

Element & Attribute ▣ Element(요소) 하나의 Element는 Start-Tags/Contents/End-Tags로 구성. <greeting> ----------------Start-Tags Hello, XML! ------------Contents(데이터) </greeting> ----------------End-Tags ※ EMPTY Element (빈요소) <tag/>로 표시. html에 경우 <br><hr>등 ▣ Attribute(속성) <tag attribute=”value”>XML 테스트</tag> 속성이름 = “value”로 html과 달리 “ ” 나 ‘ ’로 하여야 한다.

XML 문법 XML 은 데이터를 설명하기 의해 태그를 사용 정보를 나타내는 기본 요소의 표현 방식 하위요소 포함 가능 <name> Lars Peterson </name> Start tag Element content End tag <employee> <name>Lars Peterson</name> <salary>25000</salary> </employee>

XML 문서의 구성 Processing instruction Comment Root element Child element <?xml version="1.0"?> Comment <!-- This is a comment --> Root element <employee> </employee> Child element <name>Lars Peterson</name> <permanent_staff /> Empty element Attribute <salary currency="US$"> 25000 </salary> <salary> 25000 </salary>

XML 문서의 구조 Prolog 상위 element 는 다른 element를 포함 XML 선언 DTD 또는 XML schema (문법의 정의) 상위 element 는 다른 element를 포함 <?xml version="1.0"?> <!DOCTYPE employees SYSTEM "employees.dtd"> <employee> <name>Lars Peterson</name> ... </employee>

Well-Formed XML문서 생성 Well-formed 문서의 요구사항 Valid문서의 요구사항 단일, 유일한 상위 element 시작/끝 tags의 일치 대소문자 구분 Element들간의 올바른 nesting Attribute는 인용부호를 사용 하나의 element에서 속성을 반복하여 사용하지 않음 Valid문서의 요구사항

Document Object Model (DOM) XML 용어 Validation Style sheets XML XML Document Object Model (DOM) Data binding

XML 처리 시스템 구성도

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

Validation의 필요성 Validation은 XML 문서를 원하는 형식에 맞게 작성/교환 할 수 있도록 한다. 올바른 element와 attributes element와 attribute의 관계정의 하부 Element의 숫자와 순서 정의 데이터 형식(XML schema에서 언급)

Well-Formed 와 Valid 문서 Well-Formed XML 문서 Valid XML 문서 XML의 기본문법 준수 elements/attributes의 조합으로 구성 “문법”을 가지고 있음 Valid XML 문서 well formed 문서 Document Type Definition (DTD) 또는 XML schema로 정의 DTD/XML schema로 정의 된 문법사용

Validating 기술:DTD와XML Schema 다른 구현 방식 DTD XML schema 표준으로 정착 Parser가 지원 제한점 표준으로 정착 기능이 풍부

DTD (Document Type Definition)

DTD 예

마크업 선언(markup declaration) <! 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)인 '>'로 닫아준다.

요소(Element) 선언 <!ELEMENT 요소이름 요소유형 > 1 2 3 4 2. 요소이름은 XML 요소이름 명명과 같다. 3. 요소 유형을 지정한다. 4. > 로 요소 선언을 종료한다. 요소유형 : Children | EMPTY | MIXED | ANY Children : 자식 요소(child element)를 포함한다. EMPTY : 어떤 자식 요소(child element)도 포함할 수 없다. MIXED : 일반 텍스트형태(#PCDATA)와 자식 요소(child element)를 포함. ANY : 어떤 유형의 요소(element)도 포함할 수 있다. 보통 ROOT에서 사용.

요소(Element) 생성 규칙 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)

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)

 + => 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>

속성(Attribute) 1. 속성 선언은 <!ATTLIST 로 한다. > 5 <!ATTLIST 요소이름 속성 유형 1 2 4 속성이름 3 1. 속성 선언은 <!ATTLIST 로 한다. 2. 요소이름은 속성이 부여될 XML 요소이름을 지정. 3. 속성이름을 지정. 4. 속성의 유형을 지정. 5. > 로 속성 선언을 종료. ▣ 속성 유형 CDATA Enumeration(나열형식) ID IDREF IDREFS ENTITY ENTITIES NMTOKEN NMTOKENS NOTATION

DTD의 한계 제대로 된 DTD를 만들기가 어렵다. DTD는 확장할 수 없다. DTD는 데이터로서의 XML을 제대로 기술하지 못한다. DTD는 이름공간(Namespace)를 제대로 지원하지 못한다. DTD는 기술(description)능력에 한계가 있다. DTD에는 기본 요소 내용에 대한 기능이 없다.

Schema

What is XML Schemas? Answer: An XML vocabulary for expressing your data's business rules

Validating your data XML Schema validator Data is ok! XML Schema <location> <latitude>32.904237</latitude> <longitude>73.620290</longitude> <uncertainty units="meters">2</uncertainty> </location> XML Schema validator Data is ok! -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

Purpose of XML Schemas (and DTDs) Specify: the structure of instance documents "this element contains these elements, which contains these other elements, etc" the datatype of each element/attribute "this element shall hold an integer with the range 0 to 12,000" (DTDs don't do too well with specifying datatypes like this)

Motivation for XML Schemas People are dissatisfied with DTDs It's a different syntax You write your XML (instance) document using one syntax and the DTD using another syntax --> bad, inconsistent Limited datatype capability DTDs support a very limited capability for specifying datatypes. You can't, for example, express "I want the <elevation> element to hold an integer with a range of 0 to 12,000" Desire a set of datatypes compatible with those found in databases DTD supports 10 datatypes; XML Schemas supports 44+ datatypes

Highlights of XML Schemas XML Schemas are a tremendous advancement over DTDs: Enhanced datatypes 44+ versus 10 Can create your own datatypes Written in the same syntax as instance documents less syntax to remember Object-oriented'ish Can extend or restrict a type (derive new type definitions on the basis of old ones) Can 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 within a region Can define multiple elements with the same name but different content Can define elements with nil content Can define substitutable elements - e.g., the "Book" element is substitutable for the "Publication" element.

Classic use of XML Schemas (Trading Partners - B2B) Software to Process P.O. P.O. "P.O. is okay" Supplier Consumer P.O. Schema Validator P.O. Schema (Schema at third-party, neutral web site)

Let's Get Started! Convert the BookStore.dtd (next page) to the XML Schema syntax for this first example we will make a straight, one-to-one conversion, i.e., Title, Author, Date, ISBN, and Publisher will hold strings, just like is done in the DTD We will gradually modify the XML Schema to use stronger types

BookStore.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)>

ELEMENT ATTLIST BookStore #PCDATA Author Book ID Title NMTOKEN CDATA Publisher ISBN ENTITY Date This is the vocabulary that DTDs provide to define your new vocabulary

http://www.w3.org/2001/XMLSchema http://www.books.org (targetNamespace) complexType element BookStore sequence Author Book schema boolean Title string Publisher ISBN integer Date This is the vocabulary that XML Schemas provide to define your new vocabulary One difference between XML Schemas and DTDs is that the XML Schema vocabulary is associated with a name (namespace). Likewise, the new vocabulary that you define must be associated with a name (namespace). With DTDs neither set of vocabulary is associated with a name (namespace) [because DTDs pre-dated namespaces].

(explanations on succeeding pages) <?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: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: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> (explanations on succeeding pages) BookStore.xsd (see example01) xsd = Xml-Schema Definition

<?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: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: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 BookStore (Book)+> <!ELEMENT Book (Title, Author, Date, ISBN, Publisher)> <!ELEMENT Title (#PCDATA)> <!ELEMENT Author (#PCDATA)> <!ELEMENT Date (#PCDATA)> <!ELEMENT ISBN (#PCDATA)> <!ELEMENT Publisher (#PCDATA)>

Default Value for minOccurs and maxOccurs The default value for minOccurs is "1" The default value for maxOccurs is "1" <xsd:element ref="Title" minOccurs="1" maxOccurs="1"/> Equivalent! <xsd:element ref="Title"/> Do Lab1

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: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:schema> Anonymous types

Using <sequence> and <choice> DTD: <!ELEMENT life ((work, eat)*, (work | play), sleep)* > <?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:element name="work" type="xsd:string"/> <xsd:element name="eat" type="xsd:string"/> </xsd: sequence> <xsd:choice> <xsd:element name="play" type="xsd:string"/> </xsd:choice> <xsd:element name="sleep" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> XML Schema:

Summary of Declaring Elements (two ways to do it) 1 <xsd:element name="name" type="type" minOccurs="int" maxOccurs="int"/> A simple type (e.g., xsd:string) or the name of a complexType (e.g., BookPublication) A nonnegative integer A nonnegative integer or "unbounded" Note: minOccurs and maxOccurs can only be used in nested (local) element declarations. 2 <xsd:element name="name" minOccurs="int" maxOccurs="int"> <xsd:complexType> … </xsd:complexType> </xsd:element>

Built-in Datatypes Primitive Datatypes string boolean decimal float double duration dateTime time date gYearMonth gYear gMonthDay Atomic, built-in "Hello World" {true, false} 7.08 12.56E3, 12, 12560, 0, -0, INF, -INF, NAN P1Y2M3DT10H30M12.3S format: CCYY-MM-DDThh-mm-ss format: hh:mm:ss.sss format: CCYY-MM-DD format: CCYY-MM format: CCYY format: --MM-DD Note: 'T' is the date/time separator INF = infinity NAN = not-a-number

Built-in Datatypes (cont.) Primitive Datatypes gDay gMonth hexBinary base64Binary anyURI QName NOTATION Atomic, built-in format: ---DD (note the 3 dashes) format: --MM-- a hex string a base64 string http://www.xfront.com a namespace qualified name a NOTATION from the XML spec

Built-in Datatypes (cont.) Derived types normalizedString token language IDREFS ENTITIES NMTOKEN NMTOKENS Name NCName ID IDREF ENTITY integer nonPositiveInteger Subtype of primitive datatype A string without tabs, line feeds, or carriage returns String w/o tabs, l/f, leading/trailing spaces, consecutive spaces any valid xml:lang value, e.g., EN, FR, ... must be used only with attributes part (no namespace qualifier) 456 negative infinity to 0

Built-in Datatypes (cont.) Derived types negativeInteger long int short byte nonNegativeInteger unsignedLong unsignedInt unsignedShort unsignedByte positiveInteger Subtype of primitive datatype negative infinity to -1 -9223372036854775808 to 9223372036854775808 -2147483648 to 2147483647 -32768 to 32767 -127 to 128 0 to infinity 0 to 18446744073709551615 0 to 4294967295 0 to 65535 0 to 255 1 to infinity Note: the following types can only be used with attributes (which we will discuss later): ID, IDREF, IDREFS, NMTOKEN, NMTOKENS, ENTITY, and ENTITIES.

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

<!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

<xsd:element name="BookStore"> <xsd:complexType> <xsd:sequence> <xsd:element name="Book" maxOccurs="unbounded"> <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: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> Category (autobiography | non-fiction | fiction) #REQUIRED InStock (true | false) "false" Reviewer CDATA " "

"Instance documents are required to have the Category attribute <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 the enumeration facets)." Note: attributes can only have simpleTypes (i.e., attributes cannot have child elements).

Summary of Declaring Attributes (two ways to do it) 1 <xsd:attribute name="name" type="simple-type" use="how-its-used" default/fixed="value"/> required optional prohibited Do not use the "use" attribute if you use either default or fixed. xsd:string xsd:integer xsd:boolean ... 2 <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>

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