SlideShare a Scribd company logo
Introduction to XML
CS348 Information System
Guest Lecture
Hazem
Elmeleegy
Outline
 What is XML?
 Syntax of XML Document
 DTD (Document Type Definition)
 XML Query Language
 XML Databases
 XML Schema
 Oracle JDBC
Introduction to XML
 XML stands for EXtensible Markup Language
 XML was designed to describe data.
 XML tags are not predefined unlike HTML
 XML DTD and XML Schema define rules to describe data
 XML example of semi structured data
Building Blocks of XML
 Elements (Tags) are the primary components of XML
documents.
<AUTHOR id = 123>
<FNAME> JAMES</FNAME>
<LNAME> RUSSEL</LNAME>
</AUTHOR> <!- I am comment ->
Element FNAME nested inside
element Author.
 Attributes provide additional information about Elements.
Values of the Attributes are set inside the Elements
Element
Author with
Attr id
 Comments stats with <!- and end with ->
XML DTD
 A DTD is a set of rules that allow us to specify
our own set of elements and attributes.
 DTD is grammar to indicate what tags are
legal in XML documents. c
 XML Document is valid if it has an attached DTD and
document is structured according to rules defined in DTD.
DTD Example
<BOOKLIST>
<BOOK GENRE = “Science”
FORMAT = “Hardcover”>
<AUTHOR>
<FIRSTNAME>
RICHRD
</FIRSTNAME>
<LASTNAME> KARTER
</LASTNAME>
</AUTHOR>
</BOOK>
</BOOKS>
<!DOCTYPE BOOKLIST[
<!ELEMENT BOOKLIST(BOOK)*> <!
ELEMENT BOOK(AUTHOR)>
<!ELEMENT
AUTHOR(FIRSTNAME,LASTNAME)>
<!ELEMENT FIRSTNAME(#PCDATA)>
<!ELEMENT>LASTNAME(#PCDATA)>
<!ATTLIST BOOK GENRE (Science|
Fiction)#REQUIRED>
<!ATTLIST BOOK FORMAT
(Paperback|Hardcover)
“PaperBack”>]>
Xml Document And
Corresponding DTD
XML Schema
 Serves same purpose as database schema
 Schemas are written in XML
 Set of pre-defined simple types (such as string, integer)
 Allows creation of user-defined complex
types
XML Schema
 RDBMS Schema (s_id integer, s_name string, s_status string)
<Students>
<Student id=“p1”>
<Name>Allan</Name>
<Age>62</Age>
<Email>allan@abc.com
</Email>
</Student>
</Students>
 XMLSchema
<xs:schema>
<xs:complexType name = “StudnetType”>
<xs:attribute name=“id” type=“xs:string” />
<xs:element name=“Name” type=“xs:string />
<xs:element name=“Age” type=“xs:integer” />
<xs:element name=“Email” type=“xs:string” />
</xs:complexType>
<xs:element name=“Student” type=“StudentType” />
</xs:schema>
XML Document and Schema
XML Query Languages
 Requirement
Same functionality as database query
languages (such as SQL) to process Web
data
 Advantages
 Query selective portions of the document (no
need to transport entire document)
 Smaller data size mean lesser
communication cost
XQuery
 XQuery to XML is same as SQL to
RDBMS
 Most databases supports XQuery
 XQuery is built on XPath operators
(XPath is a language that defines path
expressions to locate document data)
XPath Example
<Student id=“s1”>
<Name>John</Name>
<Age>22</Age>
<Email>jhn@xyz.com</Email>
</Student>
XPath: /Student[Name=“John”]/Email
Extracts: <Email> element with value
“jhn@xyz.com”
Oracle and XML
 XML Support in Oracle
XDK (XML Developer Kit)
XML Parser for PL/SQL
XPath
XSLT
Oracle and XML
 XML documents are stored as XML Type ( data type
for XML ) in Oracle
 Internally CLOB is used to store XML
 To store XML in database create table with one
XMLType column
 Each row will contain one of XML records from XML
document
 Database Table: XML Document
 Database Row : XML Record
Examples
<Patients>
<Patient id=“p1”>
<Name>John</Name>
<Address>
<Street>120 Northwestern Ave</Street>
</Address>
</Patient>
<Patient id=“p2”>
<Name>Paul</Name>
<Address>
<Street>120 N. Salisbury</Street>
</Address>
</Patient>
</Patients>
Example
 Create table prTable(patientRecord XMLType);
 DECLARE
 prXML CLOB;
 BEGIN
 -- Store Patient Record XML in the CLOB variable
 prXML := '<Patient id=“p1">
 <Name>John</Name>
 <Address>
 <Street>120 Northwestern Ave</Street>
 </Address>
 </Patient>‘ ;
 -- Now Insert this Patient Record XML into an XMLType column
 INSERT INTO prTable (patientRecord) VALUES
(XMLTYPE(prXML));
 END;
Example
TO PRINT PATIENT ID of ALL PATIENTS
SELECT
EXTRACT(p.patientRecord,
'/Patient/@id').getStringVal()
FROM prTable p;
USE XPATH
Oracle JDBC
 JDBC an API used for database connectivity
 Creates Portable Applications
 Basic Steps to develop JDBC Application
 Import JDBC classes (java.sql.*).
 Load JDBC drivers
 Connect and Interact with database
 Disconnect from database
Oracle JDBC
 DriverManager provides basic services to
manage set of JDBC drivers
 Connection object sends queries to database
server after a connection is set up
 JDBC provides following three classes for
sending SQL statements to server
 Statement SQL statements without parameters
 PreparedStatement SQL statements to be executed multiple times with different parameters
 CallableStatement Used for stored procedures
Oracle JDBC
 SQL query can be executed using any of the
objects.
(Statement,PreparedStatement,CallableStatement)
 Syntax (Statement Object )
Public abstract ResultSet executeQuery(String sql) throws
SQLException
 Syntax (PreparedStatement,CallableStatement Object )
Public abstract ResultSet executeQuery() throws SQLException
 Method executes SQL statement that returns
ResultSet object (ResultSet maintains cursor
pointing to its current row of data. )
Oracle JDBC (Example)
Import java.sql.*;
Import java.io;
Class simple{
public static void main(String[] args) throws Exception{
Connection conn=null;
try{
String conStr = "jdbc:oracle:thin:@oracle.cs.purdue.edu:1521:orb";
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection(conStr,”username”,”passwd");
Statement cursor = conn.createStatement(); // Connection Est.
ResultSet rset = stmt.executeQuery(“Select* from table_name”);
while(orset.next()){
System.out.println(“Printing column name ”+orest.getStringVal(1));
}
}Catch(ClassNotFoundException e){}
cursor.close();
conn.close();
}
}
References
 [1] Database Management Systems by Ramakrishnan and Gehrke
Thank You

More Related Content

PPTX
Introduction to XML
PDF
Developer & Fusion Middleware 1 | Mark Drake | An introduction to Oracle XML ...
PPTX
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
PPT
unit_5_XML data integration database management
PPTX
advDBMS_XML.pptx
PPT
DATA INTEGRATION (Gaining Access to Diverse Data).ppt
PPT
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
PPT
XML and Databases
Introduction to XML
Developer & Fusion Middleware 1 | Mark Drake | An introduction to Oracle XML ...
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 1
unit_5_XML data integration database management
advDBMS_XML.pptx
DATA INTEGRATION (Gaining Access to Diverse Data).ppt
Real World Experience With Oracle Xml Database 11g An Oracle Ace’s Perspectiv...
XML and Databases

Similar to XMLLec1 (1xML lecturefsfsdfsdfdsfdsfsdfsdfdsf (20)

PDF
SQL/XML on Oracle
PPTX
XML-Extensible Markup Language
PPT
XML Amsterdam - Creating structure in unstructured data
PPTX
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
PDF
PostgreSQL and XML
DOC
PPT
Xml 215-presentation
PDF
XML Schema.pdf
PPTX
XML_Chapter13 presentation from the textbook
PPT
DB2 Native XML
PPTX
Xml schema
PDF
E05412327
PPT
Xml 215-presentation
PPTX
Introduction to XML
PDF
Xml databases
PDF
Xml schema
PPTX
Hotsos 2013 - Creating Structure in Unstructured Data
PPTX
XML Schema.pptx
PPTX
XML DATABASES in the Master of Engineering
SQL/XML on Oracle
XML-Extensible Markup Language
XML Amsterdam - Creating structure in unstructured data
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
PostgreSQL and XML
Xml 215-presentation
XML Schema.pdf
XML_Chapter13 presentation from the textbook
DB2 Native XML
Xml schema
E05412327
Xml 215-presentation
Introduction to XML
Xml databases
Xml schema
Hotsos 2013 - Creating Structure in Unstructured Data
XML Schema.pptx
XML DATABASES in the Master of Engineering
Ad

Recently uploaded (20)

PPTX
Taita Taveta Laboratory Technician Workshop Presentation.pptx
PPTX
2. Earth - The Living Planet earth and life
PDF
bbec55_b34400a7914c42429908233dbd381773.pdf
PPTX
neck nodes and dissection types and lymph nodes levels
PDF
ELS_Q1_Module-11_Formation-of-Rock-Layers_v2.pdf
PPTX
TOTAL hIP ARTHROPLASTY Presentation.pptx
PPTX
Classification Systems_TAXONOMY_SCIENCE8.pptx
PPTX
SCIENCE10 Q1 5 WK8 Evidence Supporting Plate Movement.pptx
PDF
diccionario toefl examen de ingles para principiante
PPTX
GEN. BIO 1 - CELL TYPES & CELL MODIFICATIONS
PPTX
microscope-Lecturecjchchchchcuvuvhc.pptx
PPTX
The KM-GBF monitoring framework – status & key messages.pptx
PDF
Biophysics 2.pdffffffffffffffffffffffffff
PPTX
ognitive-behavioral therapy, mindfulness-based approaches, coping skills trai...
PDF
SEHH2274 Organic Chemistry Notes 1 Structure and Bonding.pdf
PDF
CAPERS-LRD-z9:AGas-enshroudedLittleRedDotHostingaBroad-lineActive GalacticNuc...
PPTX
Microbiology with diagram medical studies .pptx
PDF
An interstellar mission to test astrophysical black holes
PPTX
7. General Toxicologyfor clinical phrmacy.pptx
DOCX
Q1_LE_Mathematics 8_Lesson 5_Week 5.docx
Taita Taveta Laboratory Technician Workshop Presentation.pptx
2. Earth - The Living Planet earth and life
bbec55_b34400a7914c42429908233dbd381773.pdf
neck nodes and dissection types and lymph nodes levels
ELS_Q1_Module-11_Formation-of-Rock-Layers_v2.pdf
TOTAL hIP ARTHROPLASTY Presentation.pptx
Classification Systems_TAXONOMY_SCIENCE8.pptx
SCIENCE10 Q1 5 WK8 Evidence Supporting Plate Movement.pptx
diccionario toefl examen de ingles para principiante
GEN. BIO 1 - CELL TYPES & CELL MODIFICATIONS
microscope-Lecturecjchchchchcuvuvhc.pptx
The KM-GBF monitoring framework – status & key messages.pptx
Biophysics 2.pdffffffffffffffffffffffffff
ognitive-behavioral therapy, mindfulness-based approaches, coping skills trai...
SEHH2274 Organic Chemistry Notes 1 Structure and Bonding.pdf
CAPERS-LRD-z9:AGas-enshroudedLittleRedDotHostingaBroad-lineActive GalacticNuc...
Microbiology with diagram medical studies .pptx
An interstellar mission to test astrophysical black holes
7. General Toxicologyfor clinical phrmacy.pptx
Q1_LE_Mathematics 8_Lesson 5_Week 5.docx
Ad

XMLLec1 (1xML lecturefsfsdfsdfdsfdsfsdfsdfdsf

  • 1. Introduction to XML CS348 Information System Guest Lecture Hazem Elmeleegy
  • 2. Outline  What is XML?  Syntax of XML Document  DTD (Document Type Definition)  XML Query Language  XML Databases  XML Schema  Oracle JDBC
  • 3. Introduction to XML  XML stands for EXtensible Markup Language  XML was designed to describe data.  XML tags are not predefined unlike HTML  XML DTD and XML Schema define rules to describe data  XML example of semi structured data
  • 4. Building Blocks of XML  Elements (Tags) are the primary components of XML documents. <AUTHOR id = 123> <FNAME> JAMES</FNAME> <LNAME> RUSSEL</LNAME> </AUTHOR> <!- I am comment -> Element FNAME nested inside element Author.  Attributes provide additional information about Elements. Values of the Attributes are set inside the Elements Element Author with Attr id  Comments stats with <!- and end with ->
  • 5. XML DTD  A DTD is a set of rules that allow us to specify our own set of elements and attributes.  DTD is grammar to indicate what tags are legal in XML documents. c  XML Document is valid if it has an attached DTD and document is structured according to rules defined in DTD.
  • 6. DTD Example <BOOKLIST> <BOOK GENRE = “Science” FORMAT = “Hardcover”> <AUTHOR> <FIRSTNAME> RICHRD </FIRSTNAME> <LASTNAME> KARTER </LASTNAME> </AUTHOR> </BOOK> </BOOKS> <!DOCTYPE BOOKLIST[ <!ELEMENT BOOKLIST(BOOK)*> <! ELEMENT BOOK(AUTHOR)> <!ELEMENT AUTHOR(FIRSTNAME,LASTNAME)> <!ELEMENT FIRSTNAME(#PCDATA)> <!ELEMENT>LASTNAME(#PCDATA)> <!ATTLIST BOOK GENRE (Science| Fiction)#REQUIRED> <!ATTLIST BOOK FORMAT (Paperback|Hardcover) “PaperBack”>]> Xml Document And Corresponding DTD
  • 7. XML Schema  Serves same purpose as database schema  Schemas are written in XML  Set of pre-defined simple types (such as string, integer)  Allows creation of user-defined complex types
  • 8. XML Schema  RDBMS Schema (s_id integer, s_name string, s_status string) <Students> <Student id=“p1”> <Name>Allan</Name> <Age>62</Age> <Email>allan@abc.com </Email> </Student> </Students>  XMLSchema <xs:schema> <xs:complexType name = “StudnetType”> <xs:attribute name=“id” type=“xs:string” /> <xs:element name=“Name” type=“xs:string /> <xs:element name=“Age” type=“xs:integer” /> <xs:element name=“Email” type=“xs:string” /> </xs:complexType> <xs:element name=“Student” type=“StudentType” /> </xs:schema> XML Document and Schema
  • 9. XML Query Languages  Requirement Same functionality as database query languages (such as SQL) to process Web data  Advantages  Query selective portions of the document (no need to transport entire document)  Smaller data size mean lesser communication cost
  • 10. XQuery  XQuery to XML is same as SQL to RDBMS  Most databases supports XQuery  XQuery is built on XPath operators (XPath is a language that defines path expressions to locate document data)
  • 11. XPath Example <Student id=“s1”> <Name>John</Name> <Age>22</Age> <Email>jhn@xyz.com</Email> </Student> XPath: /Student[Name=“John”]/Email Extracts: <Email> element with value “jhn@xyz.com”
  • 12. Oracle and XML  XML Support in Oracle XDK (XML Developer Kit) XML Parser for PL/SQL XPath XSLT
  • 13. Oracle and XML  XML documents are stored as XML Type ( data type for XML ) in Oracle  Internally CLOB is used to store XML  To store XML in database create table with one XMLType column  Each row will contain one of XML records from XML document  Database Table: XML Document  Database Row : XML Record
  • 14. Examples <Patients> <Patient id=“p1”> <Name>John</Name> <Address> <Street>120 Northwestern Ave</Street> </Address> </Patient> <Patient id=“p2”> <Name>Paul</Name> <Address> <Street>120 N. Salisbury</Street> </Address> </Patient> </Patients>
  • 15. Example  Create table prTable(patientRecord XMLType);  DECLARE  prXML CLOB;  BEGIN  -- Store Patient Record XML in the CLOB variable  prXML := '<Patient id=“p1">  <Name>John</Name>  <Address>  <Street>120 Northwestern Ave</Street>  </Address>  </Patient>‘ ;  -- Now Insert this Patient Record XML into an XMLType column  INSERT INTO prTable (patientRecord) VALUES (XMLTYPE(prXML));  END;
  • 16. Example TO PRINT PATIENT ID of ALL PATIENTS SELECT EXTRACT(p.patientRecord, '/Patient/@id').getStringVal() FROM prTable p; USE XPATH
  • 17. Oracle JDBC  JDBC an API used for database connectivity  Creates Portable Applications  Basic Steps to develop JDBC Application  Import JDBC classes (java.sql.*).  Load JDBC drivers  Connect and Interact with database  Disconnect from database
  • 18. Oracle JDBC  DriverManager provides basic services to manage set of JDBC drivers  Connection object sends queries to database server after a connection is set up  JDBC provides following three classes for sending SQL statements to server  Statement SQL statements without parameters  PreparedStatement SQL statements to be executed multiple times with different parameters  CallableStatement Used for stored procedures
  • 19. Oracle JDBC  SQL query can be executed using any of the objects. (Statement,PreparedStatement,CallableStatement)  Syntax (Statement Object ) Public abstract ResultSet executeQuery(String sql) throws SQLException  Syntax (PreparedStatement,CallableStatement Object ) Public abstract ResultSet executeQuery() throws SQLException  Method executes SQL statement that returns ResultSet object (ResultSet maintains cursor pointing to its current row of data. )
  • 20. Oracle JDBC (Example) Import java.sql.*; Import java.io; Class simple{ public static void main(String[] args) throws Exception{ Connection conn=null; try{ String conStr = "jdbc:oracle:thin:@oracle.cs.purdue.edu:1521:orb"; DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); conn = DriverManager.getConnection(conStr,”username”,”passwd"); Statement cursor = conn.createStatement(); // Connection Est. ResultSet rset = stmt.executeQuery(“Select* from table_name”); while(orset.next()){ System.out.println(“Printing column name ”+orest.getStringVal(1)); } }Catch(ClassNotFoundException e){} cursor.close(); conn.close(); } }
  • 21. References  [1] Database Management Systems by Ramakrishnan and Gehrke