XML Fundamentals Sg
XML Fundamentals Sg
s a
h a
s ฺrs) ฺ
XML Fundamentals @ em uide
o v ic t G
t o r den
s
aj s Stu
ฺ m
a Studenthi Guide
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
D64794GC11
Edition 1.1
June 2014
D86758
Author Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
publish, license, post, transmit, or distribute this document in whole or in part without
Brian Fry the express authorization of Oracle.
Diganta Choudhury
The information contained in this document is subject to change without notice. If you
Doug Mcmahon find any problems in the document, please report them in writing to: Oracle University,
500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not
Geeta Arora warranted to be error-free.
Gerry Jurrens
Restricted Rights Notice
Hui X Zhang
Janarthanan Mohan If this documentation is delivered to the United States Government or anyone using
the documentation on behalf of the United States Government, the following notice is
Jeffrey Stephenson applicable:
s a
Lakshmi Narapareddi
U.S. GOVERNMENT RIGHTS h
) or a
Mark Drake The U.S. Government’s rights to use, modify, reproduce, release, perform,
s ฺrsdisplay,
ฺ
Mike Yawn
e
license agreement and/or the applicable U.S. Government contract. m ideOracle
disclose these training materials are restricted by the terms of the applicable
Nageswara Nandimalla
v i c@ t Gu
Nancy Greenberg
Trademark Notice
t o ro den
Pranab Chakraborty Oracle and Java are registered s
j owners.Oracle
trademarks
a of
S t uand/or its affiliates. Other names
Qin Yu
n a ฺm this
may be trademarks of their respective
Radek Felcman
i
nt use
l e
Sailaja
j Pasupuleti
p
c ( va e to
Shay Shmeltzer
r o vi ens
Sriram X Krishnamurthy
j s to le lic
Ying Lu M a rab
t
Zhen Liu
n ina ansfe
le n-tr
VaEditors
no
Daniel Milne
Malavika Jinka
Vijayalakshmi Narasimhan
Richard Wallis
Graphic Designer
Rajiv Chandrabhanu
Publishers
Giri Venugopal
Jayanthy Keshavamurthy
Nita Brozowski
Contents
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Preface
1 Introduction
Objectives 1-2
Course Goals 1-3
Suggested Course Agenda 1-4
Questions About You 1-6
Database Schemas Used in This Course 1-7
s a
Human Resources (hr) Schema 1-8 h a
Order Entry (oe) Schema 1-9
s ฺrs) ฺ
em uide
purchaseorder.xsd Purchase Order XML Schema Used in the XML DB Course 1-10
@
Appendixes 1-11
o v ic t G
Class Account Information 1-12 t o r den
s
aj s Stu
Course Environment 1-13
a ฺ m hi
t i n t
Entering SQL Statements by Using Oracle SQL*Plus in a Terminal Window 1-14
e
Using Oracle JDeveloper 1-15
a l en o us
i c (v se t
Entering SQL Statements and Coding PL/SQL by Using Oracle SQL
Developer 1-16
t o rov licen
a js ble
Related Oracle University Courses: education.oracle.com 1-17
a M fera
Additional Information 1-18
n t i n n s
l e r a
Oracle Database 12c Release 1 (12.1) Documentation 1-19
Va non-tAdditional Resources: Using “Oracle by Example” (OBE) in the Online
Learning Library 1-21
Additional Resources: Oracle Learning Library (OLL) 1-22
Oracle XML DB Home Page: http://www.oracle.com/technetwork/
database-features/xmldb/overview/index.html 1-23
Oracle JDeveloper Home Page: http://www.oracle.com/technetwork/
developer-tools/jdev/overview/index.html 1-24
Additional Web Resources for XML 1-25
Course Files in the /home/oracle/labs Folder 1-26
JDeveloper Application and Projects in the labs Folder 1-27
Course Environment and Data 1-28
Practice 1-1: Overview 1-29
Summary 1-30
iii
2 Introduction to XML
Objectives 2-2
Lesson Agenda 2-3
Extensible Markup Language 2-4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
iv
Editing XML Documents in Oracle JDeveloper 2-47
Setting Preferences in Oracle JDeveloper 2-48
Quiz 2-49
Summary 2-50
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
t o rov licen
Any Element Declarations 3-15
js ble
Specifying the Cardinality of Elements 3-16
a
a M fera
Specifying the Cardinality of Elements: Examples 3-17
n t i n n s
Attribute Declarations: Syntax and Requirements 3-18
l e r a
Va non-tCDATA and Enumerated Attribute Types 3-20
NOTATION Declaration and Attribute Type 3-21
Specifying Default Attribute Values 3-22
Entities in XML 3-23
General Entity Declarations 3-24
Parameter Entities 3-26
Complete DTD: Example 3-27
Lesson Agenda 3-28
Validating XML Against a DTD 3-29
Using XML Catalogs 3-30
Benefits of Using XML Catalogs 3-31
Quiz 3-33
Summary 3-34
Practice 3: Overview 3-35
v
4 Modularizing XML with Namespaces
Objectives 4-2
What Is an XML Namespace? 4-3
Benefits of Using XML Namespaces 4-4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
vi
Declaring a <sequence> 5-30
Declaring a <choice> 5-31
Declaring an Empty Element 5-32
Using Element Wildcards 5-33
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
t o rov licen
Converting a DTD to an XML Schema 5-51
Quiz 5-52
a js ble
a M fera
Summary 5-53
n t i n n s
Practice 5-2: Overview 5-54
l e r a
Va non-t
6 Navigating XML Documents with XPath
Objectives 6-2
Lesson Agenda 6-3
What Is XML Path Language? 6-4
XPath 1.0 and XPath 2.0 6-5
XPath Terminology: Node Types 6-6
XPath Terminology: Family Relationships 6-7
XPath Model 6-8
Lesson Agenda 6-9
XPath Expressions 6-10
Location Path Expression 6-11
Location Path Expression: Example 6-12
Results of Location Path Expressions 6-13
Results of Location Path Expressions: Examples 6-14
Location Steps in XPath Expressions 6-15
vii
XPath Axes 6-16
XPath Node Test Types 6-17
Selecting Nodes by Using Abbreviated XPath Expressions 6-18
Selecting Nodes by Using Abbreviated XPath Expressions: Examples 6-19
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
viii
Effects of Default Template Rules 7-19
Looping with <xsl:for-each> 7-20
Specifying Output Formats 7-21
Attribute Value Templates 7-22
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
ix
Sequence Expressions 8-21
FLWOR Expressions 8-22
FLWOR Expression Clauses 8-23
departments.xml Document: Example 8-25
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
x
Oracle XML DB Repository: Overview 9-34
What Is the XML DB Repository? 9-35
Mapping a Web Folder to Oracle XML DB Repository 9-36
Mapping a Web Folder to the Oracle XML DB Repository 9-37
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
xi
XSLT 2.0 B-20
Grouping Data B-21
Generating Multiple Outputs B-23
Creating Temporary Trees B-25
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
xii
Preface
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Profile
Before You Begin This Course
Before you begin this course, you should have some experience in SQL.
The following is a list of the suggested prerequisites:
• Basic experience with writing HTML documents
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Related Publications
Oracle Publications
Title Part Number
Oracle XML DB Developer’s Guide 12c Release 1 E17603-09
Oracle Database SQL Language Reference12c Release 1 E17209-14
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<region xmlns:xsi="http://...">
<region_id>1</region_id>
<region_name>Europe</region_name>
</region>
Va non-t
<!ELEMENT name (#PCDATA)>
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Introduction
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Objectives
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s discusses the course goals and the daily agenda of topics. The XML
e n
This introductory
r a n
lesson
al onand
terminology
V -t XML standards used in this course are briefly described.
n products that support development of XML data, XML applications, and storage
The Oracle
for XML data are identified. The technical environment of the course and data used are
described followed by instructions about using JDeveloper to open and edit XML documents
and about using a web browser to view the document.
XML Fundamentals 1 - 2
Course Goals
XML Fundamentals 1 - 3
Suggested Course Agenda
Day 1:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
1. Introduction
2. Introduction to XML
3. Validating XML Documents with Document Type
Definitions (DTDs)
4. Modularizing XML with Namespaces
5. Validating XML Documents with XML Schemas s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n
The agendai n n s
t is aasuggested list of lessons to be covered each day. It is possible that the
l e t r
a omay
schedule
V n- differ each time the course is delivered. Day 1 is devoted to the following
aspectsnof XML:
• Introduction to the course, the environment, and the tools used
• XML standards and basics of using some of these standards, such as validating XML
documents with DTDs and XML schemas
• Using XML namespaces and XML schemas
XML Fundamentals 1 - 4
Suggested Course Agenda
Day 2:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 1 - 5
Questions About You
XML Fundamentals 1 - 6
Database Schemas Used in This Course
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t company s in the sample schemas operates worldwide to fulfill orders for several
e n
The fictitious
r a n
al oThe
products.
V n -tcompany has several divisions, with each division represented by a schema:
• Then Human Resources division tracks information about the company’s employees and
facilities. All the scripts that are necessary to create the HR schema are in the
$ORACLE_HOME/demo/schema/human_resources folder.
• The Order Entry division tracks product inventories and sales of the company’s products
through various channels. All the scripts that are necessary to create the OE schema are
in the $ORACLE_HOME/demo/schema/order_entry folder.
Notes
• Appendix A (“Table Descriptions”) contains more information about the sample
schemas.
• The code examples and the practices in this course specify the schema that must be
used.
XML Fundamentals 1 - 7
Human Resources (hr) Schema
DEPARTMENTS LOCATIONS
department_id location_id
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
department_name street_address
manager_id postal_code
location_id city
state_province
country_id
JOB_HISTORY
employee_id
start_date EMPLOYEES
end_date employee_id
job_id first_name
last_name COUNTRIES
department_id country_id
email
phone_number country_name s a
hire_date region_id
) h a
job_id
salary r s
sฺ eฺ
commission_pct m
e uid
JOBS manager_id
c @
job_id department_id
r o vi nt G
job_title
min_salary
j s t o ude REGIONS
max_salary
ฺ m a s St region_id
region_name
a h i
e n tin se t
( v al to u
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
In the HR
n t na neach
irecords, s feemployee has an identification number, email address, job
ale on-code,
identification
V tra salary, and manager. Some employees earn commissions in addition to
n
their salary.
The company also tracks information about jobs within the organization. Each job has an
identification code, job title, and a minimum and maximum salary range for the job. Some
employees have been with the company for a long time and have held different positions
within the company. When an employee resigns, the duration for which the employee worked,
the job identification number, and the department are recorded.
The sample company is regionally diverse, so it tracks the locations of its warehouses and
departments. Each employee is assigned to a department and each department is identified
by a unique department number or a short name. Each department is associated with one
location, and each location has a full address that includes the street name, postal code, city,
state or province, and the country code.
In places where the departments and warehouses are located, the company records details
such as the country name, currency symbol, currency name, and the region where the country
is located geographically.
XML Fundamentals 1 - 8
Order Entry (oe) Schema
CUSTOMERS
customer_id
ORDER_ITEM cust_first_name
order_id ORDERS cust_ last_name
order_id
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
line_item_id
product_id order_date cust_ address_typ
unit_price order_mode
quantity customer_id street_address
order_status postal_code
order_total city
sales_rep_id state_province
promotion_id country_id
phone_numbers
PRODUCT_ nls_language
INFORMATION PRODUCT_ nls_territory
DESCRIPTION credit_limit
product_id
product_id cust_ email s a
product_name language_id account_mgr_id
date_of_birth ) h a
product_description
category_id
product_name
product_description marital_status r s
sฺ eฺ
weight_class
Gender
Income_level m
e uid
c @
warranty_period
supplier_id r o vi nt G
product_status
INVENTORIES
warehouse_id aj
product_id sto StuWAREHOUSES de
warehouse_id
list_price
min_price a
quantity_on_hand
n ฺm this warehouse_name
catalog_url n t i s e location_id
e
al to u
( v
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
n t ina sells
The company n s fe categories of products, including computer hardware and
several
ale omusic,
software,
V n -traclothing, and tools. The company maintains product information that includes
n
product identification numbers, the category to which the product belongs, the weight group
(for shipping purposes), the warranty period (if applicable), the supplier, the status of the
product, a list price, a minimum price at which the product is sold, and a URL for manufacturer
information.
XML Fundamentals 1 - 9
purchaseorder.xsd
Purchase Order XML Schema
Used in the XML DB Course
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
... n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t example s the partial Purchase Order XML schema that is used in the XML DB
e n
The slide
r a nshows
al asoan
course
V n t file, purchaseOrder.xsd.
-XML
n
The Purchase Order XML schema demonstrates some key features of a typical XML
document:
• Global element PurchaseOrder is an instance of the complexType
PurchaseOrderType.
• PurchaseOrderType defines the set of nodes that make up a PurchaseOrder
element.
• LineItems element consists of a collection of LineItem elements.
• Each LineItem element consists of two elements: Description and Part.
• Part element has the following attributes: ID, Quantity, and UnitPrice.
For the complete code listing and graphical representation of the Purchase Order XML
schema, see Chapter 3 (“Using Oracle XML DB”) or Appendix A (“Oracle-Supplied XML
Schemas and Examples”) in the Oracle XML DB Developer’s Guide 12c Release 1 (12.1).
XML Fundamentals 1 - 10
Appendixes
Appendix Title
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Appendix D Glossary
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 1 - 11
Class Account Information
XML Fundamentals 1 - 12
Course Environment
• Client software
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 1 - 13
Entering SQL Statements by Using
Oracle SQL*Plus in a Terminal Window
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
Oraclen t
SQL*Plus a is s
n a command-line application with which you can submit SQL statements
l e
a PL/SQL
and t r
-blocks for execution and receive the results in an application or command
V
window. non
SQL*Plus is:
• Shipped with the database
• Installed on the database server system and accessed from an icon or the command
line
XML Fundamentals 1 - 14
Using Oracle JDeveloper
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s developers can create, edit, test, and debug PL/SQL code by using
t JDeveloper,
e n
With Oracle
r a n
al on-t GUI. Oracle JDeveloper is a part of Oracle Developer Suite and is also
a sophisticated
V n as a separate product.
available
To use JDeveloper with XML, you first create a database connection to enable JDeveloper to
access a database schema owner for the subprograms.
Note: For more information about using JDeveloper, see Appendix C.
XML Fundamentals 1 - 15
Entering SQL Statements and Coding PL/SQL
by Using Oracle SQL Developer
• Oracle SQL Developer is a free graphical tool that
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 1 - 16
Related Oracle University Courses:
education.oracle.com
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 1 - 17
Additional Information
Topic Website
features/xmldb/overview/index.html
Oracle Technology Network (OTN) http://www.oracle.com/technetwork/index.html
XML Fundamentals 1 - 18
Oracle Database 12c Release 1 (12.1)
Documentation
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
You can n i n
taccessathe
n sOracle Database 12c documentation by using the following URL:
e
al on-t r
V
http://www.oracle.com/technology/documentation
n
XML Fundamentals 1 - 19
Oracle Database 12c Release 1 (12.1)
Documentation
Documentation Guide Name
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Oracle Database PL/SQL Packages and Types Reference 12c Release 1 (12.1)
s a
Oracle SQL Developer User’s Guide Release 4.0
h a
Oracle Database Object-Relational Developer’s Guide 12c Release 1 (12.1) s ฺrs) ฺ
@ em uide
Oracle Database SQL JDeveloper Guide 12c Release 1 (12.1)
o v ic t G
t o r den
Oracle Text Reference 12c Release 1 (12.1) s
aj s Stu
a ฺ m hi 1 (12.1)
t i n e t
Oracle Text Application Developer’s Guide
a l en o us 12c Release
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 1 - 20
Additional Resources: Using “Oracle by Example”
(OBE) in the Online Learning Library
OBE tutorials:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 1 - 21
Additional Resources:
Oracle Learning Library (OLL)
You can access OBEs and other material by using the OLL at
http://www.oracle.com/oll.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 1 - 22
Oracle XML DB Home Page:
http://www.oracle.com/technetwork/database-
features/xmldb/overview/index.html
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
You can n i n
taccessathe
n sOracle XML DB home page by using the following URL:
e
al on-t r
V
http://www.oracle.com/technetwork/database-features/xmldb/overview/index.html
n
This page contains useful information such as white papers, technical presentations,
demonstrations, and hands-on practices.
XML Fundamentals 1 - 23
Oracle JDeveloper Home Page:
http://www.oracle.com/technetwork/developer-
tools/jdev/overview/index.html
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 1 - 24
Additional Web Resources for XML
Topic Website
W3C XML Schema http://www.w3.org/XML/Schema
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 1 - 25
Course Files in the /home/oracle/labs Folder
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
t i n
The /home/oracle/labs
n n s folder contains six folders: solns, lab, code_ex, demo,
l e
a onand t r a
- src.
V
classes,
n
Practices and their solutions are found in the /home/oracle/labs/lab and
/home/oracle/labs/solns folders. The solutions are named based on the lesson
number and practice question. For example, the sol_01_03.xml file is the solution code for
question 3 in Practice 1-1.
The code_ex folder contains the scripts or files for most (but not all) of the code examples in
the lessons. The code examples are named based on the lesson number and page number.
The demo folder contains a few demo scripts. The demo scripts are named based on their
functionality.
XML Fundamentals 1 - 26
JDeveloper Application and Projects
in the labs Folder
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s
The /home/oracle/labs
l e n t r a n folder contains the XMLFundamentalsWorkspace JDeveloper
a onThis
application.
V - application contains several projects (as shown in the slide).
n
XML Fundamentals 1 - 27
Course Environment and Data
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Client Database
s a
) h a
r s
sฺ eฺ
m
e uid
c @
JDeveloper 12.1.2 Java and Studio Editions HRrando viOE Schemas
n t G
Mozilla Firefox Web browser a
o uXML
jstOracle t deDB
SQL*Plus a ฺ m his S
e n tin se t
( v al to u
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
Client n t ina ansfe
Software
le n-JDeveloper
tr
V•a Oracle
no
(Java and Studio Editions) for creating, editing, and validating XML
documents
• Mozilla Firefox for viewing XML documents and transformations, and accessing the
Oracle XML DB folder functionality
• SQL*Plus to execute SQL or PL/SQL operations on the database data
• Java classes that use the Oracle XML Parser:
- The ShowXMLns class to display the effects of using XML namespaces
Database Software
• Oracle Database 12c with the Oracle XML DB features installed and enabled
Note: In this course, you use Oracle JDeveloper Java Edition 12.1.2 for most of the practices.
In the last practice in the course, Practice 9-2, titled “Creating a WebDAV Connection Using
JDeveloper,” you use JDeveloper Studio Edition 12.1.2 because creating a WebDAV is not
available in JDeveloper Java Edition.
XML Fundamentals 1 - 28
Practice 1-1: Overview
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t to annotates data by using markup to describe the data. Markup tags are user
XML isnused
e r a n
V al and
defined
o n -t therefore extensible to suit the requirements of the author or application that
are
createsnthe document.
XML standards are W3C recommendations. If you are adhering to the XML
recommendations, your XML documents must have their structure defined by a DTD or an
XML schema, thereby enabling the document to be validated and meaningfully processed by
all its consumers.
Extensible Stylesheet Language (XSL) processors can consume an XML document, enabling
it to be transformed and formatted into another type of document. Using XPath expressions,
XSL processors can search for the desired XML elements to be transformed and formatted
according to the rules specified in a stylesheet.
JDeveloper provides the tools needed to create, edit, perform well-formed checks on, and
validate XML documents. JDeveloper can be enabled to access external tools to perform
operations on XML documents.
XML Fundamentals 1 - 30
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Introduction to XML
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Objectives
XML Fundamentals 2 - 2
Lesson Agenda
XML Fundamentals 2 - 3
Extensible Markup Language
Web data
Markup and data a
h a s
s ฺrs) ฺ
XML document
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
n t i n e t XML processors
Custom tags
v a le to us
v i c ( nse
t o ro © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
s
aj rable
M
n t ina data
XML describes n s fe called XML documents that:
objects
le composed
V•a Are n - tra of markup language for structuring the document data
no custom tags for data definition, transmission, validation, and interpretation
• Support
• Have become a standard way to describe data on the web
• Are processed by XML processors
XML was developed by an XML working group headed by the World Wide Web Consortium
(W3C) with the following design goals:
• XML is usable over the Internet.
• It supports a wide variety of applications.
• It is compatible with Standard Generalized Markup Language (SGML).
• XML can be processed using easy-to-write programs.
• It has a minimum number of optional features.
• XML is human-legible and reasonably clear.
• XML enables quick design preparation.
• It enables formal and concise design.
• XML documents are easy to create.
• XML documents can be verbose.
XML Fundamentals 2 - 4
Advantages of Using XML
XML enables:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 2 - 5
XML Standards
validates validates 5
Document type
definition (DTD) XML schema
Locates
/Catalog/Item
Uniquely identifies nodes
elements 4 XPath
1 Used by
http://www.hr.com/
s a
catalog XML language
Applies Transformed
h a
to
s ฺ r s)
6 m
eฺ
Processed
3 XML namespace by e
@ GuOutputi d
v i c
t o o ent document
rstylesheet
XSL/XSLT
7 a js Stud
n a ฺm this
i
nt u(DOM
XMLeprocessor s e and SAX API)
XQuery l
va e to
c (
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t XML s
l e n
The following
t r a nstandards are covered in this course:
V1.a Then o n- language specification defines the rules that govern XML document
XML
structure, and the XML processors must read them.
2. A document type definition (DTD) provides the definition and relationships of
elements contained in an XML document. A DTD validates an XML document.
3. XML namespaces provide a mechanism to distinguish elements with the same name
but different definitions used in the same XML document.
4. The XML Path Language (XPath) provides the syntax for searching an XML document.
XPath expressions are used in an XSL style sheet to match specific nodes.
5. An XML schema provides a way to describe the XML document structure using data
type definitions, and uses namespace support.
6. The Extensible Stylesheet Language (XSL) is implemented by XSL Transformations
(XSLT) to specify how to transform an XML document into another document. XSLT
uses an XML vocabulary for transforming or formatting XML documents.
7. XQuery is an XML query language that provides a data model for XML documents and
a set of operators to use with the data model.
The next two pages briefly discuss XML Programming Models or APIs, such as the
Document Object Model (DOM) and Simple API for XML (SAX), which are used by XML
processors for processing XML documents.
XML Fundamentals 2 - 6
Document Object Model
XML Fundamentals 2 - 7
Oracle XML Parser supports most of DOM Level 2 and some Level 3 features.
Note: Using the DOM API to process large documents can consume more memory resources
compared to working on the documents by using the stream-based processing approach
provided by SAX.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 2 - 8
Simple API for XML
XML Fundamentals 2 - 9
Oracle XML Support
• Development tools
XML Fundamentals 2 - 10
XML in Oracle JDeveloper
• Is used for:
– Building Java, XML, and PL/SQL applications
– Debugging the applications
– Deploying Internet-enabled applications
• Includes Oracle Application Development Framework
(ADF) s a
h a
• Enables seamless Java, XML, XML
s ฺrs) ฺ
and SQL development of: em e
c@ t idJava
– Java for distributed code v i Gu
– XML for portable data t o ro den
s
aj s Stu
ฺ m
– SQL for querying na nthi
ti se SQL
e
al to u
( v
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
Oraclen t ina anissfaepowerful development tool for building, debugging, and deploying
JDeveloper
V aleweb
J2EE,
o n - tr and Internet applications. Oracle JDeveloper:
services,
• Isnan integrated development environment (IDE) that provides end-to-end support for
developing, debugging, and deploying J2EE applications and web services
• Provides a flexible environment for creating, editing, and debugging XML applications
and supporting the latest XML and Internet standards
• Provides developers with a set of well-integrated tools to productively develop and
deploy applications by using Java, XML, PL/SQL, and SQL at low cost
• Maximizes developer productivity by supporting the complete development life cycle
from modeling, coding, and debugging to testing and profiling
• Provides access to source code control to manage the entire development process and
enable distributed development teams to work cooperatively
• Includes the Oracle Application Development Framework (ADF), which was previously
known as Business Components for Java. Oracle ADF is a 100% Java, XML-powered
application component framework that greatly simplifies the development, deployment,
and customization of Internet-enabled applications
This course uses the XML support that is available in JDeveloper 11.1.1.2.0.
XML Fundamentals 2 - 11
Building XML Applications
with Oracle Technology
• An XML application is an application process that operates
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 2 - 12
XML in Service-Oriented Architecture
XML Fundamentals 2 - 13
Importance of XML in Web Services
s a
Registration and Discovery:
Universal Description, Discovery and Integration (UDDI) ) h a
r s
sฺ eฺ
Service Description:
Web Services Description Language (WSDL)
m
e uid
c @
Messaging:
r o vi nt G
SOAP
a jsto Stude
aฺm thlanguage.
Representation:
n
XML is the universaltirepresentation
is
l en o us e
a
(v se t
i c
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n
Many businesses n s are becoming e-businesses. The greatest barrier to this
today
e r a
al on-t is application-to-application communication. An enterprise system usually has
transformation
V n
multiple applications, each running on different hardware and sometimes implemented in
different languages. These applications often need to exchange data with one another, and
developers must write additional code to make this integration possible. A web service is a
technology (based on a set of standards) that provides a solution for application-to-application
communication and enterprise application integration.
Using web services, clients and servers can communicate over standard Internet protocols
regardless of the platform or programming language. Developers can write their business
functionality in any language and on any platform.
To be exposed and accessed as web services, the applications must be developed according
to the standards used by web services. Web service standards make use of the core concept
of XML-based representation to carry out information exchange between service providers
and requestors.
Simple Object Access Protocol (SOAP) is a lightweight, XML-based protocol for exchanging
data in a distributed environment. The definition of SOAP is in XML and places no restriction
on the format.
XML Fundamentals 2 - 14
Web Services Description Language (WSDL) uses the XML format to describe web services.
It describes what functionality a web service offers, how it communicates, and where it is
accessible. Because WSDL is in standard XML format, the services developed can easily be
made available to thousands of users. Users must invoke the correct services with the
appropriate parameters. WSDL defines an XML grammar to specify the location of the service
and to describe the operations of a service.
UDDI is an XML-based registry that enables businesses to list themselves and their services
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
on the Internet.
A web service may be defined by a WSDL interface, and the WSDL interface may import XML
Schema files. The XML schema definitions may be used to describe the message exchanges
by operations defined by the WSDL for the web service.
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 2 - 15
Creating an Application and Project in JDeveloper
1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Double-click or
click Next.
s a
3
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i n a
t with s documents in JDeveloper, you need to create or open an application
e n
When working
r a nXML
V ala project.
with
o n -tAn application contains one or more projects. A project contains one or more
projectn
files.
To create a new application with a project, perform the following steps:
1. Select File > New or click the New Application icon in the Applications pane. The
New Gallery window is displayed.
2. Select Applications from the General category, and then double-click Java Desktop
Application in the Items section. The Create Java Application – Step 1 of 4 window
is displayed.
3. In the Create Java Application – Step 1 of 4 window, perform the following steps:
a. Enter an Application Name (this becomes the file name).
b. Enter, or browse to, the Directory name for the application file.
c. Click Next. The Create Java Application – Step 2 of 4 window is displayed.
XML Fundamentals 2 - 16
Creating an Application and Project in JDeveloper
4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a a
a Mforsthe
4. Entertianname n ferproject. This is the file name that will be used for the project within
e n r a
l file nsystem.
Vathe o -t The .jpr extension is assumed, but not displayed. In this course, we are
n JDeveloper 12c; therefore, there is only one available project feature available,
using
Java. In the JDeveloper Studio edition, there are other types of project features available.
Accept the default selection, and then click Next. The Create Java Application – Step 3
of 4 window is displayed.
5. Your new project starts with a default package, Java source path, and an output directory.
Click Next. The Create Java Application – Step 4 of 4 window is displayed. Accept the
default selection, and then click Next.
Note
To open an existing application, select File > Open, and then locate and double-click a file
name with a .jws extension.
XML Fundamentals 2 - 17
Creating an Application and Project in JDeveloper
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
7
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a ra and then click Finish.
M feselection,
t a
6. Acceptinthe default
s
lennewly
7. aThe - t r an application and project are displayed in the Applications and Projects
created
non
V pane.
XML Fundamentals 2 - 18
Creating an XML Document in JDeveloper
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Double-click
1
s a
h a
s ฺrs) ฺ
@ em uide
o v ic 3 t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n
To create i n
t a newaXML
n s document in a project, perform the following steps:
l e r
-t the project name in the Applications Navigator, and then select New.
V1.a Right-click
o n
n New Gallery window is displayed.
The
2. Select the XML node from the General category, and then double-click XML Document
in the Items section. The Create XML File window is displayed.
3. In the Create XML File window, enter the File Name. Then enter, or browse to, a
Directory name to store the file, and click OK.
XML Fundamentals 2 - 19
Creating an XML Document in JDeveloper
5
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s
t XMLandocument
4. The
e n new
linitial content
t r is created as a child entry of the project in the Navigator. The
a -
V non is displayed in the JDeveloper XML Code Editor pane. The XML document
also contains the following line:
<?xml version='1.0' encoding='UTF-8'>
5. Click Save to save the new project.
UTF stands for Universal Character Set Transformation Format. XML documents can contain
international characters. To avoid errors, you should specify the encoding used, or save your
XML files as UTF-8. Character encoding (or character set) defines a unique binary code for
each different character used in a document. Unicode is an industry standard for character
encoding of text documents. It defines every possible international character by a name and a
number. The standard character encoding on the web is UTF-8. This line of text may be
different if JDeveloper is running on a different platform such as MS-Windows. In MS-
Windows, the encoding used is Windows-1252. In this course, you are using a Linux
environment.
XML Fundamentals 2 - 20
Adding an XML Document to a Project
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
2 a
h a s
r s )
m sฺ eฺ
@ e uid
c
vi nt G
r
to tudeo
a j s
3
a ฺ m his S
e n tin se t
( v al to u
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
t a sfe
inXML
To addnan
l e t r a n
document to a project, perform the following steps:
n o n- the project name in the Applications Navigator, and then select Project
V1.a Right-click
Properties from the context menu. The Project Properties window is displayed.
2. In the Project Properties window:
a. Click Add next to Java Source Paths to add the directory that contains the XML
document. The Choose Directory window is displayed. Navigate to the directory,
and then click Select.
b. Click Add next to the Included tab to add the XML document. The Add Include
Filters window is displayed.
c. Select the XML document that you want to add to the project, and then click OK.
3. The newly added XML document is added as a node to the project.
XML Fundamentals 2 - 21
Viewing the Contents of an XML Document
s a
2. Use a text editor. ) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t can display s the XML document in your web browser. In the course environment,
1. You
l e n r a n
Va Mozilla
o n -tFirefox is the default browser.
na. Open the Mozilla Firefox application as shown in the first example in the slide.
b. Navigate to the directory where the XML document resides.
c. Double-click the XML document file name. The browser displays the XML
document tree, which can be expanded or collapsed. Initially, the document tree is
expanded as shown in the slide example. To collapse the tree or a branch, click
the “+” sign at the beginning of the line. To expand the tree or a branch, click the
“-” sign at the beginning of the line.
2. You can also display the XML document using a text editor. In this course, you can
display the XML document using the gedit text editor as follows:
a. Navigate to the folder that contains the XML document as shown in the second
example in the slide.
b. Right-click the file name, and then select “Open with gedit” from the shortcut menu.
The XML document is displayed in the text editor.
XML Fundamentals 2 - 22
Viewing an XML Document in JDeveloper
s a
2. Use JDeveloper’s Code Editor pane. ) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s command line to be initiated from the JDeveloper Tools menu.
tadd youranbrowser
You can
e n r
V al is done
This
o n -byt creating an External Tools command by using the Tools > External Tools
menu. n
In this course, JDeveloper is already set up to include Mozilla Firefox in the Tools menu, as
seen in the first screenshot in the slide. To launch the browser from the Tools menu:
1. Select the XML document in the Applications Navigator.
2. Select Tools > Firefox.
You can also right-click the XML file in the JDeveloper Navigator and XML Editor, and then
select Firefox from the shortcut menu.
Note: To learn how to create and access an external tool from within JDeveloper, see
Appendix C (“Managing External Tools in JDeveloper”).
You can also display the contents of an XML document using the Code Editor pane as
follows:
1. Locate the file in the Applications pane.
2. Double-click the file. The content of the file is displayed in the Code Editor window, as
shown in the second example in the slide.
XML Fundamentals 2 - 23
Quiz
XML Fundamentals 2 - 24
Practice 2-1: Overview
XML Fundamentals 2 - 25
Lesson Agenda
XML Fundamentals 2 - 26
Extensible Markup Language
XML Fundamentals 2 - 27
XML Documents Form a Tree Structure
<root>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<child>
<subchild>.....</subchild>
</child>
</root>
<?xml version="1.0"?>
<employees>
<employee>
<employee_id>120</employee_id>
s a
<last_name>Weiss</last_name>
) h a
<salary>8000</salary> r s
sฺ eฺ
</employee> m
e uid
<employee>
c @
<employee_id>121</employee_id>
r o vi nt G
<last_name>Fripp</last_name>
a jsto Stude
<salary>8200</salary>
n a ฺm this
</employee>
i
nt use
</employee>
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s contain a root element. This element is “the parent” of all other
e n
XML documents
r a n
must
al oThe
elements.
V n -t elements in an XML document form a document tree. The tree starts at the
n then branches to the lowest level of the tree. All elements can have subelements
root and
(child elements).
The slide example displays employee information, which is self-descriptive. It contains
employee information wrapped in custom tags. Unlike HTML, XML does not have predefined
tags.
XML Fundamentals 2 - 28
XML Document Structure
<?xml version="1.0"?>
<!–- this is a comment --> Prologue
<employees>
... Root element
s a
</employees> h a
s ฺrs) ฺ
@ em uide
<?gifPlayer size="100,300"?> Epilogue ic G
r o v n t
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s the following parts:
An XML n
e document
l prologue, r a n
contains
V•a The o n -t which may contain the following information:
n- XML declaration (optional in XML 1.0; mandatory in XML 1.1)
- Document type definition (DTD), which is required only to validate the document structure
- Processing instructions and comments, which are optional
• The root element, which is also called the “document element” and contains all other elements
• An epilogue, which contains processing instructions and comments
Processing instructions give commands or information to an application that processes the XML data.
Processing instructions have the <?target instructions?> format, where target is the name of
the application that is expected to do the processing, and instructions consists of a string of
characters that embodies the information or commands for the application to process.
Processing instructions can be written in the prologue, epilogue, or root element of an XML document.
XML Fundamentals 2 - 29
Simple XML Document: Example
Prologue
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 2 - 30
XML Declaration
An XML declaration:
• Looks like a processing instruction with the xml name
• Is optional in XML 1.0 but mandatory in XML 1.1
• Must contain one of the following version attributes:
– 1.0
– 1.1 s a
) h a
• Can include the following optional attributes: r s
sฺ eฺ
– Encoding m
e uid
c @
– standalone r o vi nt G
a jsto Stude
<?xml version="1.0" encoding="UTF-8"?>
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t recommended s
l e n
It is generally
t r a n that you start an XML document with an XML declaration. If it is
a oit must
present, - be the first line in the document. Although the XML declaration resembles a
V n n
processing instruction, it is really a simple declaration. In the XML 1.0 specifications, an XML
document does not require the XML declaration. However, in the XML 1.1 specifications, the
XML declaration is mandatory.
Note: Not all tools and XML Parsers support the XML 1.1 syntax.
The only attribute that is mandatory in the declaration is the version attribute. Additional
attributes that can be added to the XML declaration include the following:
• encoding attribute, which is optional. By default, XML documents are encoded in the
UTF-8 format of the Unicode character set. The encoding for Windows is WINDOWS-
1252. This is useful for applications (such as those written in Java) that can handle
other encoding formats.
• standalone attribute, which is optional and may be set to the yes or no value. If this
attribute is omitted, the value is assumed to be no. Set the standalone value to:
- No, which indicates that the document may depend on an external DTD (covered
later in this course) to determine the document structure
- Yes, which indicates that the document exists entirely on its own, without
depending on other files such as a DTD
XML Fundamentals 2 - 31
Components of an XML Document
XML Fundamentals 2 - 33
Empty Elements
Empty elements:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
• Contain no data
• May appear as a single tag
<initials></employee>
s a
) h a
r s
sฺ eฺ
<initials/> m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t have sno content between the start and end tags. In this case, a shortened form
l e n
Empty elements
r a n
can a
V be used o -t the start tag name is followed by a slash (for example, <initials/>).
where
n
n
XML Fundamentals 2 - 34
Markup Rules for Elements
XML Fundamentals 2 - 36
Naming Convention Rules
for Elements and Attributes
Element and attribute names:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 2 - 37
Using Elements Versus Attributes
<?xml version="1.0"?>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
<?xml version="1.0"?>
s ฺrs) ฺand
id, last_name,
<employees> em asuattributes
salary
@ ide
<employee id="100" last_name="King" ic G2
r o v n t
jsto Stude
salary="24000">
</employee>
ฺm thisa
</employees>
i n a
l e nt use
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t youasee stwo examples:
e n
In the slide,
l Example r n
V1.a Inemployee
o n -t 1, id, last_name, and salary are defined as elements within the
n element, whose parent is the employees element.
2. In Example 2, id, last_name, and salary are attributes of the employee element,
whose root element is employees.
Elements and attributes accomplish approximately the same thing. That is, they describe the
data. The examples shown are both valid and communicate the same basic information about
an employee.
Note: In general, elements are more robust and flexible to use than attributes.
The choice to use elements or attributes is often a matter of preference, but it takes some
time and experience to determine the best style to use for different contexts. The easiest and
most consistent approach is to use elements for data that the user of the document wants to
see, and attributes for metadata representing additional information about the data that the
document may require. The following are additional points to consider:
• Elements are more easily added as your requirements expand.
• Elements may be ordered, but attributes are returned unordered from the document.
• Elements can be structured and may contain other elements.
• Attributes are atomic; that is, they cannot be nested or have attributes of their own.
XML Fundamentals 2 - 38
XML Entity
XML Fundamentals 2 - 40
XML Comments
XML comments:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 2 - 41
Well-Formed XML Documents
XML Fundamentals 2 - 42
Comparing XML and HTML
• XML
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 2 - 43
Comparing XML and HTML: Example
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
HTML document
s a
) h a
XML document r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
texampleaninsthe slide displays HTML code with predefined tags. HTML uses markup
e n
The first
tr web pages. The purpose of a web browser, such as Internet Explorer or
alto describe
tags
V n -
Firefox,nisoto read HTML documents and display them as web pages. The browser does not
display the HTML tags, but uses the tags to interpret the content of the page. Examples of
some of the predefined tags that are used in the first slide examples are <HEAD>, <TITLE>,
<P>, and <B>.
The second slide example displays an XML document that contains user-defined markup tags
such as <DOC>, <TITLE>, <SAYING>, and <FIGURE>.
XML Fundamentals 2 - 44
XML Development
XML Fundamentals 2 - 45
Creating an XML Document in JDeveloper
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
1 Double-click.
s a
h a
s ฺrs) ฺ
@ em uide
o v ic 3 t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n
To create i n
t a newaXML
n s document in a project, perform the following steps:
l e r
-t the project name in the Applications Navigator, and then select New.
V1.a Right-click
o n
n New Gallery window is displayed.
The
2. Select the XML node from the General category, and then double-click XML Document
in the Items section. The Create XML File window is displayed.
3. In the Create XML File window:
a. Enter the File Name.
b. Enter, or browse to, a Directory name to store the file.
c. Click OK.
XML Fundamentals 2 - 46
Editing XML Documents in Oracle JDeveloper
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
1 ) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t showsathesfollowing actions when you right-click an XML document in JDeveloper’s
n
The slide
e r n
al on-t
Navigator:
V
1. Then Open option causes the elements and data to be displayed hierarchically in the
Structure window. In the Structure window, perform the following steps:
- Click an element or attribute to navigate to it in the XML Editor.
- Double-click an element, attribute, or error to edit it in the XML Editor.
2. The Open option also causes the file’s contents to be displayed in the XML
(source/code) Editor window.
JDeveloper checks the XML syntax as you type in XML files. Errors appear with red squiggly
lines in the Code Editor and also in the Structure pane. You see a red square box near the
scroll bar if there are errors in the document. Alternatively, if there are no errors in the
document, you see a green square box. Note that when you place your cursor over the big
red square box, a pop-up with the message “Hold Ctrl to view” is displayed. Press and hold
the Ctrl key with the cursor over the big red box. You see a suggestion that can help you fix
the error in code.
Select File > Save to save your changes to the document.
Note: Select View > Structure to display the Structure window if it is not already open.
XML Fundamentals 2 - 47
Setting Preferences in Oracle JDeveloper
1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
You can n i n s in JDeveloper to assist in writing XML documents.
tset preferences
n
l e r a
-t > Preferences. The Preferences window opens.
V1.a Select
n o n Tools
2. Select XML and JSP/HTML under the Code Editor node:
- Select the Required Attribute Insertion check box for the editor to automatically
insert the required attributes when entering a space after the start tag name.
- Select the End Tag Completion check box to enable the end tag to be
automatically inserted after completing the start tag.
XML Fundamentals 2 - 48
Quiz
<?xml version="1.0"?>
<Question>Is this legal?</Question> 1
<Answer>No</Answer>
XML Fundamentals 2 - 49
Summary
XML Fundamentals 2 - 50
Practice 2-2: Overview
XML Fundamentals 2 - 51
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Objectives
XML Fundamentals 3 - 2
Lesson Agenda
– DTD rules
– Content of a DTD
• Declarations for:
– Elements
– Attributes
– Entities s a
h a
• Validating XML against a DTD
s ฺrs) ฺ
• XML catalogs
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 3 - 3
What Is a Document Type Definition?
A DTD:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 3 - 4
Reasons to Validate an XML Document
XML Fundamentals 3 - 5
General DTD Rules
A DTD:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 3 - 6
Syntax for DTD Declarations
• Elements:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
• Attributes:
<!ATTLIST element_name attribute_name attribute_type
default_value>
• Entities: s a
) h a
<!ENTITY entity_name "replacement text"> r s
sฺ eฺ
m
e uid
c @
r o vi nt G
• Notations:
a jsto Stude
<!NOTATION notation_name SYSTEM "text">
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s
A DTDn consists ofndeclarations
a for the markup and data used in an XML document. The slide
l e t r
- syntax for declaring markup components:
a theongeneric
shows
V n
• Elements, which declare tag names and their content model. The content model for an
element includes other nested markup (elements) and/or character data.
• Attributes, which declare the attribute names for the containing element, the type of
attribute (not a data type), and optional default values
• Entities, which provide a mechanism for replacement text
• Notations, which are used in DTD attribute types to provide a way for identifying how
parsed or unparsed data is encoded, typically used by applications that can process the
data
Note: Notations are not frequently used in DTDs.
The next few pages of this lesson show examples of how to use each of these declarations,
and finally how to use DTD to validate the structure and content of an XML document.
XML Fundamentals 3 - 7
Example of a Simple DTD Declaration and
an XML Document That Conforms to the DTD
• Example of a simple DTD with element declarations:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 3 - 8
Example of an XML Document
That Does Not Conform to the DTD
Using the same DTD, the following XML document is invalid
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 3 - 9
Reference the DTD in the XML Document
XML Fundamentals 3 - 10
Lesson Agenda
– DTD rules
– Contents of a DTD
• Declarations for:
– Elements
– Attributes
– Entities s a
h a
• Validating XML against a DTD
s ฺrs) ฺ
• XML catalogs
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 3 - 11
Empty Element Declaration
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<job/>
<job><job/>
s a
<job id="ST_CLERK"/>
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s building blocks of DTDs. An element declaration contains the
t are theabasic
n
Elements
e r n
al okeyword,
ELEMENT
V n -t followed by the element name and a content model. The content model
definesnwhat can be contained in the element. The four types of content models are:
1. Empty: This cannot contain subelements or text. However, an empty element may hold
attributes. Examples of an empty element include the following:
<job/>
<job></job>
<job id="ST_CLERK"/>
XML Fundamentals 3 - 12
Child Elements Declaration
XML Fundamentals 3 - 13
Mixed Elements Declarations
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 3 - 14
Any Element Declarations
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s model means that anything can be contained within the element; the
t This acontent
e n
4. Any:
r n
l modelnis-tvery loose. The ANY content model allows any element declared in the DTD to
Va be o in any order, using any number of occurrences. That is, the DTD does not
nused,
validate the element content.
Note: You should avoid using ANY because it entirely defeats the purpose of using a
DTD for validating the structure and content of an XML document.
XML Fundamentals 3 - 15
Specifying the Cardinality of Elements
Cardinality symbols:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Symbol Description a
No symbol (default) Mandatory (one and only one) h a s
r s )
? (question mark) Optional (zero or one)
m sฺ eฺ
@ e uid
* (asterisk) Zero or more (optional) c
vi nt G
r o
+ (plus sign) One or more (mandatory)
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t model s
l e n
The content
t r a nindicates how to group subelements by using parentheses, and how many
a on-of each element are permitted. Cardinality (the number of permitted occurrences
occurrences
V
of eachnelement) is expressed using the following symbols:
• Question mark (?): Indicates an optional or single-valued subelement (zero to one)
• Asterisk (*): Indicates an optional or multivalued subelement (zero to many)
• Plus sign (+): Indicates a mandatory or many-valued subelement (one to many)
The symbols can appear in the content model specification as a suffix with the individual
elements, a group, and the entire content model. By default, the absence of a symbol means
that the element, group, or content model must appear at least once; that is, it is mandatory.
XML Fundamentals 3 - 16
Specifying the Cardinality of Elements: Examples
s a
<!–- An <employee> element must have one <last_name> and <salary> -->
h a
ฺrs) ฺ
<!-- elements, and an optional <commission_pct> element:
s
<!ELEMENT employee (last_name,salary,commission_pct?)>
@ em uide
o v ic t G
t o d n many -->
rand optionally
e
<!–- The <jobs> element must have one president, s
aj s Stu
<!-- managers or clerks: -->
a ฺ m h i
t i n e t
<!ELEMENT jobs (president , (manager
a l en o| uclerk)*)> s
v
c ( nse t
v i
t o ro © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
s
aj rable
M
The slide
n t na nsshow
iexamples fe how to specify the cardinality of elements using the cardinality
ale on-tra
symbols:
V 1. Ann <employees> element can contain zero or many <employee> elements:
<!ELEMENT employees (employee*)>
2. A <department> element must contain at least one or many <employee> elements:
<!ELEMENT department (employee+)>
3. An <employee> element must have one <last_name> and <salary> element, and
an optional <commission_pct> element:
<!ELEMENT employee (last_name,salary,commission_pct?)>
4. The <jobs> element must have one president, and (optionally) many managers or
clerks:
<!ELEMENT jobs (president , (manager | clerk)*)>
XML Fundamentals 3 - 17
Attribute Declarations: Syntax and Requirements
XML Fundamentals 3 - 18
Attribute Declarations: Syntax and Requirements
s a
h a
<employee manager_id="100"> s ฺrs) ฺ
<employee_id>101</employee_id>
@ em uide
<last_name>Kochhar</last_name>
o v ic t G
</employee>
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
Example
n i n
tof XMLabynsusing the manager_id attribute declaration:
e tr
al on-manager_id="100">
V
<employee
n
<employee_id>101</employee_id>
<last_name>Kochhar</last_name>
</employee>
XML Fundamentals 3 - 19
CDATA and Enumerated Attribute Types
<employee manager_id="102">
<employee_id>104</employee_id>
<last_name>Ernst</last_name>
</employee>
XML Fundamentals 3 - 20
NOTATION Declaration and Attribute Type
XML Fundamentals 3 - 21
Specifying Default Attribute Values
XML Fundamentals 3 - 22
Entities in XML
– Built-in entities
– Character entities
• Entity types that can be declared in the DTD:
– General entities
– Parameter entities
• Entity references for: s a
a
– Built-in, character, and general entities can be made rins)anh
XML document or the DTD by using: m sฺ eฺ
@ e uid
&entity-name; c
vi nt G
r
to DTD o e using:
– Parameter entities can be made in
a jsthe t u dby
a ฺ m his S
tin se t
%entity-name;
e n
( v al to u
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
n
Accordingt intoatheaWorld
n sfeWide Web Consortium (W3C) standard, predefined entities in XML
ale on-tr
include:
V n entities representing these special characters:
• Built-in
- The less-than sign (<) represented by <
- The greater-than sign (>) represented by >
- The ampersand (&) represented by &
- The single quotation mark or apostrophe (') represented by '
- The double quotation mark (") represented by "
• Character entities representing any Unicode character specified in the XML
recommendation, which is based on Unicode 3.0. Character entities are formed using
an ampersand (&) followed by a hash (#), then a Unicode character number, and finally
a terminating semicolon (;). For example, © denotes the copyright symbol (©). The
character number can be a decimal or a hexadecimal Unicode value. Hexadecimal
values are prefixed by an x. For example, © represents the copyright symbol (©).
An entity reference to a parameter entity is done in a DTD. However, references to built-in,
character, and general entities can be done in the XML document and a DTD, as in this
example:
<Company>"Oracle Corporation"</Company> instead of
<Company>"Oracle Corporation"</Company>
XML Fundamentals 3 - 23
General Entity Declarations
XML Fundamentals 3 - 24
Well-Formed Parsed Entities
The replacement text of parsed internal or external entities must consist of well-formed XML
content. These entities can be used as replacement text inside XML elements or attributes,
and other DTD declarations. For example, in the slide, the entity declarations for company,
Emperor, and president are all (well-formed) parsed internal entities.
However, the following examples are not well-formed and therefore, invalid:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 3 - 25
Parameter Entities
XML Fundamentals 3 - 26
Complete DTD: Example
XML Fundamentals 3 - 27
Lesson Agenda
– DTD rules
– Contents of a DTD
• Declarations for:
– Elements
– Attributes
– Entities s a
h a
• Validating XML against a DTD
s ฺrs) ฺ
• XML catalogs
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 3 - 28
Validating XML Against a DTD
XML Fundamentals 3 - 29
Using XML Catalogs
Use catalogs to make your XML setup more portable and more
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 3 - 31
Referring to External DTDs
You can refer to an external DTD by using either system identifiers or public identifiers, which
are briefly mentioned earlier in this lesson.
System Identifiers
A system identifier enables you to specify the location of an external file containing DTD
declarations. It consists of two parts: The keyword SYSTEM and a URI reference pointing to
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
the document’s location. A URI can be a file on your local hard drive, a file on your network, or
a file available on the internet. The syntax has already been shown in this lesson.
Public Identifiers
Similar to system identifiers, the public identifier begins with the keyword PUBLIC followed by
a specialized identifier. However, instead of a reference to a file, public identifiers are used to
identify an entry in a catalog. Following the identifier string, you can include an optional
system identifier too. This enables the processor to find a copy of the document if it cannot
resolve the public identifier. When you include the optional system identifier, the SYSTEM a
keyword is not required. A valid document type declaration that uses a public identifier might
h a s
resemble the following: r s )
m sฺ eฺ
<? xml version = "1.0" ?>
@ e uid
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN"
v i c G
"concept.dtd">
t
. . . r o
to tude n
The public identifier "-//OASIS//DTD DITA Concept//EN" a j s S to be resolved to a local
a ฺ m his needs
DTD by the catalog file. Even the system identifier
n t in se t " concept.dtd " can be resolved to another
file by the catalog, maybe to the same lfile
a e name o ubut in a specific path.
v
( catalog t
XML editors and other tools use
o v i c the
e n seproject
to find the DTDs and XML schemas. Some use
the “resolver” Java classofrom
t r the
l i c
Apache to resolve public and system IDs using
catalogs. The resolver s
aIf jthere le to resolve the public identifier in the DOCTYPE declaration by
first tries
b
using the catalog.
a M f e r a
is no match, it tries to resolve the system identifier. If there is no
match,n i n
it tuses then s
system identifier as the actual file location.
l e t r a
Va non-
XML Fundamentals 3 - 32
Quiz
XML Fundamentals 3 - 33
Summary
XML Fundamentals 3 - 34
Practice 3: Overview
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n
In this practice, youn sare provided with a DTD for employees to test your understanding of
e
al an oexternal
using r a
-t DTD to validate an XML document. Tasks include:
V n n
• Associating the external DTD with an existing XML document
• Validating the XML document
• Correcting validation errors
• Extending the DTD by using internal DTD declarations
Note: The practice uses the oraxml command-line utility to validate the XML document.
Although Internet Explorer does not implement strict DTD validation, it is used so that you can
view the resulting XML document tree (especially to see the resulting document after the
entities are replaced).
XML Fundamentals 3 - 35
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Objectives
XML Fundamentals 4 - 2
What Is an XML Namespace?
An XML namespace:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<departments> s a
<employee>
) h a
<name> r s
sฺ eฺ
<employee_id>
m
e uid
@
<department_id>
c
<name>
r o vi nt G
<location_id>
<salary>
a jsto Stude
n a ฺm this
i
nt uhttp://hr.com/departments
s e
http://hr.com/employees l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
tnamespace: s
An XML
l e n r a n
n-t by an internationalized resource identifier (IRI), which is a case-sensitive
V•a Isnidentified
o
string of characters identifying a resource
• Provides a universally unique name for a collection of XML names made of element and
attribute names
The IRI is a string of characters that can be formatted as:
• A uniform resource indicator (URI) or uniform resource locator (URL), such as the web
address http://hr.com/employees
Note: The URL, or web address, represents a unique string and is not checked to be a
valid or existing web address.
• A uniform resource name (URN) such as urn:hr:departments. A URN starts with
the letters urn, followed by a colon (:), a namespace identifier (NID) (hr), a colon (:),
and a namespace-specific string (NSS) (departments).
The example in the slide shows two collections of XML element and attribute names, each
identified by a unique XML namespaces IRI. If the XML namespace is not used, the <name>
element for an employee would be indistinguishable from the <name> element of the
department. Applying the XML namespace qualifies each <name> element by making them
unambiguous, especially if the documents are merged.
XML Fundamentals 4 - 3
Benefits of Using XML Namespaces
XML Fundamentals 4 - 4
Declaring XML Namespaces
XML Fundamentals 4 - 5
XML Namespace Prefixes
A namespace prefix:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 4 - 6
XML Namespace Declarations: Example
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<?xml version="1.0"?>
<department xmlns="urn:hr:department-ns" Default namespace
xmlns:emp="urn:hr:employee-ns">
XML Fundamentals 4 - 7
Scope of XML Namespace Declarations
<?xml version="1.0"?>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<root-level xmlns="urn:demo:default-ns"
xmlns:one="urn:hr:one-ns"
xmlns:two="urn:hr:two-ns">
<level-one id="1">A</level-one>
<one:level-one id="2">
<one:level-two>B</one:level-two>
<two:level-two>C</two:level-two>
</one:level-one>
s a
h a
<one:level-one xmlns:one="urn:one:override-ns">ฺrs)
e ms ideฺ
<level-two xmlns="">D</level-two>
v i c@ t Gu
<level-two>E</level-two>
t o ro den
<level-two xmlns:two="urn:two:override-ns">F
s
aj s Stu
</level-two>
a ฺ m hi
</one:level-one>
t i n e t
</root-level>
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n
The scope i n s or prefixed XML namespace declaration extends from the beginning of
t of a default
n
e r a
l tagnin-t which it appears to the end of the corresponding end tag, unless it is
theastart
V no
overridden in a child (descendant) element by an inner declaration.
Note: In the case of an empty element, the scope of the XML namespace is the element itself.
The default namespace declaration applies to all nonprefixed element names within its scope.
In the slide, the default namespace applies to:
• The <level-one id="1"> element
• The <level-two> element containing the texts E and F because the element
containing the text F does not use a prefix
The attribute value for an XML namespace declaration may be the empty string. An XML
namespace with an empty string has the effect of removing any association of the default
namespace or prefix with any XML namespace name: for example, the <level-two>
element containing the text D in the slide. In this case, additional declarations may be made to
declare the default namespace or prefix again.
Note: It is an error if an element uses a prefix without its XML namespace declaration in
scope.
XML Fundamentals 4 - 8
ShowXMLns Tool
1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t the s source code and class have been provided in your project for use in
l e n
In this course,
r a n
Java
theapractices.
V o n -tUsing these, you can examine the effects of applying XML namespaces to
elements n in an XML document. The Java class has been configured as an external tool in
JDeveloper.
The tool displays the effects of using XML namespace declarations in an XML document by
showing the expanded name as a pseudo attribute for each element in the XML document.
The printed results can be seen in the JDeveloper Message Log window.
Notes
• The ShowXMLns tool is written in Java by using the Document Object Model (DOM) API
that is available in the Oracle XML Parser (xmlparserv2.jar). The source code is
included in your course project.
• For additional information on how to set an external tool, click Help on any screen in the
External Tool wizard.
XML Fundamentals 4 - 9
Invoking the ShowXMLns Tool
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Right-click
1 the XML file. 3
2
Select
ShowXMLns.
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n
To invoke i n
t this tool:
n s
l e r a
-t an XML document in the Navigator (or in the XML Code Editor).
V1.a Right-click
n o n
2. Select ShowXMLns from the context menu.
3. The tool displays the effects of using XML namespace declarations in an XML document
by showing the expanded name as a pseudo-attribute for each element in the XML
document. The printed results can be seen in the JDeveloper ShowXMLns - Log
window.
To run the tool from the command line, execute the following command:
set CLASSPATH=D:\JDeveloper\lib\xmlparserv2.jar;D:\labs\classes
java ShowXmlNS filename.xml
XML Fundamentals 4 - 10
Quiz
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
i n
t b ans
Answer:na,
e -tr an XML namespace:
alcan odeclare
V
You
n n
• With the xmlns attribute in an element start tag:
- Assigned an IRI (URL, URI, or URN) string value
- Provided with an optional namespace prefix
• With a namespace prefix after xmlns: to form qualified element names
• Without a prefix to form a “default namespace”
XML Fundamentals 4 - 11
Summary
XML Fundamentals 4 - 12
Practice 4: Overview
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n
In this practice, youn stest your understanding of writing an XML document with XML
e
al on-t
namespaces. r a
V n
XML Fundamentals 4 - 13
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Objectives
XML Fundamentals 5 - 2
Lesson Agenda
• XML schema
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
– Benefits
– Example
– Referencing an XML schema in an XML document
• Components of an XML schema
• Declaring a <simpleType> component
• Declaring a <complexType> component s a
h a
• Declaring attributes
s ฺrs) ฺ
• Using the JDeveloper XML Schema Editor @em uide
o v ic t G
• Validating an XML document by using: o r den
s t
– Oracle JDeveloper
ฺ m aj s Stu
– The oraxml command-line t i n autility thi
l e n use
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s
l e n r a n
Va non-t
XML Fundamentals 5 - 3
What Is an XML Schema?
XML Fundamentals 5 - 4
W3C XML Schema Recommendation: Overview
XML Fundamentals 5 - 5
Benefits of XML Schemas
XML schemas:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 5 - 6
XML Schema Versus DTD
• XML schema:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 5 - 7
XML Schema Document: Example
XML Fundamentals 5 - 8
Validating an XML Document
with an XML Schema Document
In the XML instance document, use the XML namespace
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
http://www.w3.org/2001/XMLSchema-instance, and
reference the XML schema using either of the following:
• noNamespaceSchemaLocation attribute
• schemaLocation attribute
noNamespaceSchemaLocation="file.xsd"
XML XSD
s a
schemaLocation="namespace file.xsd"
) h a
validates r s
sฺ eฺ
m
e uid
c @
<?xml version="1.0"?>
r o vi nt G
sto Stude
<departments xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
a j
n a ฺm this
xsi:noNamespaceSchemaLocation="departments.xsd">
Finance i
nt use
</departments>
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t an XML sinstance document using an XML schema, the XML instance document
e n
To validate
r a n
al othen-http://www.w3.org/2001/XMLSchema-instance
declares
V t XML namespace in its
n
root element to enable either of the following attributes to be used:
• The noNamespaceSchemaLocation attribute, whose value is a file name or URL
string identifying the location of the XML schema document
• The schemaLocation attribute, whose value is a namespace/file-location pair that
identifies the location of an XML schema using a specific XML namespace string, a
space, and a file location (file name or URL) of the XML schema document
These attributes are a hint to the XML Parser to validate the XML document using the XML
schema document identified by their value.
Note: The http://www.w3.org/2001/XMLSchema-instance namespace must be given
a namespace prefix such as xsi. The prefix allows the schemaLocation or the
noNamespaceSchemaLocation attribute to be recognized by the XML Parser.
The code example uses the noNamespaceSchemaLocation attribute, which indicates that
the XML document does not need to declare any XML namespace for its elements. For
example, the departments element is not required to be qualified by an XML namespace.
However, it is recommended that you use the schemaLocation attribute.
XML Fundamentals 5 - 9
Referencing an XML Schema
with the schemaLocation Attribute
• The XML schema defines the targetNamespace value.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 5 - 10
Quiz
XML Fundamentals 5 - 11
Lesson Agenda
• XML schema
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
– Benefits
– Example
– Referencing an XML schema in an XML document
• Components of an XML schema
• Declaring a <simpleType> component
• Declaring a <complexType> component s a
h a
• Declaring attributes
s ฺrs) ฺ
• Using the JDeveloper XML Schema Editor @em uide
o v ic t G
• Validating an XML document by using: o r den
s t
– Oracle JDeveloper
ฺ m aj s Stu
– The oraxml command-line t i n autility thi
l e n use
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s
l e n r a n
Va non-t
XML Fundamentals 5 - 12
Components of an XML Schema
<schema>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<element>
<restriction>
<attribute>
<simpleType> <list>
<complexType> <union>
<group> <sequence> s a
<group>
) h a
<choice> r s
sฺ eฺ
m
e uid
c @
r o vi nt G<all>
a jsto Stude
<attributeGroup>
<attributeGroup>
n a ฺm this
i
nt use
a l e o
<attribute>
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
The rootn i n
tof an XML n sschema document is the <schema> component, which can contain one
or a
e
more -t r
l declarations a for:
V n o n
• An <element> for XML elements, which can contain attributes or be structured as
<simpleType> or <complexType>
• An <attribute> representing a named attribute XML element
• A <simpleType>, which is an atomic built-in data type, or structured as a <list> or
<union> of other components such as <enumeration> components
• A <complexType>, which defines a complex structure that may be composed of other
components such as a <sequence>, <choice>, or <group>. For example, a
<complexType> is needed to declare a structure with child elements, and can define
type structures used for deriving other types or used as a user-defined type.
• A <group>, which names a structure composed of a <sequence>, <choice>, or an
<all> component
• An <attributeGroup> defining a list of attributes
Note: An XML schema contains more component types than are discussed in this course,
which covers <element>, <attribute>, <simpleType>, <complexType>, and
<sequence> components. The <attribute> item is duplicated for clarity in the slide.
XML Fundamentals 5 - 13
XML Schema Components: Example
<?xml version="1.0"?> 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n i n
t foraXML
The example n s schema contains the following components:
e
l XML r
-t declaration
V1.a The
n o n
2. The <schema> root element with the namespace declaration
xmlns:xsd="http://www.w3.org/2001/XMLSchema" to indicate that the
elements used in the XML schema document, which are specified in the W3C XML
Schema Language recommendation, define the structure of an XML instance document.
The namespace prefix, such as xsd, is optional but recommended. When the prefix is
declared, XML schema elements must use the prefix: for example, <xsd:schema>.
3. The <xsd:element> declaration within the <schema> element, which specifies a root
element name for the XML instance document: for example, region
4. The <xsd:complexType> definition within <xsd:element>, which is needed to
indicate that the <region> element contains a sequence of child elements named
<region_id> and <region_name>
5. <xsd:sequence>, which defines the order of occurrence of the two element
declarations that it contains, and forms the content model for the region element
6. The two <xsd:element> declarations for the child elements region_id and
region_name, based on the built-in int and string data type, respectively
XML Fundamentals 5 - 14
<schema> Declaration
XML Fundamentals 5 - 15
Declaring a Target Namespace
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace ="http://www.oracle.com/namespace"
xmlns:target="http://www.oracle.com/namespace">
or
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
targetNamespace="http://www.oracle.com/namespace"
xmlns:target="http://www.oracle.com/namespace">
Note: Declaring the targetNamespace value as a default namespace, or using a
namespace prefix as xmlns:target="http://www.oracle.com/namespace", in the
root element allows the XML schema document to reference vocabulary names declared in
the same XML schema document. This is necessary when you declare names that are
designed to be referenced by other declarations (and the names are then extended or used to
derive types for other components).
s a
Declaring Defaults
) h a
You can modify the default values of declarations appearing within the XML schema
s r s
ฺ to theฺ by
setting the attributeFormDefault and elementFormDefault attributes
qualified or unqualified (the default) value. These attributes @ emtheuqualification
control ide of
v i c t G
elements and attributes, with a namespace, in the instance document.
t o ro den
An element or attribute is qualified if it has an associated s tu as in the following
aj namespace,
S
example: a ฺ m his
t i n e t
l en o us
<emp:employee xmlns:emp="http://www.hr.com/employee">
a
<first name>Steven</first
<first_name>Steven</first_name>
i c (v name>
s e t
<last_name>King</last_name>
t o rov licen
</emp:employee> a js ble
a M fera
n
In this example:
i
nt <employee> n s
•aleThe - t r a element is qualified by a namespace
V• The n
no<first_name> and <last_name> elements are unqualified; that is, they have no
associated namespace
In the following example, all elements are implicitly qualified by the default namespace:
<employee xmlns="http://www.hr.com/employee">
<first_name>Steven</first_name>
<last_name>King</last_name>
</employee>
The last example can be explicitly expressed as shown here:
<emp:employee xmlns:emp="http://www.hr.com/employee">
<emp:first_name>Steven</emp:first_name>
<emp:last_name>King</emp:last_name>
</emp:employee>
XML Fundamentals 5 - 16
Global and Local Declarations
• Global declarations:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 5 - 17
Referencing Global Type Declarations
Within the Content Model
<?xml version="1.0" encoding="UTF-8"?> XSD
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:trg="http://www.hr.com/departments"
targetNamespace="http://www.hr.com/departments"
elementFormDefault="qualified">
<xsd:element name="department_id" type="xsd:int"/>
<xsd:element name="department_name" type="xsd:string"/>
<xsd:complexType name="departmentType">
<xsd:sequence>
<xsd:element ref="trg:department_id"/>
<xsd:element ref="trg:department_name"/>
</xsd:sequence>
s a
</xsd:complexType>
) h a
<xsd:element name="departments"> r s
sฺ eฺ
<xsd:complexType>
m
e uid
<xsd:sequence>
c @
<xsd:element name="department"
r o vi nt G
jsto Stude
type="trg:departmentType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType> ฺm thisa
i n a
nt use
</xsd:element>
</xsd:schema>
l e
c ( va e to
r o vi ens
j s o ©e2014,
tCopyright
l licOracle and/or its affiliates. All rights reserved.
M a rab
t a sfe
inexample
l e n
This partial
t r a n in the slide shows how to reference global type declarations within the
V a model.
content
n o n-
The XML schema reuses global type declarations in the ref and type attribute values, which
reference the names of the global component. It is recommended that an XML namespace
prefix, such as trg (with a namespace value set in the targetNamespace), should be used
to ensure that the global type name references are unique within the document.
In the slide example, the global type names are:
• department_id and department_name, which are referenced in the ref attributes
of the element declarations in the complexType called departmentType
• departmentType referenced in the type attribute of the department element that is
a child (local) type in the departments global element
XML Fundamentals 5 - 18
An XML Instance Document That Conforms
to the Preceding XML Schema: Example
<?xml version='1.0' encoding="UTF-8"?> XML
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<departments
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.hr.com/departments code_04_13n.xsd"
xmlns="http://www.hr.com/departments">
<department> s a
<department_id>10</department_id>
) h a
<department_name>Administration</department_name> r s
sฺ eฺ
</department> m
e uid
c @
</departments>
r o vi nt G
jsto Stude
...
ฺm thisa
i n a
l e nt use
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t example s a partial XML instance document that conforms to the XML schema
e n
The slide
l previous r a nshows
in a
V the
o n -t slide.
n schema elements are declared using the xsd prefix.
Note: All
XML Fundamentals 5 - 19
Declaring an Element
XML s a
<first_name>Steven</first_name> <!-- XML -->
) h a
<element r s
sฺ XSD
Fullname="name-of-element"
syntax m eฺ
e i d
type="global-type | built-in-type"
v i c@ t Gu
ref="global-element-name"
form="qualified | unqualified" t o ro den
minOccurs="non-negative number" s
aj s Stu
maxOccurs="non-negative number |ฺm
default="default-value" t i n a unbounded"
e t hi
fixed="fixed-value">
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
The XML n i n
t Schema n s
language uses the <element> component to declare an XML element.
l e t r a
V n o n- of <element> are:
a attributes
The
• The name attribute for specifying the tag name for the element
• The type attribute to specify the content type, or type of data contained in the element
• The ref attribute for referencing global type names in the schema document
• The form attribute that can be used to override the elementFormDefault attribute
value used in the <schema> element
• The minOccurs attribute that specifies the minimum number of times the element must
appear in the XML instance document. A value of zero indicates that the element is
optional.
• The maxOccurs attribute that indicates the maximum number of times the element can
appear in the XML instance document. A value of unbounded indicates that there is no
limit to the number of element occurrences.
• The default attribute that specifies a default value for the element if it does not appear
in the XML instance document. The default is not applied to an element with a value.
• The fixed attribute, which indicates that the content of the element must be equal to
this value
Note: The example specifies that the first_name element contains string data. The
string type is a built-in data type in the XML Schema language.
XML Fundamentals 5 - 20
Built-In XML Schema Data Types
as:
• string
• int
• decimal
• Many others (boolean, float, and so on)
Examples: s a
h a
<xsd:element name="employee_id" type="xsd:int"/> XSD
s ฺrs) ฺ
@ em uide
<employee_id>100</employee_id> XML vic t G
r o n
<xsd:element name="salary" type="xsd:decimal"/> a jsto Stude XSD
n a ฺm this
i
nt use XML
<salary>1000.50</salary>
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t types s can be specified in the type attribute:
Built-inndata
l e t r a n
that
on-
Va nSimpleType Example or Explanation
XML Fundamentals 5 - 21
SimpleType Example or Explanation
byte 123
nonNegativeinteger 0; 123456
unsignedLong 123456789012345
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
unsignedInt 1234567801
unsignedShort 12345
unsignedByte 123
positiveInteger 123456
date 2000-02-16 s a
h a
time 15:55:00.000
s ฺrs) ฺ
m ide
e(5:55
timeinstant 2000-12-31T05:55:00.000
i c @ G u
am,
v
ro den
Coordinated Universal Time)t
s t o
timeduration
ฺ m aj s Stu (5 years; 1 month;
P5Y1M4D10H20M1.2S
i n4adays; 20 h
t i
minutes; 1.2 seconds)
t e
en o-02-16T5:55:00
recurringinstant
v a l t us (February 16th every year
i (
c nse at 5
5:55
55 AM C
Coordinated
di d Universal
U i l Time)
Ti )
v
ro lice
long
j s t o e 1234567890123
a ab l
binary M r Bit pattern
i na s f e
l e nt tran
uri-reference standard URL
Va ID* n -
no XML 1.0 Compatibility
XML Fundamentals 5 - 22
Lesson Agenda
• XML schema
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
– Benefits
– Example
– Referencing an XML schema in an XML document
• Components of an XML schema
• Declaring a <simpleType> component
• Declaring a <complexType> component s a
h a
• Declaring attributes
s ฺrs) ฺ
• Using the JDeveloper XML Schema Editor @em uide
o v ic t G
• Validating an XML document by using: o r den
s t
– Oracle JDeveloper
ฺ m aj s Stu
– The oraxml command-line t i n autility thi
l e n use
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s
l e n r a n
Va non-t
XML Fundamentals 5 - 23
Declaring a <simpleType> Component
<simpleType>:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 5 - 24
Facets or properties that can be used in simpleType declarations:
Facet Description
s a
maxLength Maximum number of items in a list type, or h a
characters in a string type
s ฺrs) ฺ
minExclusive A minimum value, excluding @ emvalueuilisted
the de
c
vi nt G
r o
minInclusive sto including
A minimum jvalue,
a t u dethe value listed
a ฺ m his S
n in senumber
tMinimum t of items in a list type, or
minLength e
al characters
o u in a string type
( v t
o v ic nse
pattern
s t o r l i ce Restriction of string type based on a regular
M aj rable expression
t ina ansfe
totalDigits
n The total number of digits in a numeric value
l e -t r
Va whiteSpace
n o n
Control of how whitespace is treated within
a type. Values are preserve, replace,
and collapse.
XML Fundamentals 5 - 25
Using the <enumeration> Facet
. . .
<xsd:element name="job_id">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="AC_MGR"/>
<xsd:enumeration value="AD_PRES"/>
<xsd:enumeration value="FI_MGR"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
s a
. . .
h a
s ฺ rs)
<!-- The XML element can contain only one of the values --> m
e i d eฺ
<!-- specified in the enumeration list, as in this example
v i c@ t Gu
-->
. . .
<job_id>AC_MGR</job_id> <!-- is valid --> t o ro den
s
a-->j s Stu
<job_id>XX_MGR</job_id> <!-- is not valid
a ฺ m hi
t i n e t
en o us
. . .
a l
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
Example n t i n n s
l e
Toarestrict
r a
-tjob_id element value by using the <enumeration> facet:
V n o n
the
<xsd:element name="job_id">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="AC_MGR"/>
<xsd:enumeration value="AD_PRES"/>
<xsd:enumeration value="FI_MGR"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
The XML element can contain only one of the values specified in the enumeration list, as in
this example:
...
<job_id>AC_MGR</job_id> <!-- is valid -->
<job_id>XX_MGR</job_id> <!-- is not valid -->
...
XML Fundamentals 5 - 26
Using <list> and <union>
simpleType Declarations
• Declaring a <list>:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<xsd:element name="email">
<xsd:simpleType>
<xsd:list itemType="xsd:string"/>
</xsd:simpleType>
</xsd:element>
• Declaring a <union>: a
h a s
<xsd:simpleType name="mgrTypes">…</xsd:simpleType>
r s )
<xsd:simpleType name="repTypes">…</xsd:simpleType>
m sฺ eฺ
...
@ e uid
<xsd:element name="job_id"> c
vi nt G
<xsd:simpleType> r o
<xsd:union memberTypes="mgrTypes repTypes">
a jsto Stude
</xsd:simpleType>
n a ฺm this
</xsd:element> i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
The first i na
texampleaninsthe slide shows a declaration of a simpleType that provides a <list>
e n
l forn-the tr <email> element, which is shown in an XML snippet that uses a space-
of a
strings
V nolist of email strings. In the <union> example, suppose that mgrTypes and the
separated
repTypes are declared as follows:
<xsd:simpleType name="mgrTypes">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="AC_MGR"/>
<xsd:enumeration value="FI_MGR"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="repTypes">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="AC_REP"/>
<xsd:enumeration value="HR_REP"/>
</xsd:restriction>
</xsd:simpleType>
Then the following are valid XML snippets for the <job_id> element:
<job_id>AC_MGR</job_id>
<job_id>HR_REP</job_id>
XML Fundamentals 5 - 27
Lesson Agenda
• XML schema
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
– Benefits
– Example
– Referencing an XML schema in an XML document
• Components of an XML schema
• Declaring a <simpleType> component
• Declaring a <complexType> component s a
h a
• Declaring attributes
s ฺrs) ฺ
• Using the JDeveloper XML Schema Editor @em uide
o v ic t G
• Validating an XML document by using: o r den
s t
– Oracle JDeveloper
ฺ m aj s Stu
– The oraxml command-line t i n autility thi
l e n use
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s
l e n r a n
Va non-t
XML Fundamentals 5 - 28
Declaring a <complexType> Component
XML Fundamentals 5 - 29
Declaring a <sequence>
XML Fundamentals 5 - 30
Declaring a <choice>
XML Fundamentals 5 - 31
Declaring an Empty Element
<xsd:element name="departments">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="department"
maxOccurs="unbounded"/> s a
<xsd:complexType>
) h a
<xsd:attribute name="department_id" r s
sฺ eฺ
type="xsd:int"/>
<xsd:attribute name="department_name" m
e uid
c @
<xsd:complexType>
type="xsd:string"/>
r o vi nt G
</xsd:element>
</xsd:sequence> a jsto Stude
</xsd:complexType>
n a ฺm this
</xsd:element> i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t element s not allow text between the start and end tags. Empty elements are
e n
An empty
r a ndoes
V al useful
mostly
o n -tfor elements with only attributes (that is, elements that do not have text content).
n an empty element without attributes in the XML schema, use:
To declare
<xsd:element name="marker">
<xsd:complexType/>
</xsd:element>
The valid XML syntax for marker is <marker></marker> or <marker/>. The example in
the slide declares departments containing one or more department elements, each with a
department_id and department_name attribute.
Note: Text content is not allowed within each department element.
A valid XML instance document, using the XML schema in the slide, can contain:
<departments>
<department department_id="10"
department_name="Administration"></department>
<department department_id="20" department_name="Marketing"/>
</departments>
Note: The second <department> element does not use the end tag format.
XML Fundamentals 5 - 32
Using Element Wildcards
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s a form of element wildcard, which declares an element that does not
twant toause
You may
e n r n
al itsocontent
control
V n -t when including any elements declared in the XML schema or another
n Declare an element wildcard by using <any>, with the following key attributes:
namespace.
• The namespace attribute with a value of:
- ##any allows elements from all namespaces
- ##other allows elements from namespaces other than targetNamespace
- ##targetNamespace allows elements from targetNamespace
- ##local allows well-formed elements not qualified by a namespace
-A space-separated list of namespace URIs allows elements from the specified
namespaces
• The processContents attribute with a value of:
- skip indicates to the processor to skip wildcard elements in an instance document
- lax attempts the validation of the content elements if their declaring XML can be
accessed. However, errors are not flagged.
- strict (the default) validates the content if the declaring XML schema can be
accessed, and errors are flagged
Example: Use an element wildcard to create elements that you want to contain HTML/XHTML
tags as part of formatting instructions for the data within the element.
XML Fundamentals 5 - 33
Lesson Agenda
• XML schema
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
– Benefits
– Example
– Referencing an XML schema in an XML document
• Components of an XML schema
• Declaring a <simpleType> component
• Declaring a <complexType> component s a
h a
• Declaring attributes
s ฺrs) ฺ
• Using the JDeveloper XML Schema Editor @em uide
o v ic t G
• Validating an XML document by using: o r den
s t
– Oracle JDeveloper
ฺ m aj s Stu
– The oraxml command-line t i n autility thi
l e n use
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s
l e n r a n
Va non-t
XML Fundamentals 5 - 34
Declaring Attributes
Declare an <attribute>:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
Full Syntax
) h a
<attribute r s
sฺ eฺ
name="name-of-attribute" m
e uid
c @
vi nt G
type="global-type | built-in-type"
ref="global-attribute-declaration" r o
form="qualified | unqualified"
a j sto Stude
used="optional | prohibited | required"
n a ฺm this
default="default-value" i
nt use
l e
va e to
fixed="fixed-value">
c (
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t declared s using an <attribute> component are identified by a name and type
Attributes
e n r a nby
alis based
that
V o n t a built-in or user-defined <simpleType>. An attribute can be declared in
-on
n
three ways:
• As a local type contained within another component such as an <element> or an
<attributeGroup>
• As a global type that can be referenced, extended, and reused in a local type or as part
of an <attributeGroup>
• As a reference to an existing global type
In the slide, department_id is a global declaration if it appears as a direct child of the
<schema> component. Otherwise, it is a local type if nested within an element other than
<schema>. Other attributes of the <attribute> component are:
• ref, which derives the type from an existing global attribute declaration
• form, which indicates whether the attribute must be qualified by a namespace prefix or
not (the default)
• used, which indicates that the attribute is optional (the default), required, or
prohibited (not allowed)
• default, which defines a default value for the attribute when it is optional and not
specified
• fixed, which defines a constant value for the attribute
XML Fundamentals 5 - 35
Attribute Declarations: Example
1. Based on a <simpleType>:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<xsd:attribute name="department_id">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxInclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
XML Fundamentals 5 - 36
Declaring and Referencing
an <attributeGroup>
Declare an <attributeGroup>:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
• XML comments
• Attributes from other namespaces
• An <annotation> declaration:
– Provides an <appinfo> element
– Contains a <documentation> element
– Can be included within all other component types s a
) h a
r s
sฺ eฺ
<xsd:annotation>
<xsd:appinfo source="file:///d:/labs/anno.xml"/> e
m
i c @ Guid
<xsd:documentation> v t
A <b>big</b> comment about this Schematoro e n
</xsd:documentation> a js Stud
</xsd:annotation>
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i n a s ways to document your XML schema. Although XML comments are
t lists different
e n
The slide
r a n
al ofornreading
valuable
V -t the XML schema document, most processors will not report the XML
n
comments.
You can include references to attributes from namespaces other than the target namespace
of the XML schema document. These attributes are ignored by the Schema processor and
can be used to pass information to other applications, and act as comments to the human
reader of the document.
The best form of comment is to use the <annotation> declarations, which can be nested
within most other XML schema components as a form of documentation. As shown in the
slide, an annotation can contain any element from any namespace. For example, the <b> and
</b> elements represent bold text in the HTML/XHTML namespace. The <appinfo> element
is optional and can include a source attribute to identify an external file for application
processing or documentation. Different XML schema processors may ignore or treat
<appinfo> contents differently.
Note: When you create an XML schema document in JDeveloper, it automatically adds a
sample <annotation> element as a child of the <schema> component.
XML Fundamentals 5 - 38
Practice 5-1: Overview
XML Fundamentals 5 - 39
Lesson Agenda
• XML schema
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
– Benefits
– Example
– Referencing an XML schema in an XML document
• Components of an XML schema
• Declaring a <simpleType> component
• Declaring a <complexType> component s a
h a
• Declaring attributes
s ฺrs) ฺ
• Using the JDeveloper XML Schema Editor @em uide
o v ic t G
• Validating an XML document by using: o r den
s t
– Oracle JDeveloper
ฺ m aj s Stu
– The oraxml command-line t i n autility thi
l e n use
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s
l e n r a n
Va non-t
XML Fundamentals 5 - 40
Creating an XML Schema Document
in JDeveloper
1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
2
5 a
h a s
r
ฺ ฺs )
4 m s
Right-click.
@ e uide
c
vi nt G
r o
a jsto Stude 6
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t an XML s
l e n
To create
t r a n
schema document:
V1.a Select
n o na- project node and select File > New. Alternatively, you can right-click the project
node and select New from the shortcut menu.
2. In the New Gallery window, expand the General category and select the XML node.
3. Double-click XML Schema. Alternatively, you can select XML Schema and click OK.
4. In the Create XML Schema window, enter the XML schema file name and click OK.
5. The XML schema document is created and opened in the XML Schema Editor, which
provides two editing tabs:
a. A Design tab to graphically edit the XML schema
b. A Source tab to textually edit the document by using an XML editor that is aware
of the XML Schema recommendation elements and attributes. Initially, on the
Design tab, view the <schema> element with a default targetNamespace
attribute and a single child element called exampleElement that is created.
6. Add XML schema components visually on the Design tab. Perform either of the
following:
- Right-click an item and select a component from the shortcut menu.
- Drag Schema Components from the Component Palette to the Design window.
XML Fundamentals 5 - 41
Using the JDeveloper XML Schema Editor
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
1
s a
) h a
r s
sฺ eฺ
m
e uid
i c @ G 3
o v n t
4 j s tor tude
ฺ m a sS
t i n a
e t hi
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n
As shown i n s the XML Schema Editor can be used visually by using the Design tab
t in theaslide,
n
e r
al Alterations
view. -t made to the Design tab alter the source code by adding, modifying, or
V o n
n the associated XML elements in the document, which can be viewed on the Source
removing
tab.
When you edit on the Design tab:
1. Components can be:
- Moved by using drag-and-drop techniques
- Added to other components by right-clicking a component and selecting an object
from the context-sensitive menu
- Clicked to change their name in place, or by using the Property Inspector
2. The Component Palette provides XML components that can be dragged to the Design
window
3. The Property Inspector displays properties that can be altered to set component
properties such as minOccurs, maxOccurs, and type attribute values
4. The Structure pane displays the hierarchical structure of the document and indicates
validation errors. The Structure pane can be used to navigate between components and
add, modify, and delete components.
Click the Source tab to use the text-based XML Editor to view or make changes.
Note: For help on a component, select the node and press F1.
XML Fundamentals 5 - 42
Using the JDeveloper
XML Schema‒Aware XML Editor
To use the features of the XML schema‒aware editor:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s
t areadiscussed
(Thesensteps
l e t r n in detail on the following pages.)
o n-
V1.a InnJDeveloper, register the XML schema document, which can be located in a file on
disk or from a URL on the web.
2. Create an XML document associated with an XML schema.
3. The code-insight automatically becomes aware of the registered XML schema, and you
can start using it to rapidly create an XML instance document.
Note: JDeveloper has a list of preregistered XML schemas (such as the XML Schema
Recommendation) that enable you to rapidly and visually create your own XML schema
documents.
XML Fundamentals 5 - 43
Registering an XML Schema with JDeveloper
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
1
s a
) h a
s r
ฺ ฺs
2 m
e uide
c @
r o vi nt G
jsto Stude 6
4
a
ฺm this
t i n a
l e 5n u s e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
tschemaacan sbe registered or imported into JDeveloper, thereby enabling the XML
An XML
e n r n
al to obecome
Editor
V n -t aware of the XML schema.
n an XML schema with JDeveloper:
To register
1. Select Tools > Preferences from the menu to open the Preferences window.
2. Click the XML Schema node.
3. Click Add to open a dialog box for entering the XML schema location.
4. In the Add Schema dialog box, click the Browse button to find the schema that you want
to register.
5. Click OK to add the new XML schema to the User Schemas for XML Editing list.
6. Click OK to close the Preferences window. The new XML schema is now registered.
JDeveloper automatically validates the XML schema when you add it.
To use the XML schema–aware editing feature after the XML schema is registered:
1. Create an XML document.
2. Enter the root element of the document and associate it with an XML schema by
declaring the default namespace (or a namespace prefix) with the same value as the
targetNamespace specified in the appropriate XML schema document.
You can use a simple wizard to create an XML document from an XML schema. In the wizard
steps, you can select the target namespace for the XML schema, and the root element.
XML Fundamentals 5 - 44
Creating an XML Document from an XML Schema
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t an XML s
l e n
To create
t r a n
document from an XML schema in JDeveloper:
V1.a Select
n o na- project node and select File > New. Alternatively, you can right-click the project
node and select New from the context menu.
2. In the New Gallery window, expand the General category, and then select the XML
node.
3. Double-click XML Document from XML Schema. The Create XML Schema
Document from the XML Schema wizard is launched.
4. Click Next to continue.
5. Specify the file name, directory, and schema location. You can use either a schema that
is available in the file system or a schema that is already registered with JDeveloper.
6. Select the target namespace for the XML schema, the root element. Then click Finish.
The XML document instance is created. This XML document has all the elements
defined in the XML schema that are needed to instantiate the XML document.
Note: You can also choose to specify other options, such as the depth of the XML document
to be generated in terms of element levels, and encoding.
XML Fundamentals 5 - 45
Using the XML Schema–Aware XML Editor
s a
2 3 ) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
tXML schema s is registered with JDeveloper, the XML Editor becomes aware of its
e n
After the
r a n
al onThe
vocabulary.
V -t JDeveloper code-insight feature can then provide you with a context-
n selection of elements, attributes, and namespace prefixes.
sensitive
To use the schema-ware XML editor:
1. Create the root element, and assign the XML schema namespace as defined in the XML
schema in a default (or prefixed) namespace declaration in the instance document.
2. Enter a less-than (<) character and wait for a second, after which JDeveloper code-
insight displays the elements that are appropriate to that context. In the slide, the child
element of the <department> element includes the department_id,
department_name, location_id, manager_id, and elements from the xsi:
namespace (if the departments XML schema permits).
3. Alternatively, perform a drag-and-drop operation with an element from the Component
Palette if it has been configured using the Tools > Configure Palette menu.
Notes
• You perform the preceding step 1 if you do not use the wizard to create an XML
document from an XML schema.
• Entering a less-than (<) character causes elements to be displayed; adding a space
after the start tag causes a list of attributes to be displayed for the element; and entering
a colon (:) after a namespace prefix displays elements in the namespace (if accessible).
XML Fundamentals 5 - 46
Lesson Agenda
• XML schema
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
– Benefits
– Example
– Referencing an XML schema in an XML document
• Components of an XML schema
• Declaring a <simpleType> component
• Declaring a <complexType> component s a
h a
• Declaring attributes
s ฺrs) ฺ
• Using the JDeveloper XML Schema editor @em uide
o v ic t G
• Validating an XML document by using: o r den
s t
– Oracle JDeveloper
ฺ m aj s Stu
– The oraxml command-line t i n autility thi
l e n use
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s
l e n r a n
Va non-t
XML Fundamentals 5 - 47
Validating an XML Document with
Its XML Schema in JDeveloper
To validate an XML document with its XML schema:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
1 ) 2h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
Application Navigator a jsto StXML udeEditor
n a ฺm this
• Select Validate XML from
i
nt theucontext s e menu.
a l e o
v
c ( nse t
v i
t o ro © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
s
aj rable
M
n
After an t inadocument
XML n s feis associated with an XML schema, the XML instance document can
beavalidated
V tra the XML schema.
le n-against
noshows two ways to validate the XML document in JDeveloper:
The slide
• Right-click the XML document name in the Navigator pane, and then select Validate
XML from the context menu (example 1 in the slide).
• Right-click the Source tab of the XML Editor and select Validate XML from the context
menu (example 2 in the slide).
Note: The Validate XML menu item is unavailable when the XML document is not associated
with an XML schema. You can also use the oraxml command-line utility to validate an XML
document against an XML schema.
XML Fundamentals 5 - 48
Validating an XML Document with its XML
Schema with the oraxml Java Utility
The oraxml Java command-line utility:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 5 - 49
Applications for XML Schema
• E-commerce
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt usXML e schema validates
a l e o the XML information exchanged.
( v t
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
n t ina ansInfeboth business-to-business and business-to-consumer e-commerce,
• E-commerce:
le isn-largely
tr dynamic. XML schemas map robustly to server-driven data models such
Va data
o
nSQL:1999,
as which provides user-defined types, inheritance, references between
types, and collections of types among others. Libraries of schemas define business
transactions within markets and between parties. XML schemas validate a business
document and provides access to its information set.
• Web publications and syndication: The key to syndication on the web is the highly
customizable distribution between publishing and syndication services. Collections of
XML documents with complex relations (such as cross-references and kind-of relations)
among them will be the norm. Protocols (such as Simple Object Access Protocol, or
SOAP) that are built on XML can take advantage of the complex structural aspects of
XML schema.
• Enterprise application integration (EAI): The essence of an EAI hub-and-spoke
architecture is the dynamic data exchange between loosely coupled applications. DTDs
cannot fully describe today’s exchange data models. XML schema capability for
metadata interchange simplifies EAI and is an important optimization technology.
• Process control and data acquisition: In multivendor, distributed systems such as
those in plant automation, security, devices, and traffic routing, XML schema can aid
outgoing and incoming message validity. Controllers can determine which parts of
messages they understand, when to ignore information, and when to raise errors.
XML Fundamentals 5 - 50
Converting a DTD to an XML Schema
<employee>
<employee_id>120</employee_id> XML
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<last_name>Weiss</last_name> document
</employee>
s a
) h a
<xsd:complexType name="employeeType">
r
sฺ eฺs
<xsd:sequence>
m
e uid
<xsd:element name="employee_id" type="xsd:int"/>
i c @ GXML
<xsd:element name="last_name" type="xsd:string"/>
o
r de v n t schema
</xsd:sequence>
s t o
</xsd:complexType>
ฺ m aj s Stu
t i n a
e t hi
<xsd:element name="employee"
a l entype="employeeType"/>
o us
v
c ( nse t
v i
t o ro © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
s
aj rable
M
The XML n t na in n
icode s
the
e
ffirst example conforms to both the DTD and the XML schema in the
l e t r a
- parser that uses the DTD can only discern that the elements are strings. By
a A validating
slide.
V nonschema, a validating parser can discern that employee_id is an integer and
using XML
last_name is a string.
The slide presents a simple example that is easily converted by manually entering the XML
schema, provided that you understand the structure represented by the DTD. There are
several ways to automate the conversion of a DTD to an XML schema:
• Using JDeveloper
• Writing your own application with an API that provides the capabilities to convert a DTD
to an XML schema, such as in the Oracle XML Developer’s Kit (XDK)
Note: The XDK provides API calls to enable the development of an application that converts
a DTD to an XML schema.
Oracle XML SQL Utility (XSU) can generate an XML schema document from a database table
definition.
XML Fundamentals 5 - 51
Quiz
XML Fundamentals 5 - 52
Summary
XML Fundamentals 5 - 53
Practice 5-2: Overview
XML Fundamentals 5 - 54
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Objectives
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t you s about basic XML Path Language (XPath) syntax, abbreviated
e n
In this lesson,
r a nlearn
al on-and
expressions,
V t functions. You use JDeveloper’s XPath Search feature to search an XML
documentn by using XPath expressions.
XML Fundamentals 6 - 2
Lesson Agenda
• XPath expressions
– Location path expression
– Location steps
– XPath axes
– Node test types
– Abbreviated and unabbreviated XPath expressions s a
h a
ฺrs) ฺ
– XPath predicates
s
• XPath functions
@ em uide
• Testing XPath expressions o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 6 - 3
What Is XML Path Language?
XML Fundamentals 6 - 4
XPath 1.0 and XPath 2.0
2.0.
• The major difference between the two versions lies in the
following:
– XPath 1.0 supports node-sets.
– XPath 2.0 supports sequences.
• XQuery and XPath 2.0 share the same data model. a
h a s
• XPath 2.0 is a syntactic subset of XQuery.
s ฺrs) ฺ
• This lesson focuses on XPath 1.0. em de @ Gui
i c
t o rov dent
a js Stu
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s language such that the operands of various expressions, operators,
XPath nis ta strongly
a ntyped
e
alfunctions
and r
-tmust conform to designated types. It is a case-sensitive expression language.
V n o n
Typically, it is used by an XSLT Processor, where the context node changes as the processor
navigates through the XML document nodes. An XSLT Processor is guided by template
instructions that contain XPath expressions that are used to match nodes in the tree.
Notes
• The XPath 2.0 data model is different from the XPath 1.0 model. W3C specifies XQuery
1.0 and the XPath 2.0 data model, which is the data model of XSLT 2.0, XPath 2.0, and
XQuery.
• XPath 2.0 supports all the simple primitive data types that are built into XML Schema.
• For more information about additional features in XPath 2.0, see:
- The section titled “XPath 2.0.” in this lesson
- The website at http://www.w3.org/TR/xpath/
XML Fundamentals 6 - 5
XPath Terminology: Node Types
• Element
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
• Attribute
• Text
• Namespace
• Processing instruction
• Comment
• Document node s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na streated as trees of nodes. The topmost element of the tree is called the
e n
XML documents
r a n
are
V alelement.
root
o n -t
n there are seven kinds of nodes (as listed in the slide).
In XPath,
XML Fundamentals 6 - 6
XPath Terminology: Family Relationships
XML Fundamentals 6 - 7
XPath Model
4
3 <department> Num="1" 4 <department> Num="2"
s a
h a
Attribute node
ฺrs) ฺ
<department_id> <department_name> 3 . . .
s
3 @ em uide
o v ic t G
10
5 Administration 5 t o r den
s
aj s Stu
a ฺ m hi
t i
n us n e t
Text nodes ale
c ( v e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t ananXML s document as a tree of nodes. The graphic in the slide depicts the
XPath n models
e
al otypes
different r
-t of nodes as seen by XPath in an XML document:
V n n
1. Document root node, which is a virtual document root that is the parent of the entire
XML document containing the XML declaration, the root element and its children,
comments, and processing instructions at the beginning and end of the document
2. Root element node (for example, the <departments> element)
3. Element nodes (for example, the <department>, <department_id>, and
<department_name> elements. The root element node is also an element node.)
4. Attribute nodes (for example, the num="1" node)
5. Text nodes (for example, the nodes containing the text 10 and Administration)
Note: In the XPath model, the document root is not the same as the root element node.
XPath can also address comment nodes, processing instruction nodes, and namespace
nodes, which have not been shown in the diagram. XPath defines a way to compute a string
value for each type of node, some of which have names. Because XPath fully supports the
XML Namespaces Recommendation, the node name is modeled as a pair that is known as
the expanded name, which consists of a local part, and a namespace URI, which may be
null.
XPath allows various kinds of expressions to be nested with full generality.
XML Fundamentals 6 - 8
Lesson Agenda
• XPath expressions
– Location path expression
– Location steps
– XPath axes
– Node test types
– Abbreviated and unabbreviated XPath expressions s a
h a
ฺrs) ฺ
– XPath predicates
s
• XPath functions
@ em uide
• Testing XPath expressions o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 6 - 9
XPath Expressions
An XPath expression:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 6 - 10
Location Path Expression
XML Fundamentals 6 - 11
Location Path Expression: Example
/departments/department/department_id XPATH
expression
<?xml version="1.0" encoding="UTF-8"?>
<departments>
<department num="1">
<department_id>10</department_id>
<department_name>Administration</department_name>
</department> XML
</departments> s a
<department num="2">
) h a
<department_id>20</department_id> r s
sฺ eฺ
<department_name>Marketing</department_name> m
e uid
</department>
c @
</departments>
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s
t pathanexpression
l e n
The location
t r shown in the slide is an absolute path that uses the document
a as the
root - node. An absolute location path always starts with a slash (/), and is
context
V
followed nobyna relative location path that comprises the following location steps:
1. Go to the <departments> root element relative to the document root.
2. Go to the first child <department> element of the <departments> node.
3. Go to the <department_id> child element of the <department> node.
If the sample XML document includes more than one <department> element and child
<department_id> element, the XPath expression matches multiple <department_id>
nodes or a set of <department_id> nodes. The result is the entire element from the start to
the end tags, plus the data between them. As shown in the highlighted portion of the slide, the
result includes <department_id>10</department_id> and
<department_id>20</department_id>.
XML Fundamentals 6 - 12
Results of Location Path Expressions
• Empty
• A single node
• A set of nodes
<?xml version="1.0" encoding="UTF-8"?>
<departments>
<department num="1">
s a
<department_id>10</department_id>
h a
ฺrs) ฺ
<department_name>Administration</department_name>
</department> s
</departments>
@ em uide
<department num="2">
o v ic t G
<department_id>20</department_id> t o r den
<department_name>Marketing</department_name> s
aj s Stu
a ฺ m hi
</department>
t i n e t
</departments>
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n
When you i n
t evaluate n slocation path expressions, you obtain one of the following results:
l e -t r a
V•a Empty
n o n
• A single node
• A set of nodes (more than one node)
The slide shows a skeleton XML document of departments and various location path
expressions.
XML Fundamentals 6 - 13
Results of Location Path Expressions: Examples
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Absolute
Relative
2as a
s ) h
r
sฺ eฺ
m
e uid
c @
Absolute
r o vi Relative
n t G
a jsto Stude 3
ฺ m i s
n t ina se th
v a le to u
v i c ( nse
t o ro © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
s
aj rable
M
The slide
n t na the
ishows n s fe
departments.xml document and various location path expressions
and
V
e resulting
altheir n - tra nodes by using the Oracle JDeveloper XPath Search tool. The relative
no
location paths in the examples assume that the context node is the document root:
• The first example is an absolute location path expression that selects the document root,
and results in the entire document matching the expression.
• The second example shows a relative and an absolute location path that select the root
element node as their result.
• The third example provides a relative and absolute location path selecting the set of
department child elements of the root element.
In the second example, departments is called a location step. In the last example,
departments is the first location step, which is followed by a slash, and then the
department location step, thus forming a compound XPath expression.
XML Fundamentals 6 - 14
Location Steps in XPath Expressions
ancestor
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
parent/ancestor
preceding-sibling
XML Fundamentals 6 - 17
Selecting Nodes by Using
Abbreviated XPath Expressions
Expression Description
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 6 - 18
Selecting Nodes by Using
Abbreviated XPath Expressions: Examples
Abbreviated XPath Results
Expression
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 6 - 19
Abbreviated and Unabbreviated
XPath Expressions
Abbreviated XPath Unabbreviated XPath Expression
Expression
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
departments child::departments
employee/salary child::employee/child::salary
* child::*
. self::node()
.. parent::node()
s a
../salary parent::node()/child::salary
) h a
r s
sฺ eฺ
@id attribute::id
m
e uid
c @
department/@num child::department/attribute::num
r o vi nt G
text() child::text()
a jsto Stude
//salary a ฺm this
/descendant-or-self::node()/child::salary
n
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s shows the abbreviated and unabbreviated XPath expression examples
t in the aslide
The table
e n r n
al the oprevious
from
V n -t page:
n
• child::departments selects the department child elements of the context node.
• child::employee/child::salary selects the salary child elements of the
employee child elements of the context node.
• child::* selects all element children of the context node.
• self::node() selects the context node.
• parent::node() selects the parent node of the context node.
• parent::node()/child::salary selects the salary child element from the parent
of the context node.
• attribute::id selects the id attribute of the context node.
• child::department/attribute::num selects the num attribute from the
department child elements of the context node.
• child::text() selects all text node children of the context node.
• /descendant-or-self::node()/child::salary selects all salary elements of
the context node or its descendents.
Note: child::node() selects all the children of the context node, whatever their node type.
Using attribute::* selects all the attributes of the context node.
XML Fundamentals 6 - 20
Using abbreviated syntax:
• name selects the name element children of the context node
• / selects the document root, which is always the parent of the document element
• text() selects all text node children of the context node
• comment() selects all the comments node children of the context node
• node() selects all the child node types of the context node
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
j s to le lic
M a rab
n t ina ansfe
le r
Va non-t
XML Fundamentals 6 - 21
Abbreviated XPath Expression Examples:
employees.xml Document
<?xml version="1.0"?>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
//last_name <last_name>King</last_name>
<last_name>Kochhar</last_name>
employees/employee/ Steven
name/first_name/text() Neena
employees/salary <salary>24000</salary>
<salary>18000</salary>
<?xml version="1.0"?>
<!-- Employee data -->
<employees>
s a
<employee employee_id="100">
) h a
<name>
<first_name>Steven</first_name>
<last_name>King</last_name> r s
sฺ eฺ
</name> m
e uid
<salary>24000</salary>
c @
</employee>
<employee employee_id="101">
r o vi nt G
jsto Stude
<name>
<first_name>Neena</first_name>
ฺm this
<last_name>Kochhar</last_name> a
</name>
i n a
nt use
<salary>18000</salary>
</employee>
l e
va e to
</employees>
c (
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t path scan be expressed by using abbreviated syntax rather than verbose
e n
Every location
r a n
al on-t syntax. The table in the slide provides some examples of how to select nodes
unabbreviated
V n abbreviated XPath expressions.
by using
Note: The context node is the document root. <first_name> and <last_name> are
children of <name>. The comment is a child of the document root.
XML Fundamentals 6 - 23
Selecting Nodes by Using
Abbreviated XPath Expressions: Examples
Abbreviated XPath Expression Results
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
employees/employee/@employee_id employee_id="100"
employee_id="101"
comment() <?xml version="1.0"?>
<?xml version="1.0"?>
<!-- Employee data -->
<employees>
s a
<employee employee_id="100">
) h a
<name>
<first_name>Steven</first_name>
<last_name>King</last_name> r s
sฺ eฺ
</name> m
e uid
<salary>24000</salary>
c @
</employee>
<employee employee_id="101">
r o vi nt G
jsto Stude
<name>
<first_name>Neena</first_name>
ฺm this
<last_name>Kochhar</last_name> a
</name>
i n a
nt use
<salary>18000</salary>
</employee>
l e
va e to
</employees>
c (
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t path scan be expressed by using abbreviated syntax rather than verbose
e n
Every location
r a n
al on-t syntax. The table in the slide provides some examples of how to select nodes
unabbreviated
V n abbreviated XPath expressions.
by using
XML Fundamentals 6 - 24
Abbreviated XPath Expression Examples:
departments.xml Document
<?xml version='1.0' encoding='UTF-8'?>
<departments>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<department num="1">
<department_id>10</department_id>
<department_name>Administration</department_name>
<manager_id>200</manager_id>
<location_id>1700</location_id>
</department>
<department num="2">
<department_id>20</department_id>
<department_name>Marketing</department_name>
<manager_id>201</manager_id>
<location_id>1800</location_id>
</department>
s a
<department num="3">
h a
ฺrs) ฺ
<department_id>30</department_id>
<department_name>Purchasing</department_name>
s
em uide
<manager_id>114</manager_id>
<location_id>1700</location_id>
</department> @
ic t G
<department num="4">
o
r denv
<department_id>40</department_id>
s t o
<department_name>Human Resources</department_name>
ฺ m aj s Stu
hi
<manager_id>203</manager_id>
<location_id>2400</location_id>
t i n a t
</department>
l en o us e
</departments>
a
(v se t
i c
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
i n
t expression
Each XPath
n n s on the following pages is applied to the departments.xml
e
al othat
document r a
-t is shown in this slide.
V n n
//department[@num<3]/department_id[.="10"]
Literal strings Literal strings are quoted with single or double quotation marks.
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n
The slide i n s
t lists theanoperators that can be used in predicates and XPath expressions. The
l e
a onoperators
comparison - t r include:
V n
• Less than or equal to (<=), or less than (<)
• Greater than or equal to (>=), or greater than (>)
• Equal to (=), and not equal to (!=)
• A combination of multiple predicates by using a lowercase and, lowercase or, or both
The mathematical operators include:
• The asterisk (*) for multiplication
• The lowercase div for division
• The lowercase mod for the remainder of a division
• The plus sign (+) for addition
• The minus sign (-) for subtraction
When using XPath in XSLT Style Sheet documents, the “<” character must be entered by
using its entity representation, that is, using <. In addition, literal strings in expressions,
which are usually delimited by single or double quotation marks, must use entity names to
enter quotation marks, that is, either " or ' as appropriate.
Predicates can be combined as follows: [predicate1][predicate2]. This is the same as
using an and operation: [predicate1 and predicate2].
XML Fundamentals 6 - 28
Lesson Agenda
• XPath expressions
– Location path expression
– Location steps
– XPath axes
– Node test types
– Abbreviated and unabbreviated XPath expressions s a
h a
ฺrs) ฺ
– XPath predicates
s
• XPath functions
@ em uide
• Testing XPath expressions o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 6 - 29
XPath Functions
function-name(arguments,...)
s a
) h a
• May return one of the following four types: r s
sฺ eฺ
– Boolean
m
e uid
c @
– Number r o vi nt G
– Node-set a jsto Stude
n a ฺm this
– String i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na sused in predicates and expressions to yield one of the following four
XPath n
e functions
r n
are
a
V al types:
result
o n -t
• AnBoolean function can operate on Boolean expressions to return a true or false
result.
• A number function is used to operate on numbers, and returns floating-point values.
• A node-set function operates on a set of nodes selected by a location path expression,
and returns a result, usually a numeric value.
• A string function operates on Unicode strings values.
The position() function is an example of a node-set function. Functions in each of these
categories are discussed on the next few pages.
Note: XPath 2.0 provides more functions than XPath 1.0. XPath 2.0 shares its function library
with XQuery 1.0. For more information, see the lesson titled “Working with XQuery.”
XML Fundamentals 6 - 30
Boolean Functions
Function Description
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 6 - 31
Number Functions
Function Description
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
ceiling(n) Returns the smallest integer that is greater than a given number
floor(n) Returns the largest integer that is less than a given number
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t functions s can be used to manipulate numeric data. The number functions are the
e n
The number
r a n
al on-t
following:
V
• Then number() function converts its argument to a number. For example,
number('6.75') returns the numeric value 6.75.
If the argument is a Boolean expression, true is converted to a value of 1 and false
returns a value of 0. If the argument is not convertible to a number, this function returns
NaN (not a number).
• The sum() function accepts a node-set as an argument and returns the result of the
sum of the nodes. Each node is first converted to a string value, and then to a number
before being summed up.
• The ceiling() function returns the smallest integer that is greater than its argument.
For example, ceiling(2.35) returns a value of 3.
• The floor() function returns the largest integer that is less than its argument. For
example, floor(2.35) returns a value of 2.
• The round() function returns the number rounded to its nearest integer. For example,
round(2.35) returns the value 2, and round(2.65) returns the value 3.
XML Fundamentals 6 - 32
Node-Set Functions
Function Description
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
//department[position()=1]
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
//department[last()]/department_name sto
a j t u de
a ฺ m his S
e n tin se t
( v al to u
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
n t inafunctions
The node-set n s fethat manipulate and return information about a set of nodes include:
le last()
V•a The n - tra function that returns the number of nodes in the context node-set
• Thenoposition() function that returns the context position. For example,
//employee[position()=2] returns the second employee descendant node.
• The id() function that accepts a string containing one or more space-separated ID
values as the argument. It returns a node-set containing all nodes in the document that
have those ID values, which are declared as an ID attribute type in the DTD; that is, the
attribute is not named but is declared as a unique ID attribute type.
• The count() function is similar to last(). It gives a count of the number of nodes in
its node-set argument. For example, count(//employee) gives you the number of
employee elements in the document.
• The local-name() function returns the local name, without a namespace prefix, of the
first node in the node-set argument. If no argument is provided, the name of the context
node is returned.
The first example in the slide locates the first department element by its position in the node-
set. This is equivalent to //department[1]. The second example locates the last
department in the node-set, which can be written as:
//department[count(//department)]/department_name
Note: The node-set functions that are not listed in the slide are:
• namespace-uri(), which returns the namespace URI string of a node
• name(), which returns the qualified name of a node
XML Fundamentals 6 - 33
String Functions
Function Description
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
contains(s,s) Accepts two arguments and returns true if the first argument
contains the second
starts-with(s,s) Takes two arguments and returns true if the first argument starts s a
with the second; otherwise, returns false h a
s ฺ r s)
string-length(s) Returns the length of a string
e m ideฺ
Return the department elements with the department_name v i c@ tchild
G u
nodes
t o r o en
that start with the uppercase letter A.
a js Stud
n a ฺm this
n t i
/departments/department[starts-with(department_name,
e
'A')]
v a le to us
v i c ( nse
t o ro © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
s
aj rable
M
t ina afunction
The string()
n n sfe converts any type of data to a string.
e
alconcat() - tr function returns the concatenation of its arguments. For example,
V
The
no n
concat('This is ','cool') returns the string 'This is cool'.
The substring() function takes three arguments: the string to evaluate, a start position,
and a length. If the length is omitted, the return string contains all the characters from the start
position to the end of the evaluated string, as in the following examples:
• substring('employee',1,3) returns the string 'emp'.
• substring('Administration',6) returns 'istration'.
The contains() function searches for the presence of the second argument within the first.
If it is present, it returns true; otherwise, it returns false:
• contains('Steve King','ing') is true.
• contains('Neena Kocchar','charm') is false.
The starts-with() function returns true if the first argument starts with the second;
otherwise, it returns false. For example, starts-with ('Administration', 'Adm')
returns true.
The string-length() function returns the length of its argument as an integer value. For
example, string-length('King') returns a value of 4.
The example in the slide returns the <department> elements with the
<department_name> child nodes that start with the uppercase letter A.
XML Fundamentals 6 - 34
XSLT and XPath
XSLT:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 6 - 35
Note: The XSLT Specification states that XSLT processors must provide a default template
rule that causes text nodes to be output if no matching template rules exist. Suppress the
output of unprocessed text nodes by including, at the end of the XSLT Style Sheet, a template
rule that matches all the text nodes that do not output data. For example, as shown in the
slide, use:
<xsl:template match="*/text()"/>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Note: The example in the slide provides a context where XPath expressions can be used.
XSLT is covered in detail in the lesson titled “Using XSL Transformations to Transform XML
Documents.”
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 6 - 36
Lesson Agenda
• XPath expressions
– Location path expression
– Location steps
– XPath axes
– Node test types
– Abbreviated and unabbreviated XPath expressions s a
h a
ฺrs) ฺ
– XPath predicates
s
• XPath functions
@ em uide
• Testing XPath expressions o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 6 - 37
Testing XPath Expressions
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
1 2 s a
h a
s ฺrs) ฺ
@ em uide
o v ic 3 t G
t o r den
To view the results of XPath s
aj s Stu
ฺ m
expressions, use Search >
XPath Search in JDeveloper. ntin
a
e thi
v a le to us
v i c ( nse
t o ro © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
s
aj rable
M
a sfe
t
To viewntheinresults
a nof XPath expressions, use:
l e t r
V•a The n n- Search option in JDeveloper
oXPath
• An XSL stylesheet to transform an XML document that can be viewed in an XML-
enabled browser
The screenshots in the slide show the following steps to use JDeveloper’s XPath Search
option:
1. Open an XML document in JDeveloper, and then select Search > XPath Search.
2. In the XPath Search – Log pane that appears, specify the XPath expression in the
Expression field as shown in the slide example, and then click OK.
3. In the Results section of the Search – Log pane, view the results of applying an XPath
expression to your XML document.
Note: In the XPath Search – Log pane, XPath version 2.0 is selected by default. In the slide
example, XPath 1.0 was selected from the drop-down list.
XML Fundamentals 6 - 38
XPath 2.0
XPath 2.0:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
date and time. For example, the current-date() and current-time() functions return
the current date and current time in a standard format, respectively.
XPath 2.0 supports conditional logic:
if(/po:PurchaseOrder/po:Seller = 'ABC') then 'Yes' else 'NO'
The expression in parentheses first evaluates to true or false. Depending on this
evaluation result, the expression returns the then or else section.
Note: You learn how to use some of the XPath 2.0 functions in the lesson titled “Working with
XQuery.” s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 6 - 40
Quiz
XML Fundamentals 6 - 41
Summary
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 6 - 43
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Objectives
XML Fundamentals 7 - 2
Lesson Agenda
XML Fundamentals 7 - 3
What Is XSL?
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
XSL t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i
XML documents n n s structure and, unlike HTML, do not provide formatting or display
have
e
al on-XSL
instructions. r a
t adds the capability of transforming an XML document into another
V n containing XML with a different structure, or into an HTML document with
document
formatting tags.
XSL has the following parts:
• XSL Transformations (XSLT) is an XML application that processes the rules contained
in an XSLT Style Sheet. The rules in an XSLT Style Sheet can be applied to any XML
document.
• XSL Formatting Objects (XSL-FO) is an XML application that is used to describe the
precise layout of text on a page. XSLT is used to generate XSL-FO elements that are
output to another XML document. Additional processing is needed to create the final
output form such as a portable document format (PDF) document.
This lesson focuses on XSLT. The screenshot in the slide depicts an XML document and an
XSLT Style Sheet document being processed by an XSL Processor. The XSL Processor is an
XML application that applies transformation rules to the XML document as specified in the
XSL document and produces a new document as the result.
Note: XSLT is available in two versions. XSLT 1.0 is more widely used and implemented.
XSLT 2.0 is a revised version of the XSLT 1.0 recommendation. For more information about
XSLT 2.0, see the section titled “XSLT 2.0.”
XML Fundamentals 7 - 4
XSL Transformations
XSL
stylesheet s a
) h a
r
ฺ ฺs
sOutput
m
e uide
Matching
<?xml version="1.0"?>
i c @ G data
<xsl:stylesheet ...>
o v n t
rule
<xsl:template match="XPath"/>
j s t or ude
<!-- output information
m a --> S t
</xsl:template> a
n ฺ t h is
t i e
</xsl:stylesheet>
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n
XSL Transformations n s (XSLT) is an XML application, or XSL Processor, that processes rules
e
alspecify r a
-t to transform one XML document into another XML document. The rules are
that
V o nhow
n in an XSLT document called an XSLT Style Sheet, which itself is an XML document
contained
and must be well-formed.
The slide shows that an XSLT Style Sheet contains one or more template rules. Each
template rule has two parts:
• A match pattern, which is specified as an XPath expression in an attribute of an
<xsl:template> element
• Template data, appearing between the start and end tags of the <xsl:template>
element, which contains the output information. The template data typically contains
XML and HTML elements mixed with the XSLT rules.
The XSL Processor compares the elements in the XML input document with the template rule
pattern in the XSLT Style Sheet, and writes the template data for matching rules to the output
tree, typically, another XML document. Essentially, the transformation process operates on
the tree data structure of a source (input) XML document and produces a tree of nodes as its
output.
Notes
• XSL-FO elements are output elements found in <xsl:template> rules.
• XSLT 2.0 enables you to transform textual data that is not well-formed XML. XSLT 2.0
enables multiple-output documents.
XML Fundamentals 7 - 5
XSLT Style Sheet
XML Fundamentals 7 - 6
XSLT Style Sheet: Example
<?xml version="1.0"?> 1
<xsl:stylesheet version ="1.0"
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 2
<xsl:template match="/"> 3
<html>
<body>
<table border="1">
<tr><th>Id</th><th>Name</th><th>Salary</th></tr>
<xsl:apply-templates/>
</table>
</body>
</html> 5 4 s a
</xsl:template>
) h a
r s
sฺ eฺ
<xsl:template match="employee"> m
e uid
<tr>
c @
<td><xsl:value-of select="employee_id"/></td>
r o vi nt G
sto Stude
<td><xsl:value-of select="last_name"/></td>
<td><xsl:value-of select="salary"/></td>
a j
</tr>
n a ฺm this 6
</xsl:template> i
nt use
</xsl:stylesheet>
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t document sin the example, called a style sheet, shows the following components:
e n
The XSLT
l standard r a n
V1.a The o n -t XML document declaration (because a stylesheet is an XML document)
n
2. The mandatory XML namespace declaration that uses the xsl namespace prefix, and
the URI http://www.w3.org/1999/XSL/Transform namespace
3. The <xsl:template> rule that matches the root of the source XML document
4. The template data that contains the HTML tags to be written to the output document
5. The <xsl:apply-templates> element that instructs the XSLT Processor to apply
template rules, if any, to the child elements of the root in the source document. The
<xsl:apply-templates> element is replaced by any output generated for matching
child element template rules.
6. The <xsl:template> rule for matching the <employee> elements in the source
document with the template data containing the HTML table row (<tr>...</tr>) tags
that enclose three table data (<td>...</td>) tag pairs. Each table data tag pair
encloses an <xsl:value-of select="..."/> rule that inserts the value of the
source document element selected by the XPath expression, which is typically the name
of the source document element.
The XML document that uses this XSLT Style Sheet is shown in the slide titled “Viewing the
Transformed Document.”
XML Fundamentals 7 - 7
Using an XSLT Style Sheet
with an XML Document
An XML document uses an <?xml-stylesheet...?>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
processing instruction:
• After the XML declaration and before the root element of
the XML document
• Containing two pseudoattributes:
– The type value is the MIME type for the stylesheet.
– The href value is the URL of the source XSLT Style Sheet
s a
document. ) h a
s ฺrs ฺ
<?xml version="1.0"?>
@ em uide
<?xml-stylesheet type="text/xsl" href="emp.xsl"?>
o v ic t G
<employees> t o r den
. . . s
aj s Stu
a ฺ m hi
</employees>
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
An XSLT
n i n
tStyle Sheetn s is applied to an XML document by adding the xml-stylesheet
e r
al oninstruction
processing -t a in the XML document prologue that is before the document root
V n The xml-stylesheet processing instruction provides two pseudoattributes:
element.
• The type value is the Multipurpose Internet Mail Extensions (MIME) media type for the
type of stylesheet. For XSL stylesheets, the type value must be either
application/xml or text/xml. However, the XSL Processor in Internet Explorer
does not recognize application/xml as the type value, but accepts a value of
text/xsl as shown in the example in the slide. A MIME media type value of
text/css is applicable to a cascading style sheet (CSS).
• The href value is a URI string referencing the name of the stylesheet document.
The xml-stylesheet processing instruction is required for a browser to invoke its XSLT
Processor to apply the style sheet to the XML document tree.
Note: The type pseudoattribute value of text/xsl, which is a fabrication of Microsoft, is not
a formally registered MIME type. However, this course uses the text/xsl MIME type to
make it easier to observe the results of XSLT. The processing instruction is not required by
the Oracle command-line XSLT Processor. Therefore, the MIME type used is irrelevant to the
Oracle command-line XSLT Processor.
XML Fundamentals 7 - 8
Viewing the Transformed XML Document
1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
4 ) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G 3
a jsto Stude
5
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t provides sthe XML schema–aware XML editor, which you can use to create, check
l e n
JDeveloper
r a n
theasyntax
V of,-tand validate an XSL stylesheet document.
n
o
n an XSL stylesheet in JDeveloper:
To create
1. Right-click an existing project node and select New > From Gallery (or select File >
New > From Gallery from the menu).
2. In the New Gallery window, click XML under the General node in the Categories
section, and then double-click XSL Style Sheet in the Items section.
3. When the Create XSL File window is displayed, enter a file name in the File Name field
and click OK.
4. JDeveloper creates a skeleton XSL file containing:
- An XML declaration
- The <xsl:stylesheet> root element with its required XML namespace prefix
xsl and the URI http://www.w3.org/1999/XSL/Transform
- An empty <xsl:template> element with a rule matching the document root
5. Start editing the XSLT document by making use of the code-insight features of the XML
schema–aware XML editor. The screenshot shows code-insight providing a list of
suitable elements after entering the text <xsl: inside the <xsl:template> element.
XML Fundamentals 7 - 10
Lesson Agenda
XML Fundamentals 7 - 11
Creating Template Rules
A template rule:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 7 - 12
Obtaining Input Text with <xsl:value-of>
XML Fundamentals 7 - 13
Applying Template Rules
XML Fundamentals 7 - 14
The slide illustrates the same XML input document tree being processed by two different
XSLT Style Sheets:
1. In the first example, the resulting output document contains only the literal text,
Document root, which is contained in the template rule for the document root. In this
example, the <xsl:apply-templates/> element is not used; therefore, no other
nodes from the input document tree are processed. In addition, the template rule for the
document root overrides the built-in default template.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
2. In the second example, the output document contains data from each of the templates in
the XSLT Style Sheet. All templates are invoked because the <xsl:apply-
templates/> element is used in the templates for templates matching most of the
parent nodes in the tree. However, the child elements of node B (that is, C and D) are not
processed without including the </xsl:apply-templates/> in the template rule
for B.
The following sequence of events occurs in the second example in the slide:
1. XSLT Processor reads the XML input document starting with the document root node.
s a
h a
ฺrs) ฺ
2. It finds the template rule for the document root, with match="/", copies the template
s
data to the output tree, and writes the literal text “Document root” to the output tree
first.
@ em uide
v ic t G
3. It encounters the <xsl:apply-templates/> element inside the document root
o
template rule. t o r den
s
aj s Stu
ฺ m
4. It fetches the document root’s child element, root element A, from the XML input
a hi
document. t i n e t
a l en o us
5. It finds the matching template rule for node A, with match="A", and copies its template
i c (v se t
data to the output tree, appending the text “Root element A” to the result.
t o rov licen
6. The XSLT Processor encounters another <xsl:apply-templates/> element in the
a js ble
template rule for node A.
a M fera
i n s
7. The first child, element B, of parent node A is processed by the template rule, with
n t n
l e r a
match="B", appending the text “Element B” to the output results.
Va non-t
8. Because there is no more to process in the template rule for B, processing continues
with the next child node B of parent element A, appending another line of the text
“Element B” to the output results.
9. Because there are no more direct child elements of node A, the processing continues in
the context of the rule for element A, which has no more to process either.
10. Processing returns to the context of the template for the document root, the parent of
node A, which also has no more template data to be processed.
11. The result document tree is copied to the output destination, possibly the browser
display window, or a file containing the result data.
XML Fundamentals 7 - 15
Controlling Template Activation Order
XML Fundamentals 7 - 16
Template Rules and Priorities
c (
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
tStyle Sheet s usually has multiple template rules declared. As shown in the slide, the
An XSLT
e n r a n
V al pattern
match
o n -t for more than one template rule can be applicable to the same node. To deal
npotential conflict, an XSLT Processor assigns a default priority to each template rule,
with this
unless the author of the XSLT Style Sheet explicitly specifies a priority attribute in the
start tag of the <xsl:template> declaration. The default priority is:
• A -0.5 value if the match pattern is a simple node-test such as the element name
• A 0 value if the pattern uses a node name qualified by a namespace prefix, or the
processing-instruction() function (for example, dept:department)
• A 0.25 value for patterns that use a namespace prefix with a wildcard node-test (for
example, dept:*)
• A 0.5 value for all other patterns (for example, /departments, which uses an
absolute XPath pattern)
Note: If more than one template rule has a pattern that matches the same node, the rule with
the highest priority is applied. If multiple patterns share the highest priority, an error occurs or
the rule that appears last in their order of appearance is used. For example, the rule for the
department pattern that contains the text literal I WIN! in the slide is selected because it
appears last, even though it has the same priority as the previous one.
XML Fundamentals 7 - 17
Default Template Rules
XML Fundamentals 7 - 18
Effects of Default Template Rules
XML Fundamentals 7 - 19
Looping with <xsl:for-each>
XML Fundamentals 7 - 21
Attribute Value Templates
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t value s
l e n
The attribute
t r a ntemplate is a powerful technique to include node names (element and
a onames)
attribute - or their values in the attribute values of the XSLT elements in the stylesheet.
V n n
Using an attribute value template creates dynamic output results that are determined by the
information from the input document, such as attribute values for elements in the result
document, as shown in the example in the slide. You can use the <xsl:element> element
in the template to create output elements based on the element names from the input
document, as discussed in the section titled “Creating Elements with Attributes.”
The example in the slide shows three related documents:
• Part of an XML input document showing one <region> element and its children
• The XSLT Style Sheet with templates to transform the input document by converting the
child elements of the <region> element into attribute values in the output document.
The template rules hard-code the output element names for <regions> and
<region>. However, the template rules use the attribute value template technique to
obtain the text values of the <region_id> and <region_name> elements from the
input document. The text values are obtained from the input document to set the values
for their corresponding attributes id and name in the <region> element of the output
document.
• The resulting output document that contains the results after the transformation, with the
element text from the input document formatted as attribute values in the output
XML Fundamentals 7 - 22
Creating Elements with Attributes
<xsl:element name="region">Japan</xsl:element>
<region>Japan</region>
XML Fundamentals 7 - 23
Creating Elements with Attributes
<xsl:attribute-set name="region-info">
<xsl:attribute name="id">5</xsl:attribute>
<xsl:attribute name="name">Japan</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="region[1]">
s a
<xsl:element name="{local-name()}"
h a
ฺrs) ฺ
use-attribute-sets="region-info">
</xsl:element> s
</xsl:template> em ide
v i c@ t Gu
t o ro den
<region id="5">Japan</region> s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
t i n
3. An<region> n s
element with an id and a name attribute. This example uses an
l e - t r a
Va <xsl:attribute-set> element that declares the id and name attributes and their
non The template creating the output element derives the element name from the
values.
context node by using the local-name() XPath function, and generates the attributes
by referencing the region-info attribute in use-attribute-sets.
Note: The attribute set hard-codes its attribute names and values in the example. The design
can be made more flexible with the use of the <xsl:parameter> elements.
XML Fundamentals 7 - 24
Lesson Agenda
XML Fundamentals 7 - 25
Sorting an XML Document
evaluates to true.
• The test attribute is a Boolean expression.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
s a
<h2>Departments with a manager</h2>
) h a
<xsl:for-each select="//department">
<xsl:if test="manager_id"> r s
sฺ eฺ
<p><xsl:value-of select="."/></p> m
e uid
c @
</xsl:if>
r o vi nt G
jsto Stude
</xsl:for-each>
</xsl:template>
ฺm thisa
</xsl:stylesheet>
i n a
l e nt use
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t rules can sperform conditional processing by using the <xsl:if> or
Template
e n r a n
V al on-t elements. Both these elements provide a test that evaluates an XPath
<xsl:choose>
n as a Boolean result of true or false. The XPath expression is converted to a
expression
true or false value. If the XPath expression evaluates to:
• A numeric result of 0, it is converted to false; otherwise, it is considered true
• A string result with a length greater than 0, it is converted to true; otherwise, it is
false
• A node with a value, it is considered true; otherwise, an empty or nonexistent node is
false
The example in the slide creates an HTML paragraph for each <department> element
containing a <manager_id> child element with a value. Any <department> element
without a child or empty <manager_id> element is excluded.
Note: There are no <xsl:else> or <xsl:else-if> constructs in XSLT. To emulate an
“else” scenario, use the <xsl:choose> element, as discussed in the section titled
“Conditional Processing with <xsl:choose>.”
XML Fundamentals 7 - 27
Conditional Processing with <xsl:choose>
XML Fundamentals 7 - 28
Modes
than once
• Are applied by using the mode attribute in
<xsl:template> and <xsl:apply-templates>
• Are implemented by:
– Defining mode in <xsl:template>:
<xsl:template match="department" mode="toc"> ...
s a
h a
ฺrs) ฺ
<xsl:template match="department" mode="body"> ...
<xsl:template match="department "> ...
s
@ em uide
– Referencing mode in <xsl:apply-templates>:
o v ic t G
t o r den
<xsl:apply-templates s
aj s Stu
select="department" mode="toc"/>
a ฺ m hi
t i n e t
The first template is matched a and
l enprocessed.
o us
v
c ( nse t
v i
t o ro © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
s
aj rable
M
Modesn t ina aaway
provide n sftoe process the same input XML content more than once. This is
ale oby:
achieved
V n -tr
• n
Specifying the mode attribute in the <xsl:template> definitions
• Referencing the mode value of a template by using the mode attribute of the
<xsl:apply-templates> element
The mode attribute value is a string to describe the mode (such as toc for table of contents,
and body to represent the body of information) for transformation to the output tree.
After a mode attribute is defined in a template rule, you can specify mode in one or more
instances of <xsl:apply-templates>, which ensures that the XSLT Processor applies the
template by matching the specified mode value.
The example in the slide shows three incomplete template rules, with the first two specifying
their mode attribute values of toc and body, respectively. When the <xsl:apply-
templates> element example is encountered that matches the employee nodes, the
element targets the template defined with the mode value toc. In this case, only the first of
the template rules is applied because the node and mode name match the apply template
request.
XML Fundamentals 7 - 29
Example of Using Modes
. . .
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<xsl:template match="/departments">
<html>
<body>
<h1>Department Report</h1>
<ol><xsl:apply-templates
select="department" mode="toc"/></ol>
<xsl:apply-templates
select="department" mode="body"/>
</body>
</html>
</xsl:template>
s a
<xsl:template match="department" mode="toc">
) h a
<a href="#id_{department_id}">
r s
sฺ eฺ
<li><xsl:value-of select="department_name"/></li>
</a> m
e uid
c @
</xsl:template>
r o vi nt G
jsto Stude
<xsl:template match="department" mode="body">
<a name="#id_{department_id}">
ฺm thisa
<h2><xsl:value-of select="department_name"/></h2>
i n a
nt use
</a>...<xsl:apply-templates mode="body"/>...
</xsl:template>
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t example s the <xsl:apply-templates> element to specify a mode for the
e n
The slide
r a nuses
al otonbe-t applied, and specifies a mode name in the target <xsl:template> elements.
template
V n uses an XML input document of department data to generate a web report.
The example
To process an XSLT Style Sheet:
1. The template rule matching the root element /departments generates the HTML
document structure with the report header Department Report, and generates an
ordered list of department names by requesting <xsl:apply-templates> using the
mode value toc.
2. <xsl:template> with the mode toc is invoked to generate an HTML list of elements.
This list contains the department name as a hypertext link referencing an anchor that is
named with the literal text #id_ prefixed with the department_id node text.
3. The root element template rule processes another <xsl:apply-templates>
element. This time, it does so by using the mode value of body.
4. The template rule with mode="body" generates the body of the report, which is
composed of HTML anchor tags (hyperlinks). The department name is formatted as an
HTML header in the anchor text. The name attribute of each anchor tag is set to the
same value that is generated for the hypertext link (href attribute) created by the
template with mode="toc".
5. The template with a body mode applies its child templates with the mode of body.
Note: The hypertext link and anchor values are formed by using an attribute value template.
XML Fundamentals 7 - 30
Example of Using Modes
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<ol>
<xsl:apply-templates
select="department"
mode="toc"/></ol>
s a
) h a
<xsl:apply-templates
r s
sฺ eฺ
select="department" m
e uid
c @
mode="body"/>
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t showsathe ssample HTML results for the XSLT Style Sheet shown in the previous
n
The slide
e r n
V al Theostylesheet
slide. n -t shows the <xsl:apply-templates> elements with their
n
corresponding output. A snippet of the department XML document is:
<?xml version='1.0' encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="code_07_32_n.xsl"?>
<departments>
<department num="1">
<department_id>10</department_id>
<department_name>Administration</department_name>
<manager_id>200</manager_id>
<location_id>1700</location_id>
</department>
<department num="2">
<department_id>20</department_id>
<department_name>Marketing</department_name>
<manager_id>201</manager_id>
<location_id>1800</location_id>
</department>
...
</departments>
XML Fundamentals 7 - 31
The preceding report is generated by using the following XSLT Style Sheet:
<?xml version='1.0' encoding='windows-1252'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/departments">
<html>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<body>
<h1>Department Report</h1>
<ol>
<xsl:apply-templates
select="department[position()<5]"
mode="toc"/>
</ol>
s a
<xsl:apply-templates
h a
select="department[position()<5]"
s ฺrs) ฺ
mode="body"/>
@ em uide
</body>
o v ic t G
</html>
t o r den
</xsl:template> s
aj s Stu
a ฺ m hi
t i
<xsl:template match="department" mode="toc">n e t
<a href="#id_{department_id}"> a l en o us
i c (v se t
<li><xsl:value-of select="department_name"/></li>
</a> t o rov licen
a js ble
M fera
</xsl:template>
a
t i n n s
<xsl:template match="department" mode="body">
n
l e r a
Va non-t
<a name="#id_{department_id}">
<h2><xsl:value-of select="department_name"/></h2>
</a>
<table border="1">
<tr><xsl:apply-templates mode="body"/></tr>
<tr><xsl:apply-templates/></tr>
</table>
</xsl:template>
<xsl:template match="department/*" mode="body">
<th><xsl:value-of select="local-name()"/></th>
</xsl:template>
<xsl:template match="department/*">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>
XML Fundamentals 7 - 32
Calling Templates by Name
...
<xsl:template name="deptlist">
<!-- instructions to process -->
</xsl:template>
...
XML Fundamentals 7 - 34
Creating and Using Parameters
<xsl:template name="deptlist">
<xsl:param name="loc_id"/>
<xsl:for-each
select="//department[location_id=$loc_id]">
<a href="#id_{department_id}><li><xsl:value-of
select="department_name"/></li></a>
</xsl:for-each>
</xsl:template>
s a
• Pass parameters with <xsl:with-param> in an
) h a
sฺrs
<xsl:apply-templates> or <xsl:call-template>:
m ideฺ
e
<xsl:template match="/departments">
v i c@ t Gu
<ol><xsl:call-template name="deptlist">
t o ro den
<xsl:with-param name="loc_id" s
aj s Stu
select="department[1]/location_id"/>
a ฺ m hi
</xsl:call-template></ol>
t i n e t
</xsl:template>
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
Definingn t i n
parameters n sis similar to creating arguments for methods or procedures in a modular
e
al on-language.
programming t r a
V
The firstnexample in the slide defines the template named deptlist with one parameter called
loc_id. The parameter value is used by prefixing its name with a dollar sign ($) in the template
body. The example uses $loc_id to filter the department node-set identified by the <xsl:for-
each> element to departments with a specified location_id.
The second example uses <xsl:with-param> to specify the name parameter and its value
determined by the select attribute when calling the deptlist template that uses the
<xsl:call-template> element.
Guidelines
• The <xsl:param> element must be the first item in a template, and you can define one or
more parameters.
• Prefix parameter names with a dollar sign ($) to use the parameter values in the template.
• Provide default parameter values by using either the template body (between the start and
end <xsl:param> tags), or by using the select attribute.
• Provide parameter values with <xsl:with-param> either in the template body or by using
the select attribute.
Note: The <xsl:param> and <xsl:with-param> elements define their value by using either
the select attribute or their template bodies, but not both at the same time.
XML Fundamentals 7 - 35
Lesson Agenda
XML Fundamentals 7 - 36
Performing the XSLT Process in JDeveloper
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
1 2
3 s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this 4
5 i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s process in JDeveloper and view the transformed document. The slide
trun theaXSLT
You can
e n r n
al ouses
example
V n -tcode_07_37_s.xsl. The code_07_37_s_input.xml XML document is
n into a code_07_37_s_output.html file.
transformed
To run the XSLT process in JDeveloper:
1. Right-click the XSL file and select Run from the context menu.
2. In the XSLT Settings window, specify the following:
- File name and location of the XML file to use as the source document (input XML
file) in the transformation process
- File name and location of the file (output file) where the results tree will be entered
- (Optional) The XSLT source path and XSLT options (if any)
Then click OK.
3. When the running of the project is completed, you will see a message in the Log
window. The output file, code_07_37_s_output.html file, is displayed in the
Applications pane.
4. View the output file by using your web browser.
Notes
• Make sure that the project is active to start the target XSL file.
• Browse to the location of the output file, and then double-click the output file name to
view the HTML file in your web browser as seen in the slide.
XML Fundamentals 7 - 37
Using the oraxsl Utility
XML Fundamentals 7 - 38
The oraxsl utility can process multiple XML documents and accept the following command-
line options that dictate how it must behave:
• -d directory, which specifies a directory with files to be transformed. (The default
behavior is to process all files in the directory.) If only a certain subset of the files in that
directory (for example, one file) needs to be processed, this behavior must be changed
by using -l and by specifying only those files that need to be processed. You can also
change the behavior by using the -x or -i option to select files based on their
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
extension.
• -debug, which enables the debug mode. By default, the debug mode is turned off.
• -e error_log, which specifies a file into which errors and warnings are written
• -h, which prints the oraxsl invocation syntax and options
• -i source_extension, which specifies the file extensions to include (used in
conjunction with –d)
• -l xml_file_list, which specifies a list of files to be transformed
s a
a
• -o result_directory, which defines a location to place the result files. This must
h
be used with the -r option.
s ฺrs) ฺ
• -p param_list, which specifies a list of parameters
@ em uide
o v ic t G
• -r result_extension, which specifies the extensions to be used for result files. If -d
t o r den
or -l is specified, the option of –r must be specified. For example, if the extension is
s
aj s Stu
specified as out and an input document is foo, the result file is called foo.out. By
a ฺ m hi
default, results are placed in the current directory.
t i n e t
a l en o us
• -s stylesheet, which specifies the stylesheet file to use. This must be used if the -d
or -l
l option is specified
specified.
i c (v se t
t o rov licen
• -t num_of_threads, which controls the number of threads to use for processing the
js ble
transformations. Using multiple threads can provide performance improvements when
a
M fera
processing multiple documents.
a
t i n n s
• -v, which enables a verbose mode that displays some debugging information that could
n
l e r a
Va non-t
help in tracing any problems encountered
• -w, which causes warnings to be displayed. By default, warnings are turned off.
• -x source_extension, which defines files with extensions to be excluded (used in
conjunction with the -d option)
XML Fundamentals 7 - 39
XSLT 2.0
XSLT 2.0:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
• Is a W3C recommendation
• Uses the XPath 2.0 and XQuery 1.0 data model
• Supports XML Schema data types
• Provides features such as the following:
– Grouping data
– Generating multiple outputs s a
) h a
– Temporary tree r s
sฺ eฺ
– Character mapping m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t uses the s data model as XPath 2.0 and XQuery. XSLT 2.0 uses XPath 2.0 to
e n
XSLT 2.0
r a nsame
al andonprocess
locate
V -t content within an XML document’s logical hierarchy.
To usenXSLT 2.0, set the version attribute in your stylesheet as follows:
<? xml-stylesheet version="2.0" ... ?>
XSLT 2.0 has new elements that help with grouping tasks, which are difficult to perform in
XSLT 1.0. XSLT 2.0 allows multiple documents to be output.
By using XSLT 2.0, you can transform textual data that is not well-formed XML.
XSLT 2.0 allows you to define custom functions. XSLT 2.0 includes the xsl:function
element. xsl:function declares the name, parameters, and implementation of a user-
defined function that is used within XPath expressions in a given style sheet.
Note: Some elements, such as xsl_value-of, produce different results in XSLT 2.0.
Therefore, you must specify the version of the transformation.
For more information about XSLT 2.0 features and examples, see the appendix titled
“Additional Information About Document Type Definitions, XML Schemas, and XSLT 2.0.”
XML Fundamentals 7 - 40
Quiz
XML Fundamentals 7 - 41
Summary
XML Fundamentals 7 - 42
Practice 7: Overview
XML Fundamentals 7 - 43
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Objectives
XML Fundamentals 8 - 2
Lesson Agenda
• XQuery
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
– Introduction
– Applications and features
– Terminology
– Data model
– Syntax rules
• XQuery support in JDeveloper s a
h a
• XQuery expressions
s ฺrs) ฺ
• XQuery functions and operators
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 8 - 3
XQuery: Review
XML Fundamentals 8 - 4
XQuery Terminology
• Nodes
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
<?xml version="1.0" encoding="UTF-8"?>
h a
ฺrs) ฺ
<!-- Employees data -->
<emp:employees xmlns:emp="urn:hr:employee-ns">
s
<employee employee_id="100">
<name>
@ em uide
<first_name>Steven</first_name>
o v ic t G
<last_name>King</last_name>
t o r den
</name>
<salary>24000</salary> s
aj s Stu
</employee>
a ฺ m hi
. . .
t i n e t
en o us
</employees>
a l
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 8 - 5
What Is XQuery?
s a
) h a
r s
sฺ eฺ
m
e uid
c @
XQuery result ro NeweXML
vi nt data G
A simple XQuery:
a jsto Stud
n a ฺm this
doc("code_08_dept.xml")/departments/department[department_name
i
nt use
='Purchasing']
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t an XML s language developed by the World Wide Web Consortium (W3C) and
XQuerynis
e r a nquery
alon other
built
V o n t standards such as XML, namespaces, XSLT, XPath, and XML Schema.
-W3C
n
XQuery 1.0 is a W3C recommendation.
XQuery is designed to query XML data from both XML files and relational databases. Just as
SQL is the query language for structured data that is expressed as relational tables, XQuery
is designed to work with the XML data model and be a comprehensive query language for
data that is expressed in XML. You can use a single XQuery on multiple and heterogeneous
data sources to transform the query result into new XML data.
XQuery consists of a set of possible expressions that are evaluated and return values (which,
for XQuery, are sequences).
Example: The slide displays a simple XQuery that selects all department nodes from the
code_08_dept.xml document, where department_name equals Purchasing. The
doc() function is used to specify the XML document that you want to query.
XML Fundamentals 8 - 6
Applications of XQuery
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
XML generation
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
tXQueryatonsquery, generate, and transform XML content.
You use
l e n tr
V•a XML n -
Querying: XML can map a large number of different data models. XQuery thus
no a mechanism for extracting information from relational databases, files, and
provides
web services simultaneously. The key feature of XQuery as a query language is its
conciseness and simplicity when compared to other querying approaches (such as
XSLT and DOM-based approaches).
• XML generation: XQuery enables you to construct XML data by using the result of a
query.
• XML transformation: XQuery can construct XML as a result of evaluating a query
expression, in many cases more expressively and efficiently than XSL Transformations
(XSLT). XQuery enables you to scan a hierarchy of elements. You can use it to apply
transformations at each level of the hierarchy by defining a recursive function.
XML Fundamentals 8 - 7
Features of XQuery
data
– Relational databases
– XML documents
– Other data sources with XML data view
• Is protocol independent
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s structured and unstructured types of data. It can be seamlessly merged
XQuerynhandles
e r a n
both
alSQLorelational
with
V n -t queries to handle all query scenarios. XML data can be generated using
XQuerynresults. XQuery is protocol independent. As a result, queries are evaluated on any
type of system with predictable results.
Notes
• XSLT uses XML syntax, whereas XQuery uses non-XML syntax. You can use both
XQuery and XSLT to add nodes, and both of them require XPath to select nodes to
process. XSLT 2.0 and XQuery 1.0 are based on the same foundation XPath 2.0.
• You learned about the XMLType data type in the lesson titled “Introduction to Oracle
XML DB.” XML data can be stored in Oracle Database using the XMLType data type.
XQuery provides support for XMLType. A single XQuery can join multiple data sources
and obtain the result from the query in XMLType.
XML Fundamentals 8 - 8
XQuery Terminology
• Node
• Atomic value
• Item
• Relationship of nodes
• Expression
• Sequence s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t treats sXML documents as trees of nodes. The root node is also known as the
l e n
• XQuery
r a n
Va document
o n -t node. The seven kinds of nodes are listed in the section titled “XQuery Data
n
Model.”
• An atomic value is an instance of one of the built-in data types defined by XML Schema
such as integers, strings, dates, and decimals. An atomic value cannot have parent or
children nodes.
• An item may be a node or an atomic value.
• A relationship in a document between nodes can be seen through the parent, the
children, the siblings, the ancestors, and the descendants.
• XQuery is a functional language, which is made up of expressions that can be nested
and return values. An expression is the basic building block of XQuery.
• Sequences are ordered collections of zero or more items. Every value in XQuery is a
sequence. An XQuery sequence can contain items of any XQuery type, which includes
numbers, strings, Boolean values, dates, as well as various types of XML node.
XML Fundamentals 8 - 9
XQuery Data Model
4. Serialization
1. Parsing
s a
Parser Query data model
) h a
Infoset r
sฺ eฺs
m
e uid
c @
r o vi nt G
2. Validation
a jsto Stude 3. Mapping
n a ฺm this
Schema i
nt Post-Schema s e Validation
a l e o u
( v t Infoset (PSVI)
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
Beforen ina can
a tquery n s
be
feprocessed, the XQuery compilation engine converts an XML document
V
e
to aldata model
n - trainstance as follows:
no the XML document by using the XML Parser, which generates an XML
1. Parses
Information Set (Infoset)
2. Validates the parsed document against one or more schemas, and creates the
information structure called the Post-Schema-Validation Infoset (PSVI)
3. Transforms the PSVI into a data model instance
4. Transforms the query result into an XML representation from the query data model, in a
data model called serialization
XQuery is defined in terms of the data model, but it does not place any constraints on how the
data model instances are constructed.
XML Fundamentals 8 - 11
XQuery Syntax Rules
• XQuery is case-sensitive.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 8 - 12
Lesson Agenda
– Introduction
– Applications and features
– Terminology
– Data model
– Syntax rules
• XQuery support in JDeveloper s a
h a
• XQuery expressions
s ฺrs) ฺ
• XQuery functions and operators
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 8 - 13
XQuery Support in JDeveloper
1 2
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
5
3
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use 4
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t provides san XQuery editor and an execution environment. JDeveloper supports
e n
JDeveloper
r a n
V al XQuery
creating
o n -t files, syntax highlighting of XQuery syntax in the code editor, and executing
XQuerynfrom within the IDE. The slide illustrates the steps to create an XQuery file and to run
the XQuery expression against an XML document in JDeveloper.
1. Select New > XQuery File (if you already created an XQuery file previously).
2. In the Create XQuery File window, enter the file name in the File Name field, and then
click OK.
3. JDeveloper creates an XQuery file. Enter your XQuery expression and save the file.
4. Right-click the XQuery file and select Run from the context menu.
5. View the XQuery results in the Log window.
In the slide example, the XQuery expression selects the department names for all department
nodes from the code_08_dept.xml document.
You can modify the XQuery expression to select all department nodes from the
code_08_dept.xml document, where department_name equals “Purchasing.” as
follows:
doc("code_08_dept.xml")/departments/department[department_name="Purc
hasing"]
XML Fundamentals 8 - 14
Lesson Agenda
– Introduction
– Applications and features
– Terminology
– Data model
– Syntax rules
• XQuery support in JDeveloper s a
h a
• XQuery expressions
s ฺrs) ฺ
• XQuery functions and operators
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 8 - 15
XQuery Expressions
• Primary
• Sequence
• FLWOR
• Path
• Arithmetic
• Logical s a
h a
• Conditional s ฺrs) ฺ
• Quantified @ em uide
ic G
t o rov dent
a js Stu
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t areathe sbasic building blocks of XQuery. They are case-sensitive.
l e n
Expressions
r n
V•a Primary
o n -texpression: Includes literals, variable references, context item expressions,
n
constructors, and function calls
- A literal is an atomic (scalar) value. XQuery supports two types of literals: numeric
and string.
- A variable name starts with a dollar sign ($) (for example, $num).
• Sequence expression: Can be constructed by using the comma operator; may contain
a series of atomic values or nodes
• FLWOR expression: Can be used to query XML data and is considered similar to the
SELECT-FROM-WHERE statements in SQL
• Path expression: Is used to locate nodes in trees by using XPath
• Arithmetic expression: Is used to write expressions with arithmetic operators
• Logical expression: Can be written by using logical operators
• Conditional expression: Also supports IF-THEN-ELSE
• Quantified expression: Generates a Boolean based on a sequence’s content
XML Fundamentals 8 - 16
Primary Expressions: Variables
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
tuse variabless for the following purposes:
You can
l e n r a n
V•a Temporary
o n -t storage of data: Data can be stored temporarily in one or more variables
nvalidating data input and for later processing.
for
• Manipulation of stored values: Variables can be used for calculations and other data
manipulations without accessing the database.
• Reusability: After they are declared, variables can be used repeatedly in other
statements.
A variable name starts with a dollar sign ($), as in the example: $num.
XML Fundamentals 8 - 17
Primary Expressions: Literals
• String literal
– $cname := "SCOTT"
• Numeric literal
– $ItemCode := 3568
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t an explicit snumeric, character, string, or Boolean value that is not represented by
A literalnis
l e r a n
t are two types of literals:
anaidentifier.
V o n -There
n literals: Characters, numerals, spaces, and special symbols that must be
• String
enclosed in quotation marks, as in the following examples:
“I”, “Hello”, “what’s up”
• Numeric literals: Integers, decimals, and exponents, as in the following examples:
30568, 30568.5, 30568.5E-2
XML Fundamentals 8 - 18
Primary Expressions: Constructors
• Direct constructor
• Computed constructor
– Computed element constructor
– Computed attribute constructor
– All document node constructors
– All text node constructors s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
tcreate a sstructures in a query by using constructors. These are provided for
You can
e n r n
XML
al oattribute,
element,
V n -t document, text, comment, and processing instruction nodes. There are two
types ofnconstructors:
• Direct constructor: The name of the constructed element is a constant. The
constructor creates an element node. For example, the XQuery expression <a>33</a>
constructs the XML element <a>33</a>.
• Computed constructor: This can also be used to create nodes. A computed
constructor begins with a keyword that identifies the type of node to be created:
element, attribute, document, text, processing instruction, or comment.
- A computed element constructor creates an element node, allowing both the
name and the content of the node to be computed.
- A computed attribute constructor creates a new attribute node with its own
node identity.
- All document node constructors are computed constructors. The result of a
document node constructor is a new document node with its own node identity.
- All text node constructors are computed constructors. The result of a text node
constructor is a new text node with its own node identity.
XML Fundamentals 8 - 19
The following example shows the use of computed element and attribute constructors in a
simple case in which the names of the constructed nodes are constants.
element book {
attribute isbn {"isbn-0060229357" },
element title { "Harold and the Purple Crayon"},
element author {
element first { "Crockett" },
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 8 - 20
Sequence Expressions
XML Fundamentals 8 - 21
FLWOR Expressions
XML Fundamentals 8 - 22
FLWOR Expression Clauses
Clause Description
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
for Iterates across a range of sequence values and binds one or more
variables to each of any number of values. This is similar to the FROM
clause of a SQL SELECT query.
let Defines variables and assigns them, in turn, during iteration through a
for clause. This is analogous to the SQL SET statement.
where Filters the for and let variable bindings according to some condition.
This is similar to a SQL WHERE clause.
s a
order by Arranges the result (returned by the WHERE clause) in ascending or
h a
descending order
s ฺ rs)
return Constructs a result from the ordered, filtered values. Thism
e e
is the result
d ฺ
of the FLWOR expression as a whole, which can be@
c compared i
uto a
v i t G
SELECT statement. It is a flattened sequence.
t o ro den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
t i n
The components
n n
of sa FLWOR expression are as follows:
l e r a
-t for clause enables you to iterate across a range of sequence values and
V•a for: o n
The
n one or more variables to each of any number of values.
bind
Example:
for $i in (1,2,3,4)
return <project>{$i} </project>
The output of this example is:
<project>1</project><project>2</project><project>3</project><pr
oject>4</project>
Note: There can be multiple for clauses in the same FLWOR expression.
• let: You can define variables and assign values to them by using let in a for clause.
Example:
let $s := (<a/>, <b/>, <c/>)
return <out>{$s}</out>
The output of this example is:
<out><a/><b/><c/></out>
XML Fundamentals 8 - 23
• where: You can provide a condition, which works like a SQL WHERE clause:
where $i/price < 45
• order by: You can sort the result of the where filtering:
order by $i/department_name
• return: This gives you the final result after ordering and filtering of values:
return $i/department_name
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Note that using a FLWOR expression (with order by) is the only way to construct a sequence
in any order other than document order.
Note: In XQuery, nodes that are created when parsing an XML document are in an order
known as document order.
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 8 - 24
departments.xml Document: Example
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 8 - 25
Using FLWOR Expressions
for $i in doc("code_08_dept.xml")//department
let $j := 20
where $i/department_id>$j
order by $i/department_name s a
return $i/department_name/text() ) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
Human Resources
a jsto Stude
Purchasing
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t in athensslide displays a FLWOR expression to extract department names that have
The example
e n
l than tr
V aless
IDs n -20.
no of the FLWOR expression clauses:
Explanation
• The FOR clause assigns all department elements in code_08_dept.xml to a variable
named $i.
• With the LET clause, $j is assigned the value 20.
• The WHERE clause is used to filter $i so that it retains only those departments that have
department_id values less than $j.
• The text value of the resultant department is returned by using the RETURN clause.
• The ORDER BY clause causes the output to be displayed in ascending order of
department_name.
XML Fundamentals 8 - 26
Path Expressions
XML Fundamentals 8 - 27
• A node test specifying the node type of the selected nodes. The node type that is
specified as the node test for a location step can be:
- A node-name representing either a qualified or an unqualified element name. If it
is prefixed with an @ symbol, node-name represents an attribute name.
- An asterisk (*) to match all element or attribute node names
- The text() type to select text nodes
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 8 - 28
Using Path Expressions to Filter
XML Data: Example
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
for $i in doc("code_08_dept.xml")//department
where $i/department_name = "Administration"
return $i
<department num="1"> s a
h a
ฺrs) ฺ
<department_id>10</department_id>
s
<department_name>Administration</department_name>
</department> em de @ Gui
i c
t o rov dent
a js Stu
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t in athensslide shows the use of a path expression in XQuery. The FLWOR
The example
e n
expression
V -tr descendant <department> elements that contain a
al onreturns
n
<department_name> element whose text node is Administration.
XML Fundamentals 8 - 29
Using Conditional Expressions
if test_expr
then expr1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
else expr2
for $i in doc("code_08_dept.xml")//department
where $i/department_id < 30
return <Result>
<department_id> {$i/department_id/text()}
</department_id>
<department> { if ($i/@num = 1)
then "Applicable"
else "NA" }
s a
</department>
</Result> ) h a
s r
ฺ ฺs
<Result> m
e uide
c @
vi nt G
<department_id>10</department_id>
<department>Applicable</department>
r o
</Result>
<Result> a jsto Stude
<department_id>20</department_id>
n a ฺm this
<department>NA</department> i
nt use
</Result> l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i n
XQuerynsupports
a s
anconditional expression based on the keywords if, then, and else. Each
l e - t r
a of theonexpression
part
a is itself an arbitrary expression. For instance, in the following
V n
conditional expression, each of the subexpressions can be any XQuery expression:
if ($po1/price < $po2/price)
then $po1
else $po2
In a conditional expression, condition_expr should evaluate to a Boolean value or to a
type that can be cast to Boolean. If the Boolean value is true, the result of the entire
conditional expression is the same as the result of evaluating expr1; otherwise, it is the same
as the result of evaluating expr2.
The output for the query example in the slide is shown in the slide.
XML Fundamentals 8 - 30
Quantified Expressions
– Universal: every
– Existential: some
• The value of a quantified expression is always true or
false.
• Quantified expressions are shortcuts for using FLWOR
expressions. a
h a s
r s )
m sฺ eฺ
@ e uid
c
vi nt G
r o
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t expression s that uses some evaluates to true if at least one of the test expressions
A quantified
e n r a n
V althe Boolean
has
o n -t value true. When using every, the quantified expression is true only if
n
every evaluation of the test expression evaluates to true.
XML Fundamentals 8 - 31
Using Quantified Expressions
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
every $i in
doc("code_08_dept.xml")//department/department_id 1
satisfies $i< 40
--------
false
s a
) h a
some $i in r s
sฺ eฺ
doc("code_08_dept.xml")//department/department_ide m
i c @ Gu2id
rov dent
satisfies $i < 20
t
js Stu o
ฺm thisa
--------
i n a
true
l e nt use
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t 1ainnthe
1. Example s slide shows the use of the universal quantifier every. The department
e n r
l inncode_08_dept.xml
Va IDs o -t are 10, 20, 30, and 40; that is, not all values of
n
department id are less than 40. The output is therefore false.
2. Example 2 shows the use of the existential quantifier some. The query returns true if
there exists at least a single matching pair. Because there is at least one department
with department_id less than 20, the output is true.
XML Fundamentals 8 - 32
Lesson Agenda
– Introduction
– Applications and features
– Terminology
– Data model
– Syntax rules
• XQuery support in JDeveloper s a
h a
• XQuery expressions
s ฺrs) ฺ
• XQuery functions and operators
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 8 - 33
XQuery Functions
• Constructor functions
• Functions on numeric values such as fn:abs(),
fn:ceiling(), fn:floor(), and fn:round()
• Functions on string values such as fn:concat(),
fn:substring(), fn:lower-case(), and fn:upper-
case()
s a
• Aggregate functions such as fn:count(), fn:avg(), h a
s ฺ rs)
fn:max(), fn:min(), and fn:sum() em eฺ
i c @ Guid
t o rov dent
a js Stu
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s functions for string values, numeric values, sequence manipulation,
XQuerynincludes
e r a n
built-in
al ovalues,
Boolean
V n -t and so on.
n
Constructor functions
Every built-in atomic type has an associated constructor function.
xs:string($arg as xs:anyAtomicType?) as xs:string
xs:boolean($arg as xs:anyAtomicType?) as xs:boolean
Functions on Numeric Values
• fn:abs(): Returns the absolute value of the argument
• fn:abs(10.5) returns 10.5.
XML Fundamentals 8 - 34
• fn:round(): Rounds to the nearest number with no fractional part
fn:round(2.5) returns 3.
fn:round(2.4999) returns 2.
Functions on String Values
• fn:concat(): Accepts two or more arguments and casts them to xs:string, and
then returns the xs:string that is the concatenation of the values of its arguments
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
after conversion
let $v1 := "I plan to go to New"
let $v2 := "Delhi in September"
return concat($v1, $v2)
Output
"I plan to go to NewDelhi in September"
• fn:substring(): Accepts a source string and returns a substring located at a a
specified position
h a s
fn:substring("motor car", 6) returns "car".
s ฺrs) ฺ
em areuiselected.
Characters starting at position 6 of the literal to the end of the source string
@ de
fn:substring("metadata", 4, 3) returns "ada". c
vi nt G
r o
Characters at positions greater than or equal to 4 and less
a jstothan t deselected.
7uare
Aggregate Functions a ฺ m his S
fn:count(): Returns the number oftitems in
n t
in sea sequence
•
l e u
Assume $seq1 = (98.5, 98 3(va98.9).
98 9) to
(98 5 98.3,
o v ic nse
fn:count($seq1) returns
s t o r 3 .
l i ce
fn:count($seq1[.
M aj >ra100])ble returns 0.
•
n t ina anReturns
fn:avg(): sfe the average of a sequence of values
le $seq2r = (3, 4, 5).
Va non-t
Assume
fn:avg($seq2) returns 4.
• fn:max(): Returns the maximum value from a sequence of comparable values
fn:max((3,4,5)) returns 5.
fn:max((5, 5.0e0)) returns 5.0e0.
• fn:min(): Returns the minimum value from a sequence of comparable values
fn:min((3,4,5)) returns 3.
fn:min((5, 5.0e0)) returns 5.0e0.
• fn:sum(): Returns the sum of a sequence of values
Assume $seq3 = (3, 4, 5).
fn:sum($seq3) returns 12.
Note: The default prefix for the function namespace is fn:. You can call these built-in
functions without specifically declaring the namespace prefix.
XML Fundamentals 8 - 35
XQuery Operators
• op:numeric-add()
• op:numeric-subtract
• op:numeric-multiply()
• op:numeric-divide()
• op:numeric-mod()
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t on Numeric s Values
l e n
Operators
r a n
o n -t
V•a op:numeric-add(): Backs up the + operator and returns the arithmetic sum of its
n
operands: ($arg1 + $arg2)
op:numeric-add($arg1 as numeric, $arg2 as numeric) as numeric
• Op:numeric-subtract: Backs up the – operator and returns the arithmetic difference
of its operands: ($arg1 - $arg2)
op:numeric-subtract($arg1 as numeric, $arg2 as numeric) as numeric
• op:numeric-multiply(): Backs up the * operator and returns the arithmetic product
of its operands: ($arg1 * $arg2)
op:numeric-multiply($arg1 as numeric, $arg2 as numeric) as numeric
• op:numeric-divide(): Backs up the div operator and returns the arithmetic
quotient of its operands
op:numeric-divide($arg1 as numeric, $arg2 as numeric) as numeric
• op:numeric-mod(): Backs up the mod operator; returns the remainder resulting from
dividing $arg1 (the dividend) by $arg2 (the divisor)
op:numeric-mod($arg1 as numeric, $arg2 as numeric) as numeric
XML Fundamentals 8 - 36
XQuery Comparison and Boolean Operators
– op:numeric-equal()
– op:numeric-less-than()
– op:numeric-greater-than()
• Operators on Boolean values:
– op:boolean-equal()
– op:boolean-less-than() a
h a s
– op:boolean-greater-than() s )
r
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t Operators s on Numeric Values
l e n
Comparison
r a n
o n -t
V•a op:numeric-equal(): Returns true only if the value of $arg1 is equal to the value
n
of $arg2
op:numeric-equal($arg1 as numeric, $arg2 as numeric) as xs:boolean
• op:numeric-less-than(): Returns true only if $arg1 is less than $arg2
op:numeric-less-than ($arg1 as numeric, $arg2 as numeric) as
xs:boolean
• op:numeric-greater-than(): Returns true only if $arg1 is greater than $arg2
op:numeric-greater-than($arg1 as numeric, $arg2 as numeric) as
xs:boolean
Operators on Boolean Values
• op:boolean-equal(): Returns true if both arguments are true or if both
arguments are false
op:boolean-equal($value1 as xs:boolean, $value2 as xs:boolean) as
xs:boolean
XML Fundamentals 8 - 37
• op:boolean-less-than(): Returns true if $arg1 is false and $arg2 is true;
otherwise returns false
op:boolean-less-than($value1 as xs:boolean, $value2 as xs:boolean)
as xs:boolean
• op:boolean-greater-than(): Returns true if $arg1 is true and $arg2 is false;
otherwise returns false
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 8 - 38
Useful Websites About XML
Topic Website
W3C XML Schema http://www.w3.org/XML/Schema
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 8 - 39
Useful W3C Websites About XQuery
• http://www.w3.org/TR/xpath-datamodel/
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
• http://www.w3.org/TR/xpath-functions/#comp.numeric
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 8 - 40
Quiz
XML Fundamentals 8 - 41
Summary
XML Fundamentals 8 - 42
Practice 8: Overview
XML Fundamentals 8 - 43
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Objectives
XML Fundamentals 9 - 2
Lesson Agenda
• Oracle XML DB
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 9 - 3
What Is Oracle XML DB?
XML Fundamentals 9 - 5
Oracle XML DB
XML Services:
• XML Schema Registration
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
• Create Tables
Oracle Database • Insert, Delete, and Update XMLType tables
• Index XML
Oracle XML DB • Query XML
• Validate XML
XMLType • Transform XML
Tables, Retrieve / Generate XML Using XMLType APIs
Columns,
• SQL, Java, PL/SQL, C, and C++
and Views
s a
) h a
XML Services: r s
sฺ eฺ
Oracle m
XML DB
• Foldering
@ e uid
• Versioning
i c G
• ACL Security rov t
Repository
n
e XMLType APIs
sto SXML
Retrieve / jGenerate
a t udUsing
ฺmJava,thand
• SQL,
n a is PL/SQL
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t DB aisnasset of Oracle Database technologies that are related to high-performance
OraclenXML
e
al oofnXML
handling -tr data: storing, generating, accessing, searching, validating, transforming,
V n and indexing. It provides native XML support by encompassing both the SQL and
evolving,
XML data models in an interoperable way. Oracle XML DB is included as part of Oracle
Database. You learn about the key features that enable you to perform these operations in
the pages that follow.
Oracle XML DB Key Components
• XMLType storage: XML data, including XML Schema definition files, can be stored in the
XMLType columns and tables.
• Oracle XML DB Repository: This enables you to organize and manage database
content in the form of files and folders, which are called resources. Oracle XML DB
implements popular protocols such as FTP, HTTP, and Web-based Distributed
Authoring and Versioning (WebDAV) to improve data access performance, and is
designed around open standards and implemented to provide different views and
intuitive access to a single repository. The Oracle XML DB Repository can be accessed
by using Internet protocols such as WebDAV, FTP, and HTTP, and is as fast as
accessing data from any file system.
XML Fundamentals 9 - 6
Oracle XML DB: Benefits
XML Fundamentals 9 - 7
Oracle Database has the following key database capabilities for working with XML:
• Indexing and search: Applications use queries such as “find all product definitions
created between March and April 2002,” a query that is typically supported by a B-tree
index on a date column. Oracle XML DB can enable efficient structured searches on
XML data, saving content-management vendors the need to build proprietary query
APIs to handle such queries.
• Updates and transaction processing: Fast updates of subparts of records are
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
possible, with minimal contention between the users who are trying to update. File or
CLOB storage cannot provide the granular concurrency control that Oracle XML DB
does.
• Managing relationships: Data with any structure typically has foreign key constraints.
XML data stores generally lack this feature, so you must implement any constraints in
application code. With Oracle XML DB, you can constrain XML data according to XML
schema definitions, and therefore achieve control over relationships that structured data
has always enjoyed.
s a
h a
• Multiple views of data: Most enterprise applications need to group data together in
)
r s
sฺ eฺ
different ways for different modules. This is why relational views are necessary: to allow
m
e uid
for these multiple ways to combine data. By allowing views on XML, Oracle XML DB
c @
types of applications). r o vi nt G
creates different logical abstractions on XML (for example, for consumption by different
a jsto Stude
• Performance and scalability: Users expect data storage, retrieval, and query to be
a ฺm this
fast. Loading a file or CLOB value, and parsing, are typically slower than relational data
n
i
nt use
access. Oracle XML DB dramatically speeds up XML storage and retrieval.
l e
( va e to
• Ease of development: Databases are foremost application platforms that provide
c
r o vi ens
standard, easy ways to manipulate, transform, and modify individual data elements.
s to le lic
Even though typical XML Parsers give standard read access to XML data, they do not
j
M a rab
provide an easy way to modify and store individual XML elements. Oracle XML DB
n t ina ansfe
supports several standard ways to store, modify, and retrieve data. These include XML
V ale on-tr
Schema, XQuery, XPath, DOM, and Java.
n
If the drawbacks of XML file storage force you to break down XML into database tables and
columns, there are several XML advantages that you still have:
• Structure independence: The open content model of XML cannot be captured easily in
the pure tables-and-columns world. XML schemas allow global element declarations,
not just scoped to a container. Therefore, you can find a particular data item regardless
of where in the XML document it moves to as your application evolves.
• Storage independence: When you use relational design, your client programs must
know where your data is stored, in what format, what table, and what the relationships
are among those tables. By using XMLType, you can write applications without that
knowledge, and database administrators can map structured data to physical table-and-
column storage.
XML Fundamentals 9 - 8
• Ease of presentation: XML is understood natively by web browsers, many popular
desktop applications, and most Internet applications. Relational data is generally not
accessible directly from applications. Additional programming is required to make
relational data accessible to standard clients. Oracle XML DB stores data as XML and
makes it available as XML outside the database. No extra programming is required to
display database content.
• Ease of interchange: XML is the language of choice in business-to-business (B2B)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
data exchange. If you are forced to store XML in an arbitrary table structure, you are
using some kind of proprietary translation. Whenever you translate a language,
information is lost and interchange suffers. By natively understanding XML and
providing DOM fidelity in the storage/retrieval process, Oracle XML DB affords a clean
interchange.
Users today face a performance barrier when storing and retrieving complex, large, or many
XML documents. Oracle XML DB provides high performance and scalability for XML
operations. The major performance features are Native XMLType, XQuery, XPath, and XSLT a
a s
support, indexing, both full-text and XML, and a hierarchical index over Oracle XML DB
h
Repository.
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 9 - 9
An XML schema uses vocabulary defined by the schema for schemas to create a collection of
XML Schema type definitions and element declarations that comprise vocabulary for
describing the contents and structure of a new class of XML documents, the XML instance
documents that conform to that XML schema.
Note
In this course, the term “XML schema” (lowercase “s”) is used to reference any XML schema
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
that conforms to the W3C XML Schema (uppercase “S”) Recommendation. Because an XML
schema is used to define a class of XML documents, the term “instance document” is often
used to describe an XML document that conforms to a particular XML schema.
XMLType Storage Models
XMLType is an abstract data type that provides different storage models to best fit your data
and your use of it. As an abstract data type, your applications and database queries gain
flexibility: the same interface is available for all XMLType operations. Because different
storage (persistence) models are available, you can customize performance and functionality
to best fit the kind of XML data that you have and the pattern of its use. One key decision to s a
make when using Oracle XML DB for persisting XML data as XMLType is determining which ) h a
storage model to use for which XML data. r s
sฺ eฺ
m
e uid
XML/SQL Duality
c @
A key objective of Oracle XML DB is to provide XML/SQL duality. r o vi XMLnprogrammers
t G can
s t o d e
leverage the power of the relational model when working
m ajworking
with XML
S tu content and SQL
programmers can leverage the flexibility of XML
n a ฺ
when
t h is with relational content.
Thereby, you can use the most appropriate i
nttoolsuforsea particular business problem.
l e
XML/SQL
/SQ duality
dua ty means
ea s tthat
at the
t e same
c
sa
( vae datae to be eexposed
ca
can posed as rowso s in a tab
table
eaandd
o v
manipulated using SQL, or exposed i as
n s
nodes in an XML document and manipulated using
r c e
li transformation. Access and processing techniques are
jsto and
techniques such as DOM
independent of theaunderlyingb l
XSL
estorage format.
M r a
ina provide
These features
n t n s fesimple solutions to common business problems. For example:
You
V n tra XML DB SQL functions to generate XML data directly from a SQL query.
e use-Oracle
alcan
You cannothen transform the XML data into other formats, such as HTML, by using the
database-resident XSLT Processor.
You can access XML content without converting between different data formats, by using
SQL queries, online analytical processing (OLAP), and business-intelligence and data
warehousing operations.
You can perform text, spatial data, and multimedia operations on XML content.
SQL/XML Standard Functions
Oracle XML DB provides the SQL functions that are defined in the SQL/XML standard.
SQL/XML functions fall into two groups:
• Functions that you can use to generate XML data from the result of a SQL query. In this
course, these are called SQL/XML publishing functions. They are also sometimes called
SQL/XML generation functions.
• Functions that you can use to query and access XML content as part of normal SQL
operations. In this course, these are called SQL/XML query and access functions.
XML Fundamentals 9 - 10
Using SQL/XML functions, you can address XML content in any part of a SQL statement.
These functions use XQuery or XPath expressions to traverse the XML structure and identify
the nodes on which to operate. The ability to embed XQuery and XPath expressions in SQL
statements greatly simplifies XML access.
Automatic Rewriting of XQuery and XPath Expressions
SQL/XML functions and XMLType methods use XQuery or XPath expressions to search
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
collections of XML documents and to access a subset of the nodes contained within an XML
document. In many cases, Oracle XML DB is able to automatically rewrite such expressions
to code that executes directly against the underlying database objects.
Overview of Oracle XML DB Repository
Oracle XML DB Repository is a component of Oracle Database with which you can handle
XML data by using a file, folder, or URL metaphor. The repository contains resources, which
can be either folders (directories, containers) or files.
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 9 - 11
Implementing Oracle XML DB
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Repository s a
XMLType
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
Folders Access control i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t DBaKey s Components
OraclenXML
e r n
V al oprovides
XMLType n -t native XML storage and retrieval capability in the database because it is
stronglynintegrated with SQL. XML data, including XML Schema definition files, can be stored
in XMLType columns and tables. Physical storage of the XML data can be in LOBs, object-
relational (O-R) structures, or a hybrid of LOBs and O-R structures.
Oracle XML DB Repository is a component of Oracle Database 12c that is optimized for
handling XML data as files in a file system. Oracle XML DB Repository provides foldering,
access control, versioning, and other services for XML resources. Oracle XML DB Repository:
• Enables the creation of folders forming a “file system” structure in the database
• Stores data resources (database objects) such as XML, XSL, and XML Schema
documents in folders
• Can be used for fast access and manipulation of XML content, based on path names to
the XML data stored in the database
Oracle XML DB Repository can be accessed by using Internet protocols such as WebDAV,
FTP, and HTTP, and is as fast as accessing data from any file system.
XML Fundamentals 9 - 12
Lesson Agenda
• Oracle XML DB
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 9 - 13
Oracle XML DB: Features
Feature Benefit
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 9 - 14
Oracle XML DB: Features
Feature Benefit
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 9 - 15
Oracle XML DB: Features
Feature Benefit
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Your applications can access Oracle Database by using native Oracle XML DB web services.
One available service allows you to issue SQL and XQuery queries and receive results as
XML data. Another service provides access to all PL/SQL stored functions and procedures.
You can customize the input and output document formats when you use the latter service.
Web Services Description Language (WSDL) is automatically generated by the native
database web services engine.
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 9 - 17
Lesson Agenda
• Oracle XML DB
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 9 - 18
XMLType: Overview
XMLType:
• Is an abstract data type for the native handling of XML
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 9 - 19
Using XMLType
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t whenever s you want to use the database for persistent storage of XML data.
e n
Use XMLType
r a n
V alXMLType
Use o n -t to use SQL queries on a part of the document or on the entire document.
n
XMLType features include strong typing inside SQL statements and PL/SQL functions. Strong
typing ensures that the values passed are XML values and not arbitrary text strings.
The XML schema language defines 47 scalar data types. This provides for strong typing of
elements and attributes. Oracle XML DB leverages this strong typing feature of XML schema
to process XML data safely and efficiently.
XMLType uses the built-in C XML Parser and Processor. Therefore, it provides better
performance and scalability when used inside the server.
Because Oracle Database is natively aware that XMLType can store XML data, better
optimizations and indexing techniques are possible. By writing applications to use XMLType,
you can achieve these optimizations and enhancements, and preserve them in future
releases without needing to rewrite the applications. By using XMLType instead of the
standard relational or binary XML storage, applications can accommodate various storage
alternatives while minimizing changes to the SQL statements in the application.
XML Fundamentals 9 - 20
XMLType Storage Models
XML Fundamentals 9 - 21
Object-Relational storage: The XMLTYPE data is stored relationally as a set of objects. This
is also referred to as structured storage and object-based persistence. The biggest advantage
of object-relational storage is that it provides the best performance in structured cases. The
query performance matches that of relational tables, and updates can be performed in-place.
It also provides relational-like schema evolution capability.
In object-relational XMLType storage, an XML document is broken up and stored object-
relationally, but you can choose to store one or more of its XML fragments as embedded
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
CLOB instances. A typical use case for this is mapping an XML-schema complexType or a
complex element to CLOB storage, because you generally access the entire fragment as a
unit. This is sometimes called hybrid storage. For example, you can embed CLOB storage
within o-r storage.
Notes
• Each of the storage models has its own advantages and disadvantages in different
dimensions, such as performance and flexibility. No single storage model is right for all
use cases.
s a
h
• For additional information about the available XMLType storage models, see the a
following resources: s ฺrs) ฺ
- Oracle XML DB Developer’s Guide 12c Release 1 (12.1)
@ em uide
o v ic t G
- The white paper titled “Oracle XML DB: Choosing the Best XMLType Storage
t o r den
Option for Your Use Case” on OTN: s
aj s Stu
a ฺ m
http://www.oracle.com/technetwork/database/features/xmldb/xmlchoosestorage-
hi
v1-132078.pdf t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 9 - 22
Lesson Agenda
• Oracle XML DB
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 9 - 23
XML Schema Support
in Oracle Database 12c
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
DBMS_XMLSCHEMA
s a
h a
Local
s rs)
Global
ฺ
schema
e mschema
i d eฺ
v i c@ t Gu
t o ro den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
Oraclen t i n
Database n s XML schema support. You can perform the following tasks:
provides
l e r a
-tW3C-compliant local and global XML schema.
V•a Register
n o n
• Validate your XML documents against registered XML schema definitions.
• Generate XML schema from object types.
• Reference an XML schema that is owned by another user.
• Explicitly reference a global XML schema when a local XML schema exists with the
same name.
• Generate a structured database mapping from your XML schemas during XML schema
registration. This includes generating SQL object types, collection types, and default
tables, and capturing the mapping information by using XML schema attributes.
• Specify a particular SQL type mapping when there are multiple legal mappings.
• Create XMLType tables, views, and columns based on registered XML schemas.
• Perform manipulation (data manipulation language) and queries on XML schema–based
XMLType tables.
• Automatically insert data into default tables when schema-based XML instances are
inserted into the Oracle Database Repository by using FTP, HTTP, or SQL.
XML Fundamentals 9 - 24
XML Schema and Oracle XML DB
XML Fundamentals 9 - 25
Using Oracle Schema Annotations
Using Oracle XML DB, application developers and database administrators can annotate the
XML schema because they are given greater control over the set of objects that is generated
from the XML schema.
Generating SQL Types
During the schema registration process:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
• Oracle XML DB generates a SQL object type for each ComplexType defined in the
XML schema
• The definition of the SQL object mirrors the definition of ComplexType
• Each child element and attribute defined by ComplexType is mapped to an attribute of
the SQL object type
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 9 - 26
XMLType and XML Schema
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
In Oracle
n i n
t Database n s12c, you can create XMLType tables and columns. For example, you
e
al theooption
have r a
-t of specifying that they:
V n n
• Conform to a preregistered XML schema
• Are stored in the object-relational format specified by the XML schema
You can also choose to wrap existing relational and object-relational data into XML format by
using XMLType views.
You can store an XMLType object as:
• XML schema–based objects, which can be stored in object-relational format in tables,
columns, and views
• Non-XML-schema-based objects, which are stored as binary XML
Mapping from an XML instance document to object-relational or binary XML storage is
defined by registering your XML schema in Oracle Database 12c by using the
DBMS_XMLSCHEMA package. You must register the XML schema before you store XML
schema–based instance documents. To reference a registered XML schema, use its URL.
You can also store an XMLType object in binary XML format.
XML Fundamentals 9 - 27
Oracle XML DB supports the use of the W3C XML schema in two ways:
• Automatic validation of instance documents
• Definition of storage models
To use a W3C XML schema with Oracle XML DB, the XML schema document must be
registered with the database. After you register an XML schema, you can create XMLType
tables and columns that conform to the schema.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML schemas are registered by using methods provided by the DBMS_XMLSCHEMA PL/SQL
package. XML schemas can be registered as global or local schemas. This is covered later in
this lesson.
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 9 - 28
XML Schema Management
DBMS_XMLSCHEMA.
• You can use the DBMS_XMLSCHEMA subprograms to do
the following:
– Register an XML schema.
– Delete a previously registered XML schema.
– Recompile a previously registered XML schema. a
– Generate an XML schema.
s) has
– Evolve an XML schema. s ฺ r
m deฺ@ e ui
c
vi nt G
r o
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t schema s
The XML
l e n t r a n
functionality of Oracle Database12c is available through the PL/SQL-
a opackage,
supplied - DBMS_XMLSCHEMA, which is a server-side component that handles the
V n n
registration of XML schema definitions for use by Oracle Database 12c applications.
You can use the REGISTERSCHEMA procedure to register an XML schema that is specified as
a VARCHAR2 or XMLType. The REGISTERSCHEMA procedure registers an XML schema by
associating an XML schema document with a URL.
You can re-compile an already registered XML schema. This is useful to bring a schema in an
invalid state to a valid state by using the COMPILESCHEMA procedure.
You can generate an XML schema from an object type by using the GENERATESCHEMA or
GENERATESCHEMAS procedures.
You can delete a registered XML schema by using the DELETESCHEMA procedure. When you
attempt to delete an XML schema, DBMS_XMLSCHEMA checks whether the current user has
the appropriate privileges and whether there are any dependents.
A major challenge when using an XML schema is how to deal with changes in the content or
structure of XML documents. For example, new elements or attributes may need to be added
to an XML schema definition. In such cases, you perform XML schema evolution so that new
requirements are accommodated, while existing instance documents remain valid and
existing applications can continue to run.
XML Fundamentals 9 - 29
Note: Oracle XML DB supports the following kinds of XML schema evolution:
• In-place schema evolution: In-place schema evolution makes changes to an XML
schema without requiring existing data to be copied, deleted, and reinserted.
• Copy-based schema evolution: With copy-based schema evolution, all instance
documents that conform to the XML schema are copied to a temporary location in the
database. The old XML schema is deleted, the modified XML schema is registered, and
the instance documents are inserted into their new locations from the temporary area.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 9 - 30
Storage and Access Infrastructure
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s
n
While registering aanschema, Oracle Database also performs the following steps to facilitate
l e t r
a oaccess,
storage,
V n n- and manipulation of XML instances that conform to the XML Schema:
1. Creating types: When XML schema–based data is stored, its storage data types are
derived from the XML schema data types by using a default mapping and, optionally, by
using the mapping information that you specify by using XML schema annotations. For
binary XML storage, XML schema types are mapped to binary XML encoding types. For
object-relational storage, XML schema registration creates the appropriate SQL object
types for the structured storage of conforming documents.
2. Creating default tables: As part of XML schema registration, Oracle Database
generates default XMLType tables for all root elements. You can also specify any
column-level and table-level clauses and constraints for use during table creation.
You can control the creation of database objects and suppress their generation by arguments
to the registerSchema()function.
Use xdb:SQLType to specify the name of the SQL type to be generated. Set
xdb:defaultTable to the empty string ("") to suppress the creation of the default table for a
particular root element.
You can see the objects created by the registerSchema() function by writing a query that
uses the USER_OBJECTS data dictionary view.
XML Fundamentals 9 - 31
Validating XML
documents:
• Member functions
– XMLisValid()
– isSchemaValid()
– isSchemaValidated()
• Member procedures s a
– setSchemaValidated() ) h a
r s
sฺ eฺ
– schemaValidate() m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
a l e o Valid Invalid
( v t
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
n
It is oftent na nstofeknow whether a particular document conforms to a specific XML
inecessary
ale (that
schema
V n - trawhether it is valid with respect to a specific XML schema). By default, Oracle
is,
Database no12c ensures that XMLType instances are well-formed. In addition, for schema-
based XMLType instances, Oracle Database 12c performs a few basic validation checks.
Because full XML schema validation (as specified by the W3C) is an expensive operation,
when XMLType instances are constructed, stored, or retrieved, they are also not fully
validated.
To validate and manipulate the “validated” status of XML documents, several functions and
SQL operators are provided. These functions can be used to check whether the XML
documents that are being sent for input to the database conform to specific XML schemas
(that is, whether they are “valid”). However, this is not the same check as that performed by
XML Parsers, which check whether the XML documents are well formed.
Schema validation in the server uses the same functionality as XDK Schema validation.
Therefore, if you are using XDK in the middle tier, and then you call
setSchemaValidated(), it is equivalent to validating in the server.
Validating typically applies to XML schema–based XMLType instances. However, you can
also perform a validation check on unstructured XMLType instances.
XML Fundamentals 9 - 32
Lesson Agenda
• Oracle XML DB
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 9 - 33
Oracle XML DB Repository: Overview
s a
) h a
Folder r s
sฺ eฺ
m
e uid
c @
Resource
r o viLink nt G
a jsto Stude
ACL a
Pathnname ฺm Contentst his
t i e
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
Oraclen i n s the functionality of a file system in the database that forms a
t DB aprovides
XML n
e
al ofor
repository r
-tdata that is modeled via XML. The Oracle XML DB file system model maps path
V
namesn
n
or URLs to database objects of XMLType, and provides management facilities for
these objects. A database object that is mapped to the file system is called a resource. Oracle
XML DB resources are database objects with another (navigational) access path in addition to
SQL.
Oracle XML DB provides a generic access control list (ACL) mechanism that is usable by
applications, but provides significantly more functionality for objects mapped to the Oracle
XML DB file system. ACLs are usable on a per-object (per-row) basis and shareable across
table boundaries. ACLs can be seen as a particular implementation of database row-level
security.
Oracle XML DB also provides support for standard Internet protocols [FTP, HTTP(S), and
WebDAV] as a means of accessing its file system. XML elements are mapped to database
tables, XMLType tables, registered XML schema–based tables with XMLType columns, and
views. These can be easily viewed and accessed in Oracle XML DB Repository. Data in
XMLType tables and tables that contain XMLType columns can be stored in character large
objects (CLOBs) or natively in structured XML storage. Data in XMLType views can be stored
in local tables or remote tables that are accessed by using DBLinks. Both XMLType tables
and views can be indexed by using B*-tree, Oracle Text, function-based, or bitmap indexes.
XML Fundamentals 9 - 34
What Is the XML DB Repository?
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t isasimilar s to a directory structure in the database. You can access it by using
n
The repository
e r n
aldesktop
any
V o n t (such as a browser) or by creating a WebDAV connection (as you do in this
-tool
npractice). In the Address field, you can specify a database resource path. This maps
lesson’s
to a web folder so that you can view the database as a hierarchy. Access control applies so
that when you enter the path name, you are prompted for the password.
The documents in each folder are listed just as any file system document. However, the
documents are internally stored in rows and columns in the database.
The slide shows the contents of the PurchaseOrders table in the OE schema that is viewed
by using WebDAV connection as explained on the next few pages. On the right, you see the
contents of the table as .xml files. These files can be accessed by using SQL and any editor
(such as Microsoft Word) or browser.
XML Fundamentals 9 - 35
Mapping a Web Folder to
Oracle XML DB Repository
OE oe
2
3
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
4 r s
sฺ eฺ
m
e u4id
c @
r o vi nt G
Click the drill-
j s to tude
down icon.
ฺ a
m his S
a
tin se t
e n
( v al to u
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
na folder
To mapnatiweb n s feOracle XML DB Repository:
to
le n-NX
V1.a Innyour trasession, select Connect to Server from the Places menu. The Connect to
o
Server window is displayed.
2. Complete the Connect to Server window as follows:
a. Service type: WebDAV (HTTP)
b. Server: localhost
c. Port: 8080
d. Folder: /home/OE
e. User Name: OE (upper case)
Then click Connect. The Authentication window is displayed.
1. In the Authentication window, enter oe (lower case) in the Password field, and then
click Connect. The web folder is displayed as shown in the slide. In addition, an icon for
the mapped web folder, WebDAV on localhost, is created on the desktop.
2. To view the content of the PurchaseOrders table, click the drill-down icon next to
PurchaseOrders.
XML Fundamentals 9 - 36
Mapping a Web Folder to the
Oracle XML DB Repository
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t showsathescontents of the PurchaseOrders table in the OE schema that is viewed
The slide
e n
l a nmapped r n
byausing
V o -t web folder. On the right, you see the contents of the table as .xml files.
These nfiles can be accessed by using SQL and any editor such as gedit in Linux.
XML Fundamentals 9 - 37
Oracle XML DB Repository: Features
• Foldering
• Access control list (ACL)
• Protocol support
• Versioning
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t A afolder s is a node or directory in the repository hierarchy that contains or can
l e n
• Folder:
r n
Va contain
o n -at resource. A folder is also a resource.
n control list (ACL): ACL restricts access to a resource or resources. Oracle
• Access
XML DB uses ACLs to restrict access to any Oracle XML DB resource.
• Protocol support: Oracle XML DB allows access through Internet protocols such as
FTP and HTTP(S) as well as WebDAV (an extension of HTTP) to store and retrieve
XML data in the database.
• Versioning: With Oracle XML DB, you can maintain different versions of the same
resource.
In addition to containing resources, a folder resource can contain links to other resources
(files or folders). These are known as repository links or folder links.
Note: ACL is a set of database users who are allowed access to one or more specific
resources.
XML Fundamentals 9 - 38
Repository Support for Internet Protocols
• Internet protocols:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 9 - 39
WebDAV is a set of extensions to the HTTP protocol that you can use to edit or manage your
files on remote web servers. WebDAV can also be used to share and edit content by using
the Internet. Oracle XML DB supports WebDAV features such as folders (specified by
RFC2518), access control, and versioning.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 9 - 40
Oracle XML DB Versioning
XML Fundamentals 9 - 41
Lesson Agenda
• Oracle XML DB
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 9 - 42
Benefits of Oracle XML DB
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s native XML capabilities in the Oracle database include:
t of integrating
e n
The benefits
l ability r a n
V•a The o n -t to store and manage both structured and unstructured data under a standard
n XML data model
W3C
• Complete transparency and interchangeability between the XML and SQL metaphors so
that XML operations can be performed on database data, and SQL operations on XML
documents stored in the database
• Oracle XML DB Repository functionality such as creating folders, access control, FTP,
and WebDAV protocol access
• Version control of database resources
• Superior performance and scalability for XML operations
• Better management of unstructured XML data through piecewise updates, indexing,
search, multiple views on data, managing intradocument and interdocument
relationships
• Enabling data and documents from disparate systems to be accessed. For example, by
using Oracle Gateways and external tables, data can be combined into a standard data
model. These integrative capabilities reduce the complexity of developing applications
that must deal with data from different sources.
XML Fundamentals 9 - 43
XQuery Support in Oracle XML DB
XMLQuery()
Oracle
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XMLTable()
Database
XMLCast()
XMLExists()
Query result
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
ฺ m
a SQL thi
XQuery
Compilation t i
n usen
into
compilation engine l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s the XQuery language through a native implementation of the
t DB asupports
Oraclen
e XML
r n
V al ofunctions,
SQL/XML n -t XMLQuery and XMLTable. Oracle XML DB supports the SQL*Plus
commandn XQUERY, which allows you to enter XQuery expressions directly. In effect, the
XQUERY command turns SQL*Plus into an XQuery command-line interpreter.
Oracle XML DB compiles XQuery expressions that are passed as arguments to the SQL
functions XMLQuery, XMLTable, XMLExists, and XMLCast. This compilation produces
SQL query blocks and operator trees that use SQL/XML functions and XPath functions. A
SQL statement that includes XMLQuery, XMLTable, XMLExists, or XMLCast is compiled
and optimized as a whole, leveraging both relational database and XQuery-specific
optimization technologies.
You can use the XQuery functions, fn:doc and fn:collection, to query the resources in
Oracle XML DB Repository. In this section, the XQuery function fn:collection is used to
query the data in database tables and views. Later in the lesson, the XQuery function
fn:collection is used to query the resources in Oracle XML DB Repository.
XML Fundamentals 9 - 44
XQuery Support in Oracle Database
XML Fundamentals 9 - 45
Both XMLQuery and XMLTable evaluate an XQuery expression. In XQuery language, an
expression always returns a sequence of items. XMLQuery aggregates the items in this
sequence to return a single XML document or fragment. XMLTable returns a SQL table
whose rows each contain one item from the XQuery sequence.
Note: SQL/XML functions can be categorized into two types:
• Functions that you can use to query and access XML content. The XMLQuery,
XMLTable, and XMLExists functions belong to this category.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
• Functions that you can use to generate XML data from the result of a SQL query. These
include the XMLElement, XMLAttributes, XMLAgg, and XMLForest functions.
Oracle XML DB adds some XQuery functions to those provided in the World Wide Web
Consortium (W3C) standard. These additional functions are in the Oracle XML DB
namespace, http://xmlns.oracle.com/xdb, which uses the predefined prefix ora.
To query a relational table or view as if it were XML data, without having to first create a
SQL/XML view on top of it, use the XQuery function fn:collection within an XQuery
expression, passing as argument a URI that uses the URI-scheme name oradb together with s a
h a
the database location of the data.
s ฺrs) ฺ
search by using the contains text expression. @ em uide
XQuery Full Text search using contains text: You can use the XQuery Full Text
o v ic t G
For more information about the contains text expression,
t o r the
see
d e n XML DB
Oracle
Developer’s Guide 12c Release 1 (12.1). s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 9 - 46
Using XQuery with Oracle XML DB
Examples:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Oracle XML DB s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto SXQuery t ude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s and expressive language, and the SQL functions XMLQuery(),
t a veryageneral
XQuerynis
e r n
V al on-t and XMLExists() combine that power of expression and computation with
XMLTable(),
n strengths of SQL. The following are some examples where you typically use
the similar
XQuery with Oracle XML DB:
• Query XMLType relational data, possibly decomposing the resulting XML into relational
data using the XMLTable() function.
• Query a relational table or view as if it were XML data, without having to first create a
SQL/XML view on top of it, by using the XQuery function fn:collection within an
XQuery expression, passing as argument a URI that uses the URI-scheme name oradb
together with the database location of the data.
• Query XML data in Oracle XML DB Repository.
In this lesson, you see simple examples of using the XMLQuery() and XMLTable()
functions. For more information about XQuery functions in Oracle Database, see the Oracle
XML DB Developer’s Guide 12c Release 1 (12.1).
XML Fundamentals 9 - 47
XMLQuery
Syntax:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XMLQuery(<XQuery-string-literal>
[PASSING [by value] <expression-
returning-XMLType>]
RETURNING CONTENT)
Example:
s a
) h a
SELECT XMLQUERY('(1,2+3, "a")'
r s
sฺ eฺ
RETURNING CONTENT)as output m
e uid
FROM DUAL;
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s is very flexible. You can provide numbers, strings, and XML nodes as
The XMLQuery
e n r a n
function
al onto-tthis function. In the slide example, the argument is an XQuery sequence of two
arguments
V n expressions and a string. In the syntax, the XQuery string literal is a
numerical
complete XQuery expression, including the prolog and so on. A prolog is a series of
declarations and imports that define the processing environment for the fragment of XQuery
code. The PASSING clause contains SQL expressions, each returning an XMLType that is
used as the context for evaluating the XQuery expression. Oracle XML DB supports only
passing “by value” and not passing “by reference,” so the BY VALUE clause is implicit and can
be omitted.
SELECT XMLQuery(‘<TEST>34</TEST>’
RETURNING CONTENT) AS xmlres
FROM DUAL;
XML Fundamentals 9 - 48
In the preceding example, the XQuery string <TEST>34</TEST>, which is an element
constructor, is invoked through the XMLQuery function. Because this XQuery string does not
require a context item or bind variables, you do not have to pass additional parameters.
XQuery returns an XQuery sequence consisting of a single element node. returning
content is supplied to force the XQuery sequence into the XML(CONTENT) type.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals 9 - 49
URI Scheme oradb: Querying Table or View
Data with the XQuery fn:collection Function
• You can use the XQuery functions fn:doc and
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals 9 - 50
URI Scheme oradb: Querying Table or View
Data with the XQuery fn:collection Function
The format of the URI argument passed to fn:collection is
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
as follows:
• For an XMLType or relational table or view, TABLE, in the
database schema DB-SCHEMA:
– oradb:/DB_SCHEMA_NAME/TABLE_NAME/
• For an XMLType column in a relational table or view:
– oradb:/DB_SCHEMA_NAME/TABLE_NAME/ROW_PREDICATE/X-COL
s a
• Example: h a
s ฺrs) ฺ
. . . @ em uide
o v ic t G
'fn:collection("oradb:/OE/WAREHOUSES/ROW[WAREHOUSE_ID
t o r den
< 6]/WAREHOUSE_SPEC")' s
aj s Stu
a ฺ m hi
. . . t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
i n s argument passed to fn:collection is as follows:
t of theanURI
The format
n
e r
l ann-XMLType
t
V•a For
n o or relational table or view, TABLE, in the database schema DB-
SCHEMA:
oradb:/DB-SCHEMA/TABLE/
You can use PUBLIC for DB-SCHEMA if TABLE is a public synonym or if TABLE is a
table or view that is accessible to the database user who is currently logged in.
• For an XMLType column in a relational table or view:
oradb:/DB-SCHEMA/REL-TABLE/ROWPRED/X-COL
- REL-TABLE is a relational table or view.
- PRED is an XPath predicate that does not involve any XMLType columns.
- X-COL is an XMLType column in REL-TABLE.
- PRED is optional.
- DB-SCHEMA, REL-TABLE, and X-COL are required.
The XQuery expression example in the slide represents all XML documents in the XMLType
column, warehouse_spec, of the oe.warehouses table, for rows where the column
warehouse_id has a value of less than 6.
XML Fundamentals 9 - 51
fn:collection Function: Example
-- Create and populate the emp_departments table before running
-- this example as shown in the notes section of this page.
SELECT
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XMLQUERY('fn:collection("oradb:/HR/EMP_DEPARTMENTS")'
RETURNING CONTENT)
FROM dual;
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t in athensslide shows the use of fn:collection to query the
The example
e n
V al on-tr table. You need to create this table before running the code example in
EMP_DEPARTMENTS
n
the slide.
The EMP_DEPARTMENTS table is created by using the following commands:
CREATE TABLE EMP_DEPARTMENTS OF XMLTYPE;
INSERT INTO EMP_DEPARTMENTS VALUES (XMLType(bfilename('XML_DIR',
'department.xml'),nls_charset_id('AL32UTF8')));
XML Fundamentals 9 - 52
XMLTable
XML Fundamentals 9 - 53
XMLTable: Example
SELECT *
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
FROM
XMLTABLE('fn:collection("oradb:/OE/WAREHOUSES/")/ROW/LOC
ATION_ID');
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
t i
The XMLTable
n n n s and the output of the query are shown in the slide.
query
l e r a
Va non-t
XML Fundamentals 9 - 54
Quiz
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
t
Answer:na i n n s
l e r a
Va non-t
XML Fundamentals 9 - 55
Summary
XML Fundamentals 9 - 56
Practice 9: Overview
XML Fundamentals 9 - 57
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Table Descriptions
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Schema Descriptions
Overall Description
The Oracle Database sample schemas portray a sample company that operates worldwide to
fill orders for several different products. The company has two divisions:
• Human Resources (HR): Tracks information about the employees and facilities
• Order Entry (OE): Tracks product inventories and sales through various channels
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Each of these divisions is represented by a schema. In this course, you have access to the
objects in all the schemas. However, the emphasis of the examples, demonstrations, and
practices is on the HR and OE schemas.
All scripts necessary to create the sample schemas reside in the
$ORACLE_HOME/demo/schema/ folder.
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals A - 2
Human Resources (HR)
In the HR records, each employee has an identification number, an email address, a job
identification code, salary, and manager. Some employees earn commissions in addition to
their salary.
The company also tracks information about the jobs within the organization. Each job has an
identification code, a job title, and a minimum and maximum salary range for the job. Some
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
employees have been with the company for a long time and have held different positions
within the company. When an employee resigns, the duration that the employee was working,
the job identification number, and the department are recorded.
The sample company is regionally diverse, so it tracks the locations of its warehouses and
departments. Each employee is assigned to a department, and each department is identified
by a unique department number or a short name. Each department is associated with one
location, and each location has a full address that includes the street name, postal code, city,
state or province, and the country code.
s
In places where the departments and warehouses are located, the company records details
a
h a
ฺrs) ฺ
such as the country name, currency symbol, currency name, and the geographical region
where the country is located. s
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals A - 3
The HR Entity Relationship Diagram
DEPARTMENTS LOCATIONS
HR department_id location_id
department_name street_address
manager_id postal_code
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
location_id City
state_province
country_id
JOB_HISTORY
employee_id
start_date EMPLOYEES
end_date employee_id
job_id first_name COUNTRIES
department_id last_name country_id
Email country_name
s a
phone_number region_id h a
ฺrs) ฺ
hire_date
job_id s
JOBS
job_id
Salary
@ em uide
job_title
commission_pct
manager_id o v ic t G
min_salary department_id t o r denREGIONS
max_salary
s
aj s Stu region_name
region_id
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals A - 4
Human Resources (HR) Row Counts
XML Fundamentals A - 5
Order Entry (OE)
The company sells several categories of products, including computer hardware and
software, music, clothing, and tools. The company maintains product information that includes
product identification numbers, the category into which the product falls, the weight group (for
shipping purposes), the warranty period if applicable, the supplier, the status of the product, a
list price, a minimum price at which the product will be sold, and a URL for manufacturer
information.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Inventory information is also recorded for all the products, including the warehouse where the
product is available and the quantity on hand. Because the products are sold worldwide, the
company maintains the names of the products and their descriptions in different languages.
The company maintains warehouses in several locations to facilitate filling customer orders.
Each warehouse has a warehouse identification number, name, and location identification
number.
Customer information is tracked in some detail. Each customer is assigned an identification
number. Customer records include name, street address, city or province, country, phone s a
numbers (up to five phone numbers for each customer), and postal code. Some customers ) h a
order through the Internet, so email addresses are also recorded. Because of language
r
sฺ eฺs
differences among customers, the company records the NLS language and territory of each
m
e uid
c @
r o vi nt G
customer. The company places a credit limit on its customers to limit the amount for which
n a ฺm this
When a customer places an order, the company
n i
t tracks s e the date of the order, the mode of the
order, status, shipping mode, total amount e
al notoft tbbe
theu
o order, and the sales representative who
h l d place
helped l th
the order.
d Thi This may (
orv
c nse may th
the same iindividual
di id l as ththe accountt manager
v i
for a customer, or in the case
recorded. In additionjs
oro ofe an
tot the order l e over the Internet, the sales representative is not
icorder
information, the number of items ordered, the unit price, and
a
M fare b l
a tracked.
the products ordered
na e ralso
For each i
ntcountry s
ainn which it does business, the company records the country name, currency
a l e - t r
V non name, and the geographical region where the country is located. This data
symbol, currency
is useful to interact with customers living in different geographical regions around the world.
XML Fundamentals A - 6
Order Entry (OE)
OE CUSTOMERS
customer_id
cust_first_name
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
l e nt tran warehouse_id
quantity_on_hand
warehouse_name
Va non- location_id
XML Fundamentals A - 7
Order Entry (OE) Row Counts
XML Fundamentals A - 8
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Objectives
following:
• Include element, attribute, entity, and notation declarations
in a DTD
• Declare attributes with the following attribute types:
– CDATA
– Enumerated
– NOTATION s a
h a
– ENTITY and ENTITIES
s ฺrs) ฺ
– NMTOKEN and NMTOKENS
@ em uide
– ID, IDREF, and IDREFS o v ic t G
t o r den
• Create an XML schema from multiple a j XML
s t u schema
documents ฺm this S
t i n a
len use
• Describe XSLT 2.0 features
va e to
c (
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t focuses s on the use of declarations in a document type definition (DTD) to
e n
This appendix
r a n
al theonvalidity
control
V -t of XML documents. Apart from revisiting basic DTD declarations for
n attributes, entities, and notations, the appendix covers additional information about
elements,
each of the attribute types listed in the slide.
Creating an XML schema from multiple XML schema documents is covered, as are the
benefits of XSLT 2.0 and examples of some of the features.
XML Fundamentals B - 2
Declaration Types in a DTD (Review)
• Elements
<!ELEMENT element_name content_model>
• Attributes
<!ATTLIST element_name attribute_name attribute_type
default_value>
• Entities s a
) h a
<!ENTITY entity_name "replacement text"> r s
sฺ eฺ
m
e uid
• Notations c @
r o vi nt G
<!NOTATION notation_name SYSTEM "text">
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s
A DTDn consists ofndeclarations
a for the markup and data used in an XML document. The slide
l e t r
- syntax for declaring markup components:
a theongeneric
shows
V n
• Elements, which declare tag names and their content model. The content model for an
element includes other nested markup (elements) and/or character data.
• Attributes, which declare the attribute names for the containing element, the type of
attribute (not a data type), and optional default values
• Entities, which provide a mechanism for replacement text
• Notations, which are used in DTD attribute types to provide a way for identifying how
parsed or unparsed data is encoded, typically used by applications that can process the
data
Note: Notations are not frequently used in DTDs.
The next few pages of this appendix show examples of how to use each of these
declarations, and finally how to use DTD to validate the structure and content of an XML
document.
XML Fundamentals B - 3
Referencing the DTD (Review)
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n
The XML i n
t document n sreferences the DTD to be validated by using a specification syntax of:
e r a
al on-root-element-name
t
V
<!DOCTYPE
n
[declarations]>
The root element name must be used after the <!DOCTYPE keyword in the declaration. To
use an external DTD, replace the [declarations] part with:
• The SYSTEM keyword and a quoted string containing a URL or a relative path to a file
with a .dtd extension, such as employees.dtd in the slide, or a URL such as
http://www.myserver.com/dtd/employees.dtd
• The PUBLIC keyword and a quoted string containing a Formal Public Identifier (FPI).
For example, to reference the public XHTML identifier, use:
<!DOCTYPE xhtml PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
The last example in the slide uses an internal DTD with declarations placed between:
• The <!DOCTYPE root-element [ characters
• The closing ]> characters
Note: The <!DOCTYPE name [...]> specification appears after the XML declaration and
before the root element of the XML document. Public identifiers are seldom used. An XML
document can reference both an external DTD and an internal DTD. The internal DTD takes
precedence if an element is defined both externally and internally.
XML Fundamentals B - 4
Element Declarations (Review)
<last_name>Greenberg</last_name>
XML Fundamentals B - 6
Specifying Cardinality of Elements (Review)
Cardinality symbols:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Symbol Description
No symbol (default) Mandatory (one and only one)
XML Fundamentals B - 8
CDATA and Enumerated Attribute Types
<employee manager_id="102">
<employee_id>104</employee_id>
<last_name>Ernst</last_name> XML
</employee>
XML Fundamentals B - 9
ENTITY and ENTITIES Attribute Types
XML Fundamentals B - 10
ENTITIES Attribute Type
The ENTITIES type is an extension of the ENTITY type that:
• Allows the attribute value to be a space-separated list of external unparsed entity
names
• Is declared, as in the following example:
<!ATTLIST employee resume ENTITIES #IMPLIED>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
• Requires an entity declaration for each entity name used in the attribute value list of the
XML document
For example: A DTD, in a file called employee.dtd, shows the declaring of the resume
attribute by using the ENTITIES type:
<!ELEMENT employee (#PCDATA)>
<!ATTLIST employee resume ENTITIES #IMPLIED>
<!–- Required ENTITY declarations -->
s a
<!ENTITY resume-data SYSTEM "emp.txt" NDATA text>
h a
<!ENTITY resume-image SYSTEM "emp.jpg" NDATA jpeg>
s ฺrs) ฺ
<!-- Required NOTATION declarations -->
@ em uide
<!NOTATION text SYSTEM "text/plain">
o v ic t G
t o r den
<!NOTATION jpeg SYSTEM "image/jpeg">
s
aj s Stu
ฺ m
t
An example of an XML code that uses thenresume e thi can be written as:
ina sattribute
v a le to u
c ( "employee.dtd">
<?xml version="1.0"?>
<!DOCTYPE employee SYSTEM o v i
e n se
j s tor le lic resume-image">
<employee resume="resume-data
M a rab
ina ansfe
Bruce Ernst
n t
le n-tr
</employee>
a
V no resume attribute in the XML document contains a space-separated list of
Note: The
unescaped entity names, each of which must also be declared in the DTD.
XML Fundamentals B - 11
ID Attribute Type
XML Fundamentals B - 12
IDREF and IDREFS Attribute Types
<employees>
s a
<employee employee_id="_102">
) h a
<last_name>De Haan</last_name> r s
sฺ eฺ
</employee>
<employee employee_id="_103" manager_id="_102"> m
e uid
c @
<last_name>Hunold</last_name>
r o vi nt G
jsto Stude
</employee>
<employee employee_id="_104" mgrs="_102 _103">
a XML
<last_name>Ernst</last_name>
a ฺ m his
</employee>
t i n e t
</employees>
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
i n
t andaIDREFS
The IDREF
n n s types allow other elements to reference one or more elements with a
e r
al IDonattribute.
unique -t Declare the attribute type as:
V n IDREF type to reference a single attribute value of an element with an ID attribute
• An
• An IDREFS type to reference multiple ID attribute values
The DTD in the slide declares:
• The manager_id attribute as an IDREF type
• The mgrs attribute as an IDREFS type
The XML example shows the following:
• The employee element with its ID type value _103 (in employee_id) references the
employee element with the _102 value.
• The employee element with its ID value _104 references, as a space-separated list,
the following two employee elements:
- With employee_id value _102
- With employee_id value _103
XML Fundamentals B - 13
NMTOKEN and NMTOKENS Attribute Types
s a
<employees>
) h a
<employee hire_date="13-JAN-1993"> r s
sฺ eฺ
<last_name>De Haan</last_name> m
e uid
</employee>
c @
<employee email="AHUNOLD Alexander.Hunold">
r o vi nt G
<last_name>Hunold</last_name>
a jsto Stude XML
</employee>
n a ฺm this
</employees> i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t Attribute sType
NMTOKEN
e n r a n
V alNMTOKEN
The o n -ttype represents a name token whose value is like an XML name; that is, it can
containncharacter values, including:
• Letters (A-Z, a-z)
• Numbers (0-9)
• Underscores (_)
• Colons (:)
• Hyphens (-)
• Periods (.)
Note: However, an NMTOKEN value cannot contain any white space characters.
NMTOKENS Attribute Type
Using the NMTOKENS type allows a space-separated list of NMTOKEN attribute values.
The example in the slide shows the hire_date attribute declared as an NMTOKEN type and
the email attribute as an NMTOKENS type.
XML Fundamentals B - 14
Entities in XML (Review)
– Built-in entities
– Character entities
• Entities in a DTD can be declared as:
– General entities <!ENTITY name "text">
• Entities reference: s a
) h a
– Built-in, character, and general entities in an XML document r s
or the DTD by using: m sฺ eฺ
@ e uid
&entity-name; &entity-name; c
vi nt G
r o
– Parameter entities in the DTD by jusing:
a sto Stude
%entity-name;
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s Wide Web Consortium (W3C) standard, the predefined entities in XML
t to theaWorld
n
According
e r n
al on-t
include:
V
• Then built-in entities, which represent the following special characters:
- The less than sign (<), represented by <
- The greater than sign (>), represented by >
- The ampersand (&), represented by &
- The single quotation mark or apostrophe ('), represented by '
- The double quotation mark ("), represented by "
• The character entities, which represent any Unicode character specified in the XML
recommendation, which is based on Unicode 3.0. Character entities are formed by using
an ampersand (&), followed by a hash (#), a Unicode character number, and terminated
by a semicolon (;). For example, © denotes the copyright symbol (©). The
character number can be a decimal or a hexadecimal Unicode value. Hexadecimal
values are prefixed with an x. For example, © represents the copyright symbol (©).
An entity reference to a parameter entity is done in a DTD. However, references to built-in,
character, and general entities can be done in the XML document and a DTD, for example:
<Company>"Oracle Corporation"</Company> instead of
<Company>"Oracle Corporation"</Company>
XML Fundamentals B - 15
Creating an XML Schema
from Multiple XML Schema Documents
• The W3C XML Schema recommendation provides the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals B - 16
Declaring an <import>
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
xmlns:employees="http://www.hr.com/employees" employees.xsd
targetNamespace="http://www.hr.com/employees"
elementFormDefault="qualified"> . . .
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" resource.xsd
xmlns:target="http://www.hr.com/resource"
targetNamespace="http://www.hr.com/resource"
elementFormDefault="qualified"> . . .
s a
h a
<?xml version="1.0"?>
s ฺrs) ฺ
<schema xmlns="http://www.w3.org/2001/XMLSchema"
@ em uide
xmlns:employees="http://www.hr.com/employees"
o v ic t G
xmlns:resource="http://www.hr.com/resource"
t o r den
targetNamespace="http://www.hr.com/employees"
s
aj s Stu employees1.xsd
elementFormDefault="qualified">
ฺ m
a. . thi
<import namespace="http://www.hr.com/resource"
schemaLocation="resource.xsd"/> t i
n usen.
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
timport a s declarations from other XML schemas by using the <import>
You can
e n r n
global
al onThe
declaration.
V -t <import> declaration must always be a direct child of the <schema>
n
element. During the process of importing declarations from other namespaces, the XML
schema validator looks for the document based on the schemaLocation attribute specified
in the <import> declaration.
The slide example shows how to use an <import> declaration. The two XML schemas
employees.xsd and resource.xsd have different targetNamespaces.
In the employees1.xsd XML schema, the XML namespace declaration
http://www.hr.com/resource is added in the root element. The definition of
employees1.xsd shows the <import> declaration. The employees1.xsd XML schema
imports declarations from the http://www.hr.com/resource namespace, which is
located in the resource.xsd file. This declaration enables you to reuse the declarations
from the resource.xsd XML schema within the employees1.xsd XML schema.
XML Fundamentals B - 17
Declaring an <include>
resource_contacts.xsd
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:employees="http://www.hr.com/employees"
targetNamespace="http://www.hr.com/employees"
elementFormDefault="qualified">
. . .
employees1.xsd
s a
) h a
<?xml version="1.0"?>
r s
sฺ eฺ
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:employees="http://www.hr.com/employees" m
e uid
c @
xmlns:resource="http://www.hr.com/resource"
r o vi nt G
to tude
targetNamespace="http://www.example.com/employees"
elementFormDefault="qualified">
a j s
<include schemaLocation="resource_contacts.xsd"/>
a ฺ m his S
e n tin se t
( v al to u
o v ic nse
s t o r © 2014,
Copyright l i ceOracle and/or its affiliates. All rights reserved.
M aj rable
t ina adeclaration
The <include>
n n sfe allows you to combine XML schemas that have the same
V ale on-tr or no targetNamespace. You use the schemaLocation attribute to
targetNamespace
n
specify the location of the XML schema that you are including.
The slide example shows two XML schema documents with the same targetNamespace
http://www.hr.com/employees. Observe that in employees2.xsd, there is no
namespace attribute within the <include> declaration. This is because, unlike the
<import> declaration, you use the <include> declaration only on documents with the
same targetNamespace or no targetNamespace.
When the XML schema validator processes employees2.xsd, it includes the declarations
from resource_contacts.xsd as if they were declared in one document.
Note: Consider an example involving two XML schemas: A.xsd and B.xsd. The following
may be some useful scenarios to use the <import> and <include> declarations:
• If both A.xsd and B.xsd XML schemas have a targetNamespace and the
targetNamespace of A.xsd is different from the targetNamespace of B.xsd,
A.xsd must import B.xsd.
• If both A.xsd and B.xsd XML schemas have a targetNamespace and the
targetNamespace of A.xsd is the same as the targetNamespace of B.xsd, A.xsd
must include B.xsd.
XML Fundamentals B - 18
• If both A.xsd and B.xsd XML schemas do not have a targetNamespace, A.xsd
must include B.xsd.
• If XML schema A.xsd has no targetNamespace and XML schema B.xsd has a
targetNamespace, A.xsd must import B.xsd.
• If XML schema A.xsd has a targetNamespace and XML schema B.xsd has no
targetNamespace, A.xsd can either import or include B.xsd.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals B - 19
XSLT 2.0
XSLT 2.0:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
• Is a W3C recommendation
• Uses the XPath 2.0 and XQuery 1.0 data model
• Supports XML Schema data types
• Provides features such as the following:
– Grouping data
– Generating multiple outputs s a
) h a
– Temporary tree r s
sฺ eฺ
– Character mapping m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t uses the s data model that is used for XPath 2.0 and for XQuery. XSLT 2.0
e n
XSLT 2.0
r a nsame
V al XPath
uses
o n -t to locate and process content within an XML document’s logical hierarchy.
2.0
To usen
XSLT 2.0, set the version attribute in your stylesheet as follows:
<? xml-stylesheet version="2.0" ... ?>
XSLT 2.0 has new elements that help with grouping tasks, which are difficult to perform in
XSLT 1.0. XSLT 2.0 allows more than one document to be output.
By using XSLT 2.0, you can transform textual data that is not well-formed XML.
XSLT 2.0 allows you to define your own custom functions. It includes the xsl:function
element. xsl:function declares the name, parameters, and implementation of a user-
defined function that is used within XPath expressions in a given stylesheet.
Note
• Both XQuery and XSLT 2.0 use XPath 2.0 as a path language. XSLT is the primary
choice for transforming XML data, whereas XQuery is for querying XML documents.
• Some of the elements, such as xsl_value-of, produce different results in XSLT 2.0.
Therefore, you must make sure to specify the version of the transformation.
The next few pages of this appendix show examples of how to use some of the XSLT 2.0
features.
XML Fundamentals B - 20
Grouping Data
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="/">
<xsl:for-each-group select="/LIBRARY//BOOK" group-
by="CATEGORY">
<xsl:sort select="CATEGORY"/>
<CATEGORY name="{CATEGORY}">
<xsl:for-each-group select="current-group()" group-
s a
by="YEAR">
) h a
<YEAR year="{YEAR}">
<xsl:copy-of select="current-group()/TITLE"/> r s
sฺ eฺ
</YEAR> m
e uid
c @
</xsl:for-each-group>
</CATEGORY> r o vi nt G
</xsl:for-each-group>
a jsto Stude
</xsl:template>
n a ฺm this
</xsl:stylesheet>
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s common task when you transform XML documents using XSLT. The
t data isaanvery
e n
Grouping
r
al ofongrouping
process
V -t data is difficult in XSLT 1.0. Even though there are techniques, such as
n
the Muenchian method to perform grouping, XSLT 1.0 has no built-in support for grouping.
For example, you want to publish library information online. You want to transform the library
document into a set of books grouped by their categories. You then want to further group the
books by year.
First, you specify XPath expressions in the select attribute of <xsl:for-each-group> to
select the elements to be grouped. You then provide one of the following four attributes for the
<xsl:for-each-group> element:
• group-by: To group selected items by ignoring the order in which the items appear
• group-adjacent: To group together only adjacent items with the same value
• group-starting-with: For a pattern that matches the first node in each group
• group-ending-with: For a pattern that matches the last node in each group
In the slide example, all the selected <BOOK> elements are grouped by the content within its
child <CATEGORY> element, regardless of the selected order. Within the <xsl:for-each-
group> element, you can include an <xsl:sort> element to sort the groups. In the slide
example, <xsl:sort select=“CATEGORY”> ensures that the order of the book groups
depends on the alphabetical order of their category names.
XML Fundamentals B - 21
In XSLT 2.0, you can refer to the current group node-set by using the current-group()
function. In the slide example, the current-group() function is used to group the books in
each category by their published year.
Note: The XSLT 2.0 examples discussed in this appendix use the Library_app.xml
document that has the following code:
<LIBRARY>
<BOOK>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<TITLE>PL/SQL</TITLE>
<AUTHOR>Nancy Greenberg</AUTHOR>
<CATEGORY>LANGUAGES</CATEGORY>
<PUBLICATION>ABC</PUBLICATION>
<PRICE>38.90</PRICE>
<YEAR>2006</YEAR>
</BOOK>
<BOOK>
s a
<TITLE>XML</TITLE> h a
<AUTHOR>Chaitanya Koratamaddi</AUTHOR>
s ฺrs) ฺ
<CATEGORY>LANGUAGES</CATEGORY>
@ em uide
<PUBLICATION>XYZ</PUBLICATION>
o v ic t G
<PRICE>40.00</PRICE>
t o r den
<YEAR>2007</YEAR> s
aj s Stu
a ฺ m hi
</BOOK>
t i n e t
<BOOK>
a l en o us
i c (v se t
<TITLE>Data Warehousing</TITLE>
t o rov licen
<AUTHOR>Richard Green</AUTHOR>
js ble
<CATEGORY>APPLICATION DEVELOPMENT</CATEGORY>
a
M fera
<PUBLICATION>PQR</PUBLICATION>
a
n t i n n s
<PRICE>25.20</PRICE>
l e r a
Va non-t
<YEAR>2005</YEAR>
</BOOK>
<BOOK>
<TITLE>SOA</TITLE>
<AUTHOR>Glenn Stokol</AUTHOR>
<CATEGORY>FUSION MIDDLEWARE</CATEGORY>
<PUBLICATION>XYZ</PUBLICATION>
<PRICE>31.20</PRICE>
<YEAR>2007</YEAR>
</BOOK>
</LIBRARY>
Note: You can run XSLT 2.0 transformations using the oracle.xml.parser.v2.oraxsl
command-line utility. For more information about the oraxsl command-line utility, see the
lesson titled “Using XSL Transformations to Transform XML Documents.”
XML Fundamentals B - 22
Generating Multiple Outputs
documents.
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" name="book-format"/>
<xsl:template match="/">
<xsl:for-each-group select="/LIBRARY//BOOK" group-by="CATEGORY">
<xsl:result-document
href="BOOK{position()}_{current-group()/CATEGORY}.xml"
s a
format="book-format">
) h a
<BOOK_LIST category="{current-group()/CATEGORY}">
<xsl:copy-of select="current-group()"/> r s
sฺ eฺ
</BOOK_LIST> m
e uid
c @
vi nt G
</xsl:result-document>
</xsl:for-each-group>
r o
</xsl:template>
a jsto Stude
</xsl:stylesheet>
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
treal-world s
In many
l e n t r a napplications, you need to create multiple outputs from one XML document.
a 2.0osupports
XSLT - creating multiple XSLT outputs. This feature allows you to define multiple
V n n
XSLT transformation outputs in one XSL stylesheet.
XSLT 1.0 does not have the capability to define multiple outputs in one XSL stylesheet. This
means that you must apply separate XSL transformations for each document. You can write
one XSL stylesheet that relies on XSLT parameters to indicate which page to create. But, the
XSL stylesheet needs to execute multiple times. The process is complicated because of the
need to manage the XSLT parameters.
XSLT 2.0 introduces the <xsl:result-document> element to define multiple outputs.
Suppose, while transforming a library catalog, you want to publish the <BOOK/> element
under each category as a separate result document. If you provide the slide example as the
XSL stylesheet and Library_app.xml as the input source XML document, the oraxsl
utility generates three output documents as BOOK1_LANGUAGES.xml,
BOOK2_APPLICATION DEVELOPMENT.xml and BOOK3_FUSION MIDDLEWARE.xml.
To generate multiple output documents, perform the following steps:
1. Specify the output formats.
2. Specify the output file names.
XML Fundamentals B - 23
Each output may have a different format. Therefore, you define the output formats by using
<xsl:output> at the beginning of the XSL stylesheet. You then refer to the formats by
using their names. Each <xsl:result-document> element then generates the output
format named by its format attribute.
In the slide example, a book-format output format is defined as an XML output format with
element output indentations:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals B - 24
Creating Temporary Trees
XML Fundamentals B - 25
The following is the complete listing of the slide example:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:variable name="library" select="//BOOK[number(YEAR)>=2006]"/>
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
<xsl:template match="/">
<Expensive>
<xsl:apply-templates select="$library[number(PRICE)>38]"/>
</Expensive>
<Cheap>
<xsl:apply-templates select="$library[number(PRICE) < 38]"/>
</Cheap>
s a
</xsl:template> h a
s ฺrs) ฺ
<xsl:template match="*">
@ em uide
<xsl:copy-of select="."/>
o v ic t G
t o r den
</xsl:template> s
aj s Stu
</xsl:stylesheet> a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals B - 26
Character Mapping
XML Fundamentals B - 27
Summary
XML Fundamentals B - 28
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Objectives
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na sare guided through the process of managing external tool commands in
e n
In this appendix,
r a n
you
al on-Adding
JDeveloper.
V t external tools enables you to invoke a variety of utilities and operating
systemncommands within JDeveloper to process files in projects.
XML Fundamentals C - 2
External Tools with JDeveloper
An external tool:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals C - 3
Managing External Tools
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
Two external tools were added
a j sto Stude
in this example: Mozilla Firefox
n a ฺm this
and ShowXMLns i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i n a
t Tools swindow is displayed when you select Tools > External Tools.
e n
The External
r a n
V alslideoshows
The n -t the External Tools window with two externals tools that were added for this
course:nMozilla Firefox and ShowXMLns.
In the External Tools window, you can perform the following tasks:
1. Click New to create a new external tool.
2. Click Edit after selecting the tool name to alter the settings for the external tool.
3. Click Delete after selecting the tool name to delete the external tool from the JDeveloper
environment.
These operations are explained on the next few pages.
XML Fundamentals C - 4
Create External Tool:
Step 1 of 11 – Type
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
n t New
After clicking a ninsthe External Tools window, you are guided through the required steps
e
l then-Create
byausing t r External Tool wizard.
V n o
In Step 1 of 11: Type, you select the tool type and then click Next. The “Create External
Tool: Step 2 of 11 - External Program Options” window is displayed.
Note: The number of wizard steps that you go through depends on the options that you select
in the various windows.
XML Fundamentals C - 5
Create External Tool:
Step 2 of 11 – External Program Options
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na s to provide the path of the program executable, the directory in which to
t enablesanyou
e n
This step
l program, r
V athe
run
o n -t and the arguments to pass into it.
n
• Program Executable: Enter the complete path and file name of the external program to
be invoked, or click Browse to locate it.
• Arguments: Provide arguments that JDeveloper passes to the external program when it
is launched. You can add your own arguments, or select one from a list of macros by
clicking Insert. Make sure that you insert a space between the text you enter and the
macros you add.
• Run Directory: Enter the complete path name of the directory that the launched
external program will use as its current directory, or click Browse to locate a directory
and select it. You can add your own arguments, or select one from a list of macros by
clicking Insert. If this field is left blank, the external program will run from the parent
directory of the program executable.
• Command Sample: After you have supplied values, JDeveloper displays a sample of
the command that launches the external program for your inspection.
When all the settings are complete, click Next. The “Create External Tool: Step 9 of 11 –
Display” window is displayed.
XML Fundamentals C - 6
Create External Tool:
Step 9 of 11 – Display
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t controls s appearance of the menu items and toolbar buttons that launch the
e n
This step
r a n
the
V al program
external
o n -t from JDeveloper.
n
• Caption for Menu Items: Enter the name of the external program that will appear in
menus and on toolbars.
• ToolTip Text: Enter the tool tip label for the external program icon on the JDeveloper
IDE toolbar. If you leave this field empty, the tool tip text of the toolbar button will be the
same as “Caption for Menu Items.”
• Icon Location: If the external program is to be invoked from the toolbar, or if you want
the external program menu item to display an icon, enter the path name to an image file
or click Browse to locate and select it.
• Click Use Default to reset the icon location back to the default for the tool. For external
program tools, this is the icon of the application being launched on Windows, or a
generic external program icon on other platforms.
• Preview: This displays the menu entry that you have specified for your review.
When all the settings are complete, click Next. The “Create External Tool: Step 10 of 11 –
Integration” window is displayed.
XML Fundamentals C - 7
Create External Tool:
Step 10 of 11 – Integration
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i n a
t controls s the external program is integrated into the JDeveloper IDE.
l e n
This step
r a n
how
V•a Add o n -t to Menu: Select options to control which menus display the menu items that
Items
n
launch external programs.
• Tools Menu: Select to place the item in the main Tools menu, under External Tools.
• Navigator Context Menu: Select to place the item at the bottom of the context menu
(which appears when you right-click) for a document icon in the Navigator.
• Code Editor Context Menu: Select to place the item at the bottom of the context menu
(which appears when you right-click) for a document window.
Add Buttons to Toolbar: Select options to control where the buttons that launch external
programs will display. Select the Main Toolbar check box to place the item at the extreme
right of the main window’s toolbar.
Before tool starts: Select the Save all check box to save all open files before starting this
tool.
After Tool Exits: Select the Reload Open Files check box to ensure that JDeveloper
refreshes any open files after the external program exits.
Log Output to Message Log: Select this check box to send the output of the external tool to
the JDeveloper Message Log. When all settings are complete, click Next. The “Create
External Tool: Step 11 of 11 – Availability” window is displayed.
XML Fundamentals C - 8
Create External Tool:
Step 11 of 11 – Availability
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t controls s the external program is available from JDeveloper:
l e n
This step
r a n
when
V•a Always:
o n -tSelect this option to enable the external program to be launched at all times.
n
• When a File is Selected or Open in the Editor: Select this option to enable the
external program to be launched only when a file is selected or open in an editor.
• When Specific File Types are Selected: If you select this option, the external program
will be available only when the file types that you specified are selected. Select the
appropriate file types from Available Types and move them to Selected Types. You can
make multiple choices.
When all the settings are complete, click Finish. The External Tools window is displayed
again.
XML Fundamentals C - 9
Using the Newly Added
“gedit Text Editor” External Tool
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
t Tools swindow now displays the newly added “gedit Text Editor” tool. Click OK
e n
The External
r
l this nwindow.a n
to a
V exit
o -t
n Tools menu to display the newly added external tool. Select the gedit Text Editor
Click the
menu option to launch the gedit text editor as shown in the slide.
XML Fundamentals C - 10
Editing an External Tool
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
i na
tExternal s – Step 1 of 4 window is displayed. Note that the number of wizard
e n
The Edit
r a nTool
al youogo
steps
V n t
-through depends on the external tool that you select.
n
In the slide example, you want to edit the newly added “gedit Text Editor” external tool. The
window displays a graphic representation of the steps of the wizard that you can edit: External
Program Options, Display, Integration, and Availability.
XML Fundamentals C - 11
Deleting an External Tool
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na s not prompt for confirmation before the tool entry is deleted. You may
e n
Note: JDeveloper
r a n
does
V al to make
want
o n -ta copy of the product-preferences.xml file before removing or editing a
n
command.
XML Fundamentals C - 12
Summary
s a
) h a
r s
sฺ eฺ
m
e uid
c @
r o vi nt G
a jsto Stude
n a ฺm this
i
nt use
l e
c ( va e to
r o v©i 2014, eOracle
nsand/or its affiliates. All rights reserved.
c
jsto ble li
Copyright
a
M fera
t i na slearned how to use the External Tools window to find, add, edit, and
e n
In this appendix,
r a n
you
V al external
remove
o n -t tools, and use the menu or toolbar options in the JDeveloper environment.
n
The configuration of each external tool is stored in a file called tools.xml, which is located
in the JDEV_HOME\jdev\system<version> directory, where JDEV_HOME is the directory
in which JDeveloper is installed and <version> is a number sequence representing the
version of JDeveloper installed.
XML Fundamentals C - 13
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Glossary
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov© 2014,
Copyright l i c n and/or its affiliates. All rights reserved.
eOracle
a js ble
a M fera
n t i n n s
l e r a
Va non-t
GLOSSARY
D
Database A collection of data, usually in the form of tables or files, under the control of a
database management system. See Database management system.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
Database administrator (DBA) A person within the information technology (or information
systems) organization, who is responsible for administering, monitoring, and maintaining the
database
Database management system (DBMS) The component of a database that controls all user
and system activities related to the core functions of the database such as security
checking, tablespace allocation, space management
Document Object Model (DOM) The Document Object Model (DOM) recommended by the
W3C is a universal API for accessing the structure of XML documents. DOM provides a a
a
language-neutral and platform-neutral object model for web pages and XML documents.
h s
s) and
DOM describes language-independent and platform-independent interfaces toฺraccess
s
operate XML components and elements. e m ideฺ
i c@ t Gofuelements
Document Type Definition (DTD) provides the definition and relationships
v
contained in an XML document. A DTD validates an XML o en
tordocument.
a js Stu d
F
n a ฺm this
File Transfer Protocol (FTP) A service that i
ntallows e to transfer files to and from other
you
s
computers on the Internet. Anyonevwho a l ehas u
access
o to the FTP server can transfer the
( t
o v ic nse
available files to his or her computer.
FLWOR The acronymtFLWOR
s o r l i ce
(pronounced “flower”) represents the XQuery clauses FOR,
a j l e
b RETURN. A FLWOR expression has at least one FOR or LET
LET, WHERE, ORDER
a M feBY, r aand
clause and
n t in ans
a return clause; single WHERE and ORDER BY clauses are optional.
HVale n - tr
no Markup Language (HTML) The language used to create HTML pages for the Web
Hypertext
using a word processor or text editor
Hypertext Transfer Protocol (HTTP) The first component, the protocol, of a URL address,
that is used widely in the Internet and intranet environment. HTTP defines how to interpret
information. Other common protocols that you may come across include FTP, news, and
gopher. Also See Uniform Resource Locator.
J
J2EE (Java 2 Platform, Enterprise Edition) A Java platform designed for the mainframe-
scale computing that is typical of large enterprises. Sun Microsystems (together with
industry partners such as IBM) designed J2EE to simplify application development in a thin
client–tiered environment. J2EE simplifies application development and decreases the need
for programming and programmer training by creating standardized, reusable modular
components and by enabling the tier to handle many aspects of programming automatically.
XML Fundamentals D - 2
J
JavaScript JavaScript is the most popular scripting language (A scripting language is a
lightweight programming language) on the Internet, and works on all major browsers such
as Internet Explorer, Firefox, Chrome, Opera, and Safari.
N
Namespace provides a mechanism to distinguish elements with the same name but different
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
XML Fundamentals D - 3
W
Web Services Description Language (WSDL) uses the XML format for describing web
services. It describes what functionality a web service offers, how it communicates, and
where it is accessible.
World Wide Web Consortium (W3C) The World Wide Web Consortium (W3C) is an
international community where member organizations, a full-time staff, and the public work
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
together to develop Web standards. Led by Web inventor Tim Berners-Lee, W3C’s mission
is to lead the Web to its full potential. Contact W3C for more information.
X
Extensible Hypertext Markup Language (XHTML) The World Wide Web Consortium (W3C)
has defined Extensible Hypertext Markup Language (XHTML) as a successor to HTML.
XHTML is designed to conform with XML standards and well-formed document rules, and
provides a way to reproduce, subset, and extend HTML documents. An XHTML document a
a s
is a particular XML document instance that is intended for processing by a web browser.
h
s
XML Extensible Markup Language (XML) describes data objects called XMLฺrdocuments s)
that are composed of markup and data. em ideฺ
XML Developer’s Kit (XDK) To help application developersrtake o ic@
v advantage t
uGof XML, Oracle
n
disea standards-based set
Application Server includes XML Developer’s Kit, or jXDK.
a sto XDK t u
S and deploying XML-
of components, tools, and utilities that eases the
a ฺ m of hbuilding
task i s
enabled applications.
le ntin se t
u
XML Entity A unit of data storage(that
c va is identified
e to by a case
case-sensitive
sensitive name.
name It represents
replacement text to eliminate i s
ova lotlicofetyping
n in XML documents. An entity is referenced by
t o r
a js an ampersand
its name prefixed with
b l e (&) and terminated by a semicolon (;). The ampersand
is referred to asM
na racharacter.
an escape
fe
n ti aspecification
XMLelanguage n s defines the rules that govern XML document structure, and how
a l - t r
on must read them.
VXML processors
n
XML Parser Most browsers have a built-in XML Parser to read and manipulate XML. The
parser converts XML into a JavaScript-accessible object (the XML DOM). The XML DOM
contains methods (functions) to traverse XML trees, and access, insert, and delete nodes.
XML Schema provides a way to describe XML document structure by using data type
definitions, and uses namespace support.
XML Schema Document (XSD) XML Schema is an XML-based alternative to DTD. An
XML schema describes the structure of an XML document. The XML Schema language is
also referred to as XML Schema Definition (XSD).
XPath The XML Path Language (XPath) provides syntax for searching an XML document.
XPath expressions are used in an XSL stylesheet to match specific nodes.
XQuery is an XML query language that provides a data model for XML documents and a set
of operators to use with the data model.
XML Fundamentals D - 4
X
Extensible Stylesheet Language (XSL) XSL is implemented by XSL Transformations (XSLT)
to specify how to transform an XML document into another document. XSLT uses an XML
vocabulary for transforming or formatting XML documents.
XSL Formatting Objects (XSL-FO) An XML application that is used for describing the
precise layout of text on a page. XSLT is used to generate XSL-FO elements that are output
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
to another XML document. Additional processing is needed to create the final output form
such as a portable document format (PDF) document.
XSL Transformations (XSLT) An XML application that processes rules contained in an XSLT
Style Sheet. The rules in an XSLT Style Sheet can be applied to any XML document.
XSLT An XML Stylesheet Language (XSL) document is an XML document with elements
that define the transformation rules.
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t
XML Fundamentals D - 5
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2017, Oracle and/or its affiliatesฺ
s a
h a
s ฺrs) ฺ
@ em uide
o v ic t G
t o r den
s
aj s Stu
a ฺ m hi
t i n e t
a l en o us
i c (v se t
t o rov licen
a js ble
a M fera
n t i n n s
l e r a
Va non-t