DTD & XML Schema Group 3 Seriousl

Well-formed and Valid ที่มา : http://www.ict.up.ac.th/sathienh/DTD%20and%20XML%20Schema.pdf

Well-formed XML Document -

ตองมี root element

-

ตองมี tags เปด - ปด

-

Tags ตองเปน case sensitive

-

Attribute ตองมี quoted(“ ”)เสมอ

Valid XML Document -

เอกสาร Valid ตองเปนเอกสาร Well-formed

-

ตองใช tag ที่กําหนดเฉพาะใน Schema ที่ตกลงกันไวเทานั้น ปจจุบันมี Schema ที่นิยม 3 ตัว คือ DTD , XML Schema และ RELAX NG

What is DTD ? ที่มา http://www.w3schools.com/xml/xml_dtd_intro.asp

DTD DTD ยอมาจาก Document Type Definition โดย เปนตัวกําหนด structure elements และ attributes ของ ไฟล XML DTD จะทําหนาที่ตรวจสอบความถูกตองของเอกสาร XML วาเปนไปตามขอตกลงที่กําหนดไวในไฟล DTD หรือไม ถาไมก็จะฟองแสดงขอผิดพลาดออกมา

XML document with an internal DTD ]> Tove Jani Reminder Don't forget me this weekend

การเขียน DTD ภายในไฟล XML จะเขียนตอ จาก XML Declaration และ ถูกครอบดวย

XML document with an internal DTD ]>

เราสามารถ ตีความหมายของ DTD ไดดังนี้ - !DOCTYPE note กําหนด root element ของไฟลนี้คือ note - !ELEMENT note กําหนดวา element ของไฟล จะมี elements ตามนี้ : "to,from,heading,body" - !ELEMENT to กําหนด element to เปนประเภท "#PCDATA" - !ELEMENT from กําหนด element from เปนประเภท "#PCDATA" - !ELEMENT heading กําหนด element heading เปนประเภท "#PCDATA" - !ELEMENT body กําหนด element body เปนประเภท "#PCDATA"

An External DTD Declaration Tove Jani Reminder Don't forget me this weekend!

ถาทําการประกาศ DTD ไวภายนอกไฟล XML จะตองอางอิง(reference)ไป ยังไฟล DTD ดวย

An External DTD Declaration



รูปแบบไฟล "note.dtd" ทีมี DTD ประกาศไว

The Building Blocks of XML Documents สวนประกอบของไฟล XML มีดังนี้ ● ● ● ● ●

Elements Attributes Entities PCDATA CDATA

The Building Blocks of XML Documents - Elements เปนสวนหลักของการสรางไฟล XML ภายใน Element จะบรรจุ text เอาไวดานใน Example some text some text

The Building Blocks of XML Documents - Attributes เปนสวนเพิ่มเติมขอมูลใหกับ Element และจะถูกใสไวใน tag เปดของ Element Example

"img" คือ element name "src" คือ attribute name "computer.gif" คือคาของ attribute ถา Element วางเปลาจะถูกปดดวย /

The Building Blocks of XML Documents - Entities ขอความพิเศษบางตัวใน XML ไมสามารถใชงานไดโดย ตรงอยางเชน < จึงตองใชตัวอักษรอื่นมาเทียบแทน Example

Entity References

Character

<

<

>

>

&

&

"

"

'



The Building Blocks of XML Documents - PCDATA(parsed character data) เปนขอความที่จะถูก parsed โดย parser ก็คือ เครื่องหมาย < จะบอกวาเปน tag เปดถาตองการให < มีความ หมายวา นอยกวา ตองใช Entity References เขามาเสริม

- CDATA(character data) เปนขอความที่จะไมถูก parsed โดย parser ก็คือ เครื่องหมาย < จะไมไดหมายความวาเปน tag เปด แตจะเปนตัว อักษรปกติทั่วไป

Declaring Elements การกําหนดคา Element ตาม syntax ดังนี้

Or

Empty Elements

Example

XML Example


Elements with Parsed Character Data



Example

Elements with any Contents



Example

Elements with Children (sequences)



Or

Example

Declaring Only One Occurrence of an Element



Example

Declaring Minimum One Occurrence of an Element



Example

เครื่องหมาย + เปนตัวบอกวา ภายใน Element note จะ มี child ที่ชื่อ message ได 1 หรือมากกวานั้น

Declaring Zero or More Occurrences of an Element

Example

เครื่องหมาย * เปนตัวบอกวา ภายใน Element note จะ มี child ที่ชื่อ message ได 0 หรือมากกวานั้น

Declaring Zero or One Occurrences of an Element



Example

เครื่องหมาย ? เปนตัวบอกวา ภายใน Element note จะ มี child ที่ชื่อ message ได 0 หรือ 1 ตัวเทานั้น

Declaring either/or Content



เปนตัวบอกวาใน note element จะมี to element , from element , header element และ message หรือ body element

Declaring Mixed Content



เปนการกําหนดวา ใน note element จะมี Zero or More Occurrences และเปนแบบ parsed character data โดยขางใน จะมี to,from,header หรือ message อยู

Declaring Attributes การกําหนด Attributes syntax ดังนี้

DTD Example

XML Example

Declaring Attributes Attribute-type สามารถใสไดตามนี้ Type

Description

CDATA

The value is character data

(en1|en2|..)

The value must be one from an enumerated list

ID

The value is a unique id

IDREF

The value is the id of another element

IDREFS

‘The value is a list of other ids

NMTOKEN

The value is a valid XML name

Declaring Attributes

Type

Description

NMTOKENS

The value is a list of valid XML names

ENTITY

The value is an entity

ENTITIES

The value is a list of entities

NOTATION

The value is a name of a notation

xml:

The value is a predefined xml value

Declaring Attributes Attribute-value สามารถใสไดตามนี้

Value

Description

value

The default value of the attribute

#REQUIRED

The attribute is required

#IMPLIED

The attribute is optional

#FIXED value

The attribute value is fixed

Use of Elements vs. Attributes Anna Smith female Anna Smith

จะเห็นไดวา ในตัวอยางการใช Attributes กับไมใชใหขอมูลที่เหมือนกัน

Avoid using attributes เราควรหลีกเลี่ยงการใช Attributes เพราะบางทีอาจทําใหเกิดปญหาได เชน ● ● ● ● ●

attributes ไมสามารถเก็บคาหลายคาได (child elements สามารถทําได) attributes นั้นขยายไดยาก (สําหรับเปลี่ยนแปลงขอมูลในอนาคต) attributes ไมสามารถอธิบายโครงสรางได (child elements สามารถทําได) attributes นั้นยากตอการจัดการดวย code attribute values ทดสอบกับ DTD ไดยาก

ถาหากใช Attributes ในการเก็บขอมูลจะทําใหอานไดยาก ใหใช Element เปนตัวอธิบายขอมูลและใช Attributes ในการใหขอมูลที่ไมไดเกี่ยวของกับขอมูล หลักโดยตรงจะดีที่สุด

Example TV Schedule DTD


Example TV Schedule DTD

]>

Movies DTD
]>

Movies DTD
]>

ทดลองการใช DTD ที่ผิด

Output

ที่มา http://www.herongyang.com/XML/DTD-Validation-of-XML-with-DTD-Using-DOM.html

What is XML Schema ? ที่มา : http://www.w3schools.com/xml/schema_howto.asp

XML Schema XML Schema จะใชอธิบายโครงสรางของ XML Document ภาษา XML Schema อางอิงจาก XML Schema Definition (XSD) ซึ่ง จะใชการเขียนรูปแบบเดียวกับภาษา XML โดย XML Schema กําหนด มาตรฐานโดย W3C

The Purpose of XML Schema -

มี Element และ Attribute อยูภายใน XML Document มีลําดับของ Child Element มีประเภทของขอมูลใน Element และ Attribute กําหนดคา default และ fixed ของขอมูลใน Element และ Attribute

XML Schema Example

XML Document reference to XML Schema

XML Schema Example Define XML Schema ( note.xsd)

Structure of XML Schema
Indicate element and data type used in schema

targetNamespace="http://www.w3schools.com"

*Indicate that the element defined by this schema

xmlns="http://www.w3schools.com"

*Default namespaces

elementFormDefault="qualified">

*Any element in schema must be namespace qualified



Simple Type VS Complex Type Simple Type :

Complex Type :

Peter

Peter

Parker

Parker

28

28


Most Common Data Type ●

xs:string



xs:decimal



xs:integer



xs:boolean



xs:date



xs:time

Define Simple Element and Attribute Syntax :



Peter Parker 28



Define Complex Element Peter Parker 28



Schema of Movies Project Movies

film 1

film 2

...

film 3

film n

title

title

title

title

year

year

year

year

types

types

types

types

type 1

type 1

type 1

type 1

type 2

type 2

type 2

type 2

type 3

type 3

type 3

type 3

time

time

time

time

director

director

director

director

Movie XSD

Movie XSD

ทดลองการใช XSD ที่ผิด

Output

DOM parser in Java ตัวอยาง วิธีจัดการกับ tree เมื่อชื่อ element เหมือนกัน ที่ parent Node ตางกัน

title

year

types

film 61

Movies

time

director

screenplay

type 1

p1

type 2

p2

story p1

type 3

film 62 title

year

types

time

director

screenplay

type 1

p1

type 2

p2

type 3

story p1

DOM parser in Java Insert Data เพิ่ม element screenplay และ story

film 61

film 62

สรางฟงกชัน searchMovie() private static void searchMovie(NodeList nList, String search){ System.out.println("\n\nsearch about : " + search); System.out.println("----------------------------"); for (int i = 0; i < nList.getLength(); i++) { //all film Element film = (Element) nList.item(i); NodeList childfilm = film.getChildNodes(); for (int j= 0; j < childfilm.getLength(); j++){ //all node in film Node temp = childfilm.item(j); NodeList childElement = temp.getChildNodes(); if (childElement.getLength() > 1){ for (int l=1; l
เรียกใชฟงกชันคนหา searchMovie() public class MovieST { public static void main(String[] args) { try { File inputFile = new File(".../parseMovie.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inputFile); doc.getDocumentElement().normalize(); //defines tage list film NodeList nList = doc.getElementsByTagName("film");

[...] searchMovie(nList,"Ted Elliott"); [...] }

DOM parser in Java ผลลัพธที่ไดเมื่อเรียกฟงกชัน searchMovie(nList,"Ted Elliott") NodeId = 61 parent Node = screenplay child Node = p1

NodeId = 61 parent Node = story child Node = p1

NodeId = 62 parent Node = story child Node = p2

Summary ที่มา : http://www.w3schools.com/xml/schema_howto.asp

When to Use a DTD/Schema?

-

ทําใหกลุมคนตางๆ สามารถตกลงใชรูปแบบที่เปน มาตรฐานเพื่องายตอการแลกเปลี่ยนขอมูลกัน

-

สามารถตรวจสอบไดวา ขอมูลที่รับมานั้นมีความถูกตอง (Valid)

-

นอกจากนั้นยังสามารถใช DTD เพื่อตรวจสอบขอมูลของ ตนเอง

When to NOT to Use a DTD/Schema? -

XML ไมจําเปนตองใช DTD/Schema.

-

เมื่อตองการทดลอง XML หรือทํางานเกี่ยวกับไฟล XML ที่มีขนาดเล็ก การทํา DTD อาจจะทําใหเสียเวลา

-

ถาหากทําการพัฒนา applications ใหรอจนกระทั่ง โปรแกรมมีความเสถียรกอนจึงคอยทํา DTD ไมเชนนั้น Software อาจจะหยุดทํางานเนื่องจากการผิดพลาดใน การตรวจสอบ

DTD & XML Schema.pdf

Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. DTD & XML Schema.pdf. DTD & XML Schema.pdf. Open. Extract.

881KB Sizes 3 Downloads 174 Views

Recommend Documents

XML Schema - Computer Science E-259: XML with Java
Dec 3, 2007 - ..... An all group is used to indicate that all elements should appear, in any ...

My First XML Parser
Oct 15, 2007 - Computer Science E-259: XML with Java, Java Servlet, and JSP .... phones didn't exist in 1636, so the course hadn't a phone number on file for.

XML programming with SQL/XML and XQuery
agers fulfill vital responsibilities in complex informa- tion systems by ... other information-service systems. Permission to ...... Client, network, and server resources ...

XML programming with SQL/XML and XQuery - IEEE Xplore
XML programming model evolution. SAX (the simple API [application programming in- terface] for XML)1 was the first popular interface for. XML programming.

Gain PF Circular dtd 2016Nov19.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Gain PF Circular ...

XML Schema (Second Edition)
Nov 26, 2007 - Different companies all proposed different variations of ... XML Data (MS, Arbortext, Inso), January 1998 ... Storage of application information ...

XML Tooling - Sites
J2EE Tooling (2 of 2). Connector Projects. J2EE Connector Architecture (JCA) based. EJB Test Client – Universal Test Client. HTML-based. J2EE programming ...

My First XML Parser
Oct 15, 2007 - Consider now a larger excerpt from CSCI E-259's original database, the .... element can be printed as a start tag immediately followed by an ...

Learning XML
Extensible Markup Language (XML) is a data storage toolkit, a configurable vehicle for any kind of information, an .... computer programs to determine the functions and boundaries of document parts. ...... so perhaps the backup is a good idea.

pdf xml php
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. pdf xml php.

Introduction to XML
Industry standards and data exchange applications. 2. Web services, SOA data transport and message ... e.g., Phone numbers (home, office, mobile), in patient.

generate pdf xml
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. generate pdf xml.

pdf export xml
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. pdf export xml.

voice xml pdf
File: Voice xml pdf. Download now. Click here if your download doesn't start automatically. Page 1 of 1. voice xml pdf. voice xml pdf. Open. Extract. Open with.

A Case for XML - IJEECS
With these considerations in mind, we ran four novel experiments: (1) we measured instant messenger and RAID array throughput on our 2-node testbed; (2) we ...

XML Notepad 2007 Design - GitHub
XML Notepad 2007 Design ... Validation, IntelliSense, and Custom Editors ... you'll find the core XmlNotepad dll project, an Application project that builds.

A Case for XML - IJEECS
butions. For starters, we propose a novel methodology for the investigation of check- sums (TAW), which we use to verify that simulated annealing and operating systems are generally incompatible. We use decen- tralized archetypes to verify that super

pdf xml converter
File: Pdf xml converter. Download now. Click here if your download doesn't start automatically. Page 1 of 1. pdf xml converter. pdf xml converter. Open. Extract.

An Intelligent XML-RDBMS Mapper
Supervisor's Signature… ... electronic publishing. But due to its generic design .... database), accepting XML as input and rendering XML as output. A lot of work ...

pdf to xml converter java
Page 1. Whoops! There was a problem loading more pages. pdf to xml converter java. pdf to xml converter java. Open. Extract. Open with. Sign In. Main menu.

1 DKPmon eqDKP export XML
Listing of when each player joined the raid; players in at the start will still be listed playerleaves Listing of when each player left the raid, if they left prior to logging being shut down lootinfo. Information about each piece of loot that was di

xml free pdf download
Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. xml free pdf download. xml free pdf download. Open. Extract.

pdf to xml convertor
Connect more apps... Try one of the apps below to open or edit this item. pdf to xml convertor. pdf to xml convertor. Open. Extract. Open with. Sign In. Main menu.