Advance Database S2-2011 Week-5 Dr.Kwanchai Eurviriyanukul

Slides:



Advertisements
Similar presentations
MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Advertisements

1 XML DTD & XML Schema Monica Farrow G30
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
1 Lecture 10 XML Wednesday, October 18, XML Outline XML (4.6, 4.7) –Syntax –Semistructured data –DTDs.
1 COS 425: Database and Information Management Systems XML and information exchange.
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
Winter 2002Arthur Keller – CS 18018–1 Schedule Today: Mar. 12 (T) u Semistructured Data, XML, XQuery. u Read Sections Assignment 8 due. Mar. 14.
Creating a Well-Formed Valid Document. 2 Objectives Introducing XHTML Creating a Well-Formed Document Creating a Valid Document Creating an XHTML Document.
1 XML Document Type Definitions XML Schema. 2 Well-Formed and Valid XML uWell-Formed XML allows you to invent your own tags. uValid XML conforms to a.
Summary. Chapter 9 – Triggers Integrity constraints Enforcing IC with different techniques –Keys –Foreign keys –Attribute-based constraints –Schema-based.
Fall 2001Arthur Keller – CS 18017–1 Schedule Nov. 27 (T) Semistructured Data, XML. u Read Sections Assignment 8 due. Nov. 29 (TH) The Real World,
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
1 XML Semistructured Data Extensible Markup Language Document Type Definitions.
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
4/20/2017.
Pemrograman Berbasis WEB XML part 2 -Aurelio Rahmadian- Sumber: w3cschools.com.
XP Tutorial 9New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with XHTML Creating a Well-Formed Valid Document Tutorial 9.
XP The University of Akron Summit College Business Technology Department Computer Information Systems 2440: 140 Internet Tools Instructor: Enoch E. Damson.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
Copyright © 2003 Pearson Education, Inc. Slide 3-1 Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA The Web Wizard’s Guide.
s Advance Database Systems Week-2 Dr.Kwanchai Eurviriyanukul
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.
Extensible Markup and Beyond
XML Schema and Stylus Studio. Introduction to XML Schema XML Schema defines building blocks of a XML document XML Schemas are alternative to DTD Why XML.
CSCE 520- Relational Data Model Lecture 2. Relational Data Model The following slides are reused by the permission of the author, J. Ullman, from the.
XP 1 DECLARING A DTD A DTD can be used to: –Ensure all required elements are present in the document –Prevent undefined elements from being used –Enforce.
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.
Advance Database S Week-7 Dr.Kwanchai Eurviriyanukul
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro.
 XML is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Winter 2006Keller, Ullman, Cushing18–1 Plan 1.Information integration: important new application that motivates what follows. 2.Semistructured data: a.
1 Chapter 10: XML What is XML What is XML Basic Components of XML Basic Components of XML XPath XPath XQuery XQuery.
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
XP Tutorial 9 1 Working with XHTML. XP SGML 2 Standard Generalized Markup Language (SGML) A standard for specifying markup languages. Large, complex standard.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
Module 3: Creating Data Types and Tables. Overview Working with Data Types Working with Tables Generating Column Values Generating Scripts.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
17 Apr 2002 XML Syntax: Documents Andy Clark. Basic Document Structure Element tags – Elements have associated attributes Text content Miscellaneous –
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.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
Jeff Ullman: Introduction to XML 1 XML Semistructured Data Extensible Markup Language Document Type Definitions.
Semistructured Data Extensible Markup Language Document Type Definitions Zaki Malik November 04, 2008.
The eXtensible Markup Language (XML). Presentation Outline Part 1: The basics of creating an XML document Part 2: Developing constraints for a well formed.
INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
s1 201 Advance Database Systems Dr.Kwanchai Eurviriyanukul
CSCE 520- Relational Data Model Lecture 2. Oracle login Login from the linux lab or ssh to one of the linux servers using your cse username and password.
XML Document Type Definitions and the Document object model.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
XML DTD. XML Validation XML with correct syntax is "Well Formed" XML. XML validated against a DTD is "Valid" XML.
Session 1 Module 1: Introduction to Data Integrity
XP Tutorial 9New Perspectives on HTML and XHTML, Comprehensive 1 Working with XHTML Creating a Well-Formed Valid Document Tutorial 9.
Advance Database S Week-6 Dr.Kwanchai Eurviriyanukul
Tutorial 9 Working with XHTML. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Describe the history and theory of XHTML.
SEMI-STRUCTURED DATA (XML) 1. SEMI-STRUCTURED DATA ER, Relational, ODL data models are all based on schema Structure of data is rigid and known is advance.
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
XML Introduction to XML Extensible Markup Language.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
Week-9 (Lecture-1) XML DTD (Data Type Document): An XML document with correct syntax is called "Well Formed". An XML document validated against a DTD is.
XML: Extensible Markup Language
Unit 4 Representing Web Data: XML
Tutorial 9 Working with XHTML
Chapter 7 Representing Web Data: XML
Tutorial 9 Working with XHTML
Teaching slides Chapter 8.
Lecture 9: XML Monday, October 17, 2005.
Lecture 24: Final Review Friday, March 10, 2006.
Presentation transcript:

Advance Database S Week-5 Dr.Kwanchai Eurviriyanukul

Contents Week-5 XML Basics 5: 7 ธค. – DOM – XML DTD – XML Schema XML Query – Xpath 6: 14 ธค – Xquery7: 21 ธค – XSL 8: 24 ธค WebService 9: 4 มค – TH-E-GIF DataIntegration 10: 11 มค – Schema matching and mapping Parallel Database 11:18 มค GIS 12:

Contents Week-5 XML Basics 5: 7 ธค. – DOM – XML DTD – XML Schema : 14 ธค XML Query – Xpath 6: 21 ธค – Xquery7: 24 ธค – XSL 8: 24 ธค WebService 9: 4 มค – TH-E-GIF DataIntegration 10: 11 มค – Schema matching and mapping Parallel Database 11:18 มค GIS 12:

XML Basics: Content of Week 5 DOM (Reviews) XML DTD XML Schema Lab: DTD and Schema construction

Week5-Lab Construct and Validate your XML document using DTD and php.

XML Basics: Content of Week 5 DOM (Reviews) XML DTD XML Schema Lab: DTD and Schema construction

XML Document example

8 From Stanford: Well-Formed and Valid XML Well-Formed XML allows you to invent your own tags. Valid XML conforms to a certain DTD. What is “Well-Formed XML ”?

9 From Stanford: Well-Formed and Valid XML Well-Formed XML allows you to invent your own tags. Valid XML conforms to a certain DTD. What is “Well-Formed XML ”?

10 What are XML syntax rules? Well-Formed XML allows you to invent your own tags. Valid XML conforms to a certain DTD. What is “Well-Formed XML ”?

11 What are XML syntax rules? 1.? 2.? 3.? 4.? 5.?

12 What are XML syntax rules?

13 From Stanford: Well-Formed XML Start the document with a declaration, surrounded by. Normal declaration is: – “standalone” = “no DTD provided.” Balance of document is a root tag surrounding nested tags.

XML DTD

DTD Declaration

GUESS??? Internal or External???

DTD Declaration GUEST??? Internal or External???

DTD Declaration GUEST??? Internal or External???

DTD Declaration External Declaration note.dtd

Internal DTD Declaration

24 Refresh From Stanford: Well-Formed XML Start the document with a declaration, surrounded by. Normal declaration is: – “standalone” = “no DTD provided.” Balance of document is a root tag surrounding nested tags.

25 From Stanford: Example: (a) <!DOCTYPE BARS [ ]> Joe’s Bar Bud 2.50 Miller 3.00 … The DTD The document 1.? 2.?

26 From Stanford: Example: (a) <!DOCTYPE BARS [ ]> Joe’s Bar Bud 2.50 Miller 3.00 … The DTD The document 2.?

27 From Wiki: Example 1.? 2.? 3.? 4.?

28 From Wiki: Example 2.? 3.? 4.?

29 From Wiki: Example 3.? 4.?

30 From Wiki: Example 4.?

31 From Wiki: Example

DTD Declaration Exercise External Declaration note.dtd

33 From Stanford: Example: (b) Assume the BARS DTD is in file bar.dtd. Joe’s Bar Bud 2.50 Miller 3.00 … Get the DTD from the file bar.dtd 1.? External Declaration

34 From Stanford: Example: (b) Assume the BARS DTD is in file bar.dtd. Joe’s Bar Bud 2.50 Miller 3.00 … Get the DTD from the file bar.dtd External Declaration

35 From Wiki: Example 1.? 2.? 3.? External Declaration

36 From Wiki: Example 2.? 3.? External Declaration

37 From Wiki: Example 3.? External Declaration

38 From Wiki: Example

Why using DTD

DTD - XML Building Blocks

DTD - Elements

DTD - Attributes

DTD - Entities

DTD - PCDATA

DTD - CDATA

DTD - XML Building Blocks

DTD - Elements Webpage for more details

DTD - Elements

50 From Stanford: Element Descriptions Subtags must appear in order shown. A tag may be followed by a symbol to indicate its multiplicity. – * = zero or more. – + = one or more. – ? = zero or one. Symbol | can connect alternative sequences of tags.

DTD – Elements-Quiz

DTD – Elements-Quiz tutorial.dtd Valid XML document????

DTD – Elements-Quiz tutorial.dtd Valid XML document???? => YES

DTD – Elements-Quiz tutorial.dtd Valid XML document????

DTD – Elements-Quiz tutorial.dtd Valid XML document???? => NO

DTD – Elements-Quiz tutorial.dtd Valid XML document???? => NO

DTD – Elements-Quiz tutorial.dtd Valid XML document????

DTD – Elements-Quiz tutorial.dtd Valid XML document???? => YES

DTD – Elements-Quiz tutorial.dtd Valid XML document????

DTD – Elements-Quiz tutorial.dtd Valid XML document???? => No

DTD – Elements-Quiz tutorial.dtd Valid XML document???? => No

DTD – Elements-Quiz tutorial.dtd Valid XML document????

DTD – Elements-Quiz tutorial.dtd Valid XML document????=>NO

DTD – Elements-Quiz tutorial.dtd Valid XML document????=>NO

65 From Stanford: Example: (a) <!DOCTYPE BARS [ ]> Joe’s Bar Bud 2.50 Miller 3.00 … The DTD The document 1.? 2.?

66 From Stanford: Example: (a) <!DOCTYPE BARS [ ]> Joe’s Bar Bud 2.50 Miller 3.00 … The DTD The document 1.?

DTD - XML Building Blocks

68 From Standford:DTD Structure [ ( )>... more elements... ]>

XML Basics: Content of Week 5 DOM (Reviews) XML DTD XML Schema Lab: DTD and Schema construction

Advance Database S Week-5 Dr.Kwanchai Eurviriyanukul

Week-1-Homework Marking criteria. 1.You have successfully created your database. (2.5 marks) 2.You have successfully populated your data into your big table. (2.5 marks) 3.You have successfully populated your data into your normalized tables (2.5 marks) 4.Your have demonstrated the enforcement of foreign key constraints for your database. (2.5 marks)

Homework-Week-2 1.Data Population (Normalization from last week) 1 2.HTML processing 4 3.Venn Diagram Creation 4

Lab for Week-3 1.Marking Week-2 Lab 2.Hand-Draw an XML tree structure for the given example in the class. (2.5) 3.Program-Draw an XML tree structure for an html data (from line ) 1. k-2/thailand.htm (2.5) k-2/thailand.htm 4.Change the Xpath expression of your previous code to … and observe what is different (5)

Contents Week-4 Create table using MySQL Workbench – Collation => Sorting => UTF-8_general/unicode – Storage Engine => MyISAM, InnoDB Populate Data: Select Data into table Join Optimization XML Basics – DOM

Lab for Week-4 1.Write “SQL statements” to populate data into the following schema 2.Create indexes to speed up the join of these tables. 3.Create a program to retrieve data from the web and populated into your tables – Province coords – Amphur coords

Lab for Week-4-Cont.

Week-4 Homework Explain

ID Structure province-district_name-sub_district_name- moo จังหวัด - อำเภอ - ตำบล - หมู่ => รหัสหมู่บ้าน เชียงใหม่ - จอมทอง - แม่สอย - หมู่ 13 => หมู่บ้าน ห้วยพัฒนา เชียงใหม่ - แม่แจ่ม - ช่างเคิ้ง - หมู่ 2 => หมู่บ้านต่อ เรือ

How about ID like ‘000001’? In INT format? => ‘1’ => We will loose ‘00000’ So char(6) will be a solution. From: refman-5.5-en.html-chapter/data-types.html#numeric-types As an extension to the standard MEDIUMINT MySQL supports the SQL standard integer types INTEGER (or INT) and SMALLINT. As an extension to the standard, MySQL also supports the integer types TINYINT, MEDIUMINT, and BIGINT.

Let’s analyze the possible ID for regions SQL Here to get => Villagedata

Let’s analyze the possible ID for regions Villagedata

How about? select DISTINCT left(village_id,1), DISTINCT region_name from villagedata;

How about? select DISTINCT left(village_id,1), DISTINCT region_name from villagedata; Error

Contents Week-4 Create table – Collation => Sorting => UTF-8_general/unicode – Storage Engine => MyISAM, InnoDB Populate Data: Select Data into table Join Optimization XML Basics – DOM

Now we need to construct region table Select name, collation, engine

What is collation???

Now we need to construct region table What is collation ?

Now we need to construct region table Select name, collation, engine

Collation utf8, a UTF-8 encoding of the Unicode character set using one to three bytes per character =>to collect and arrange in correct order the sheets of a document

Character Sets and Collations in General

Let’s have a look What are these?

Let’s have a look

Let’s have a look

Collation What collation should we use?

Collation

Collation => การเรียงลำดับตัวอักษร We use utf8_unicode_ci because it provides more correct Comparison for foreign characters, e.g. B => ‘ss’ in stead of ‘s’. Note it will be slower than utf8_general_ci for comparison.

Now we need to construct region table What is collation ?

Now we need to construct region table Select name, collation, engine

Database Engine Selection EB = 10E+18 engines.html

Database Engine Selection So we will use InnoDB because we want Transaction and Foreign key support. EB = 10E+18 engines.html

Create table region

Synchronize with DB CREATE TABLE IF NOT EXISTS `sml_test`.`region` ( `idregion` CHAR(1) NOT NULL, `nameregion` VARCHAR(45) NULL DEFAULT NULL, PRIMARY KEY (`idregion`) ) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;

Synchronize with DB 1.CREATE TABLE IF NOT EXISTS `sml_test`.`region` ( 2. `idregion` CHAR(1) NOT NULL, 3. `nameregion` VARCHAR(45) NOT NULL, 4. PRIMARY KEY (`idregion`) ) 5.ENGINE = InnoDB 6.DEFAULT CHARACTER SET = utf8 7.COLLATE = utf8_unicode_ci; 8.DROP TABLE IF EXISTS `sml_test`.`tb_region` ; 9.DROP TABLE IF EXISTS `sml_test`.`tb_province` ;

Synchronize with DB 1.CREATE TABLE IF NOT EXISTS `sml_test`.`region` ( 2. `idregion` CHAR(1) NOT NULL, 3. `nameregion` VARCHAR(45) NOT NULL, 4. PRIMARY KEY (`idregion`) ) 5.ENGINE = InnoDB 6.DEFAULT CHARACTER SET = utf8 7.COLLATE = utf8_unicode_ci; 8.DROP TABLE IF EXISTS `sml_test`.`tb_region` ; 9.DROP TABLE IF EXISTS `sml_test`.`tb_province` ;

Contents Week-3 Constraints Create table using MySQL Workbench – Collation => Sorting => UTF-8_general/unicode – Storage Engine => MyISAM, InnoDB Select Data into table XML Basics – XML Quizs –

Let’s analyze the possible ID for regions

What is wrong?

Drop primary key of region Now please write down an SQL statement to insert into the region table.

Insert into region insert into select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata;

Insert into region insert into select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata;

Insert into region insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata;

Insert into region insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata;

What should be primary key? insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata; Single column is duplicated

What should be primary key? insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata; How about two columns for PK.

What should be primary key? insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata; How about two columns for PK.

What should be primary key? insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata; How about two columns for PK.

What should be primary key? How about two columns for PK.

Synchronize database Alter table sml_test.region Add primary key(idregion, nameregion); Data still exists

Contents Week-4 Create table using MySQL Workbench – Collation => Sorting => UTF-8_general/unicode – Storage Engine => MyISAM, InnoDB Populate Data: Select Data into table Join Optimization XML Basics – DOM

Join Optimization 80,000 8,

Join Optimization 80,000 8, How about join them back together?

Join Optimization 80,000 8, How about join them back together?

Response Time-1 -- Second query select region_name, prov_name,amp_name from region r, province p, amphur a where r.region_id = p.region_id and p.prov_id = a.prov_id;

Response Time-2 select region_name, prov_name,amp_name, tam_name from region r, province p, amphur a, tambon t where r.region_id = p.region_id and p.prov_id = a.prov_id and a.amp_id = t.amp_id;

Response Time-3 select region_name, prov_name,amp_name, tam_name, vill_name from region r, province p, amphur a, tambon t, village v where r.region_id = p.region_id and p.prov_id = a.prov_id and a.amp_id = t.amp_id and t.tam_id = v.tam_id;

Join Optimization How about join them back together? 80,000 8,

phpMyAdmin

How to speed up a join?

Create Index

How to speed up a join? Create Index

How to speed up a join? Create Index

How to speed up a join? Create Index Which table should be considered? Which column should be considered? 80,000 8,

Create Index Village Table

Response Time-3 select region_name, prov_name,amp_name, tam_name, vill_name from region r, province p, amphur a, tambon t, village v where r.region_id = p.region_id and p.prov_id = a.prov_id and a.amp_id = t.amp_id and t.tam_id = v.tam_id;

What if We remove an index on village.tam_id? select region_name, prov_name,amp_name, tam_name, vill_name from region r, province p, amphur a, tambon t, village v where r.region_id = p.region_id and p.prov_id = a.prov_id and a.amp_id = t.amp_id and t.tam_id = v.tam_id;

What if We remove an index on village.tam_id? select region_name, prov_name,amp_name, tam_name, vill_name from region r, province p, amphur a, tambon t, village v where r.region_id = p.region_id and p.prov_id = a.prov_id and a.amp_id = t.amp_id and t.tam_id = v.tam_id; remove an index Has an index

Where else that we can add indexes?

Can we create index on every column?

Where else that we can add indexes? Can we create index on every column?

Contents Week-3 Create table using MySQL Workbench – Collation => Sorting => UTF-8_general/unicode – Storage Engine => MyISAM, InnoDB Populate Data: Select Data into table Join Optimization XML Basics – DOM

DOM

XML => Book

DOM Nodes

Node Tree

Node Type Property

Node List

DOM XPath::query Returns a DOMNodeList containing all nodes matching the given XPath expression

DOM $my_xpath_query = "/";

DOM $my_xpath_query =

DOM $my_xpath_query = != 0) and != '#')]";

DOM $my_xpath_query = != 0) and != '#')]";

Week-4-Home-Work

End of Week-4 Lecture