Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Systems Week 12 by Zohaib Jan.

Similar presentations


Presentation on theme: "Database Systems Week 12 by Zohaib Jan."— Presentation transcript:

1 Database Systems Week 12 by Zohaib Jan

2 XML Standard for data representation and exchange Similar to HTML
Tags describe contents of data

3 XML Hierarchical (Tree) Data Model
The basic object in XML is the XML document. Two main structuring concepts are used to construct an XML document Elements Attributes

4 Book Store XML Bookstore will have Books Books will have titles
Books will have authors

5 XML Complex elements are constructed from other elements hierarchically Simple elements contain data values

6 XML vs Relational Model
Structure Schema Queries Ordering Implementation

7 Well formed XML Adheres to basic structural requirements.
Single root elements Matched tags, proper nesting Unique attributes within elements XML DOCUMENTS >> XML PARSER >> WELL / NOT FORMED

8 Valid xml A valid XML has 2 things DTD XSD

9 DTD Grammar like language for specifying elements, attributes, nesting, ordering Also special attribute types ID and IDREF(s)

10 Why Use a DTD? With a DTD, independent groups of people can agree on a standard DTD for interchanging data. An application can use a DTD to verify that XML data is valid. Ref: w3schools

11 XML with inline DTD <?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note>

12 XML with external DTD <?xml version="1.0"?> <!DOCTYPE note SYSTEM "note.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>

13 The Building Blocks of XML Documents
Seen from a DTD point of view, all XML documents are made up by the following building blocks: Elements Attributes Entities PCDATA CDATA

14 DTD So lets create bookstore DTD

15 DTD <!DOCTYPE Bookstore[ <!Element Bookstore (Book*, Author*)> <!Element Book (Title, Remark?)> <!Attlist Book ISBN ID #REQUIRED PRICE CDATA #REQUIRED Authors IDREFS #REQUIRED> <!Element Title (#PCDATA)> <!Element Remark (#PCDATA | BookRef)*> <!Element BookRef Empty> <!Attlist BookRef book IDREF #REQUIRED> <!ELEMENT author (First_Name, Last_Name)> <!Attlist Author Ident ID #REQUIRED> ]>

16 XSDs XML Schema Description XSD is written in XML
Extensive language Can pretty much do anything like DTD but much more XSD is written in XML An XML Schema describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD).

17 XSD <?xml version="1.0"?> <xs:schema xmlns:xs=" <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>

18 External XSD <?xml version="1.0"?> <note xmlns=" xmlns:xsi=" xsi:schemaLocation="note.xsd"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>

19 JSON Standard for serializing data objects
When exchanging data between a browser and a server, the data can only be text. JSON is text, and we can convert any JavaScript object into JSON, and send JSON to the server. We can also convert any JSON received from the server into JavaScript objects. This way we can work with the data as JavaScript objects, with no complicated parsing and translations.

20 JSON Is not as rigid as XML and is also light weight

21 JSON JSON syntax is derived from JavaScript object notation syntax:
Data is in name/value pairs Data is separated by commas Curly braces hold objects Square brackets hold arrays

22 JSON datatype In JSON, values must be one of the following data types:
a string a number an object (JSON object) an array a boolean null In JavaScript values can be all of the above, plus any other valid JavaScript expression, including: a function a date undefined

23 JSON vs XML Both JSON and XML can be used to receive data from a web server. {"employees":[ { "firstName":"John", "lastName":"Doe" }, { "firstName":"Anna", "lastName":"Smith" }, { "firstName":"Peter", "lastName":"Jones" } ]} <employees> <employee> <firstName>John</firstName> <lastName>Doe</lastName> </employee> <firstName>Anna</firstName> <lastName>Smith</lastName> <firstName>Peter</firstName> <lastName>Jones</lastName> </employees>

24 JSON Book Store { "Books": [ { "ISBN":"ISBN ", "Price":85, "Edition":3, "Title":"A First Course in Database Systems", "Authors":[ {"First_Name":"Jeffrey", "Last_Name":"Ullman"}, {"First_Name":"Jennifer", "Last_Name":"Widom"} ] } , { "ISBN":"ISBN ", "Price":100, "Remark":"Buy this book bundled with 'A First Course' - a great deal!", "Title":"Database Systems:The Complete Book", "Authors":[ {"First_Name":"Hector", "Last_Name":"Garcia-Molina"}, {"First_Name":"Jeffrey", "Last_Name":"Ullman"}, ], "Magazines": { "Title":"National Geographic", "Month":"January", "Year":2009 } { "Title":"Newsweek", "Month":"February", ] }

25 JSON Schema { "type":"object", "properties": { "Books": { "type":"array", "items": { "type":"object", "ISBN": { "type":"string", "pattern":"ISBN*" }, "Price": { "type":"integer", "minimum":0, "maximum":200 }, "Edition": { "type":"integer", "optional": true }, "Remark": { "type":"string", "optional": true }, "Title": { "type":"string" }, "Authors": { "minItems":1, "maxItems":10, "First_Name": { "type":"string" }, "Last_Name": { "type":"string" }}}}}}}, "Magazines": { "Month": { "type":"string", "enum":["January","February"] }, "Year": { "type":"integer" }}}} }}

26 NO SQL Not every data problem is solved using a traditional relational DBMS NOSQL means not using traditional DBMS

27 Benefits of NOSQL Flexible schema Cheaper and quicker to setup
Massive scalability Relaxed consistency

28 No SQL Most important motivation for nosql is we don’t know the schema or structure of the data before hand Large quantities of unstructured data Scalable Massive data Solution Hadoop Nosql

29 Nosql Nosql is JSON known is Byson

30

31 NoSQL Hadoop >> Mapreduce Document stores Graph Databases
GFS HDFS Provide functions Map(), Reduce(0 Reader(), Writer(), Combiner() Document stores Graph Databases Column stores

32 Reviews


Download ppt "Database Systems Week 12 by Zohaib Jan."

Similar presentations


Ads by Google