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 XMLXML 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 XMLElements (Tags) are the primary components of XML documents. JAMES RUSSEL
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 idComments stats with
XML DTDA 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. cXML Document is valid if it has an attached DTD and document is structured according to rules defined in DTD.
DTD Example
RICHRD KARTER
LASTNAME(#PCDATA)>
]>
Xml Document And Corresponding DTD
XML SchemaServes same purpose as database schemaSchemas are written in XMLSet of pre-defined simple types (such as string, integer)Allows creation of user-defined complex types
XML SchemaRDBMS Schema (s_id integer, s_name string, s_status string)
XMLSchema
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
XQueryXQuery 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
XPath: /Student[Name=John]/EmailExtracts: element with value [email protected]
Oracle and XMLXML Support in Oracle
XDK (XML Developer Kit) XML Parser for PL/SQL XPath XSLT
Oracle and XMLXML documents are stored as XML Type ( data type for XML ) in OracleInternally CLOB is used to store XMLTo store XML in database create table with one XMLType columnEach row will contain one of XML records from XML documentDatabase Table: XML DocumentDatabase Row : XML Record
Examples
John120 Northwestern AvePaul120 N. Salisbury
ExampleTO PRINT PATIENT ID of ALL PATIENTS
SELECT EXTRACT(p.patientRecord, '/Patient/@id').getStringVal()FROM prTable p;
USE XPATH
Oracle JDBCJDBC an API used for database connectivityCreates Portable ApplicationsBasic Steps to develop JDBC ApplicationImport JDBC classes (java.sql.*).Load JDBC driversConnect and Interact with database Disconnect from database
Oracle JDBCDriverManager provides basic services to manage set of JDBC driversConnection object sends queries to database server after a connection is set upJDBC provides following three classes for sending SQL statements to server
Statement SQL statements without parametersPreparedStatement SQL statements to be executed multiple times with different parametersCallableStatement Used for stored procedures
Oracle JDBCSQL query can be executed using any of the objects. (Statement,PreparedStatement,CallableStatement)Syntax (Statement Object )Public abstract ResultSet executeQuery(String sql) throws SQLExceptionSyntax (PreparedStatement,CallableStatement Object )Public abstract ResultSet executeQuery() throws SQLExceptionMethod 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