1 / 59

Basic XML, DTD & Schema

Basic XML, DTD & Schema. XML 의 필요성. 오늘날 문서 데이터의 요구사항 사람과 시스템이 모두 읽을 수 있는 형태 데이터의 내용과 구조를 정의 관계설정 자료의 구조와 보여주는 부분의 분리 개방성 및 확장성 XML 은 위의 요구사항을 지원한다 !!. XML 태그를 이용한 데이터의 표현. 문서는 세가지 요소로 구성됨 XML 문서는 문서의 내용에 대한 구조적인 정보를 가지고 있음 XML 문서는 출력에 관한 내용은 정의하지 않음. 자료. 구조. 출력. XML 의 역사와 W3C.

arella
Télécharger la présentation

Basic XML, DTD & Schema

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic XML, DTD & Schema

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

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

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

  5. 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에 대한 표준규약 제정

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

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

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

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

  10. XML in Community-Specific

  11. XML Everywhere

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

  13. 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과 달리 “ ” 나 ‘ ’로 하여야 한다.

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

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

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

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

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

  19. XML 처리 시스템 구성도

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

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

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

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

  24. DTD(Document Type Definition)

  25. DTD 예

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

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

  28. 요소(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)

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

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

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

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

  33. Schema

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

  35. Validating your data <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

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

  37. 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

  38. 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. Highlights of XML Schemas

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

  40. 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

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

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

  43. http://www.w3.org/2001/XMLSchema http://www.books.org (targetNamespace) complexType element BookStore Author sequence Book schema Title boolean string ISBN Publisher Date integer 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].

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

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

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

  47. <?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> Anonymous types

  48. 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: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> XML Schema:

  49. 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. <xsd:element name="name" minOccurs="int" maxOccurs="int"> <xsd:complexType> … </xsd:complexType> </xsd:element> 2

  50. 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 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 Built-in Datatypes Note: 'T' is the date/time separator INF = infinity NAN = not-a-number

More Related