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
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)
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
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. )