Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No.
(3-1)
Unit III
Object Based Database and XML
CHAPTER 3
K-SCHEME SYLLABUS
3.1 Object Based Database: Overview, Complex datatypes, Structured types and inheritance in SQL
3.2 Table inheritance
3.3 Array and multiset types in SQL
3.4 Object-oriented vs. Object-Relational database
3.5 XML: Introduction, Structure of Xml Data, Xml Document Schema, X path, X Query: FLWOR Expressions,
Joins, Nested Queries, Sorting of Functions, Functions and Types.
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-2)
3.1 OBJECT-BASED DATABASE: Promotes reusability and reduces redundancy.
OVERVIEW 5. Persistence:
Objects are made persistent, meaning they
An Object-Based Database (OBDB) is a type of continue to exist even after the application that created
database that represents data in the form of objects, them has ended.
similar to how objects are used in object-oriented
programming (OOP). This approach combines 3.1.2 Components
database capabilities with object-oriented
1. Objects: Instances of classes that hold actual data.
programming principles.
2. Classes: Blueprints for creating objects.
3. Inheritance: Mechanism to derive new classes
from existing ones.
4. Identifiers (OIDs): Unique identifiers assigned to
each object.
3.1.3 Advantages
1. Suitable for applications with complex data, like
CAD/CAM, multimedia, and scientific data.
2. Improves code reusability and data integrity.
3. Better mapping between application objects and
Fig 3.1: Object based database database objects (reduces mismatch).
3.1.1 Key Features 3.1.4 Disadvantages
1. Object-Oriented Data Model:
1. Less mature than relational databases.
Data is stored as objects, not as rows and
2. Not as widely supported or standardized.
columns.
3. May require learning new database models or
Each object contains:
query languages (like OQL - Object Query
Attributes (data fields) Language).
Methods (functions or operations that can be
performed on the data) 3.1.5 Challenges in Implementing
Object-Based Databases and
2. Support for Complex Data Types:
Their Solutions
Can handle multimedia, images, graphs, and other
complex data types that are hard to represent in Implementing an Object-Based Database (OBDB)
relational models. comes with several challenges due to its complex
3. Encapsulation: structure and difference from traditional relational
Data and operations are bundled together as a models. Below are the major challenges and their
single unit (object). potential solutions:
1. Object-Relational Impedance Mismatch
Helps in maintaining data integrity.
4. Inheritance: Challenge
Allows creation of new object classes based on There is a mismatch between object-oriented
existing ones. programming languages (like Java, C++) and relational
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-3)
databases. Object-based databases aim to solve this but 5. Performance Overhead
often still face integration issues with existing systems Challenge
that use relational databases.
Object databases may suffer from performance
Solution issues, especially in terms of object navigation and
Use Object-Relational Mapping (ORM) tools method invocation.
like Hibernate to bridge the gap between object Solution
models and relational databases.
Use indexing and caching techniques.
Adopt native object databases when possible to
avoid conversion. Optimize object design and query strategies.
6. Steep Learning Curve
2. Complex Querying Mechanism
Challenge Challenge
Querying data in object databases is not as Developers and DBAs familiar with relational
straightforward as using SQL in relational databases. databases may find object databases difficult to learn
Object Query Language (OQL) or custom APIs can be and use.
harder to learn and use. Solution
Solution Provide training and documentation.
Improve query languages to be more SQL-like or Use hybrid object-relational systems during
provide query abstraction layers. transition phases.
7. Scalability and Integration
Offer visual query tools for non-expert users.
3. Lack of Standardization Challenge
Challenge Scalability can be an issue, and integrating with
Unlike SQL in relational databases, object existing systems (e.g., ERP, CRM) can be complex.
databases do not have a widely accepted standard. Solution
This makes interoperability and migration harder. Use modular architectures that allow easier
Solution integration.
Use databases that follow standards like ODMG Design with scalability in mind (e.g., distributed
(Object Data Management Group). object stores).
Encourage adoption of unified APIs and formats. 3.2 COMPLEX DATA TYPES IN
4. Limited Tool Support
DATABASES
Challenge
There are fewer tools for backup, reporting, 3.2.1 What are Complex Data Types?
analytics, and administration compared to relational
databases. Complex data types are data types that allow you
to store structured, nested, or composite data in
Solution a single field or column of a database table. These
Develop or integrate third-party tools for essential data types are essential in modern databases for
functions. representing real-world entities that are not
Use open-source communities to build and share easily broken down into simple data types like int,
useful tools. char, or date.
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-4)
They are widely used in object-based databases, Usage : Useful when an object has
object-relational databases, and NoSQL subcomponents that themselves are structured.
databases.
c. Arrays
3.2.2 Types of Complex Data Types Allows storing multiple values of the same type
in a single column. Arrays can be fixed-length or
a. User-Defined Types (UDTs)
variable-length.
These are custom data types that allow combining Example
multiple attributes of different data types into one type.
Example (in SQL)
Usage : Storing a list of marks, tags, or sensor
readings.
d. Collections (Sets, Lists, Bags)
Collections allow storing multiple elements in one
Usage: Helpful in storing composite data such as field. These can be:
addresses, coordinates, or any logically grouped Set: Unordered, unique values
fields. List: Ordered, duplicates allowed
b. Nested Records (Tuples) Bag (Multiset): Unordered, duplicates allowed
A record (or row) that contains another record as a Example (Object DB):
field.
Example
Usage : Tags, ordered steps, item quantities.
e. References (REFs)
REFs are like pointers to other objects in object
databases. They are used to define relationships
between objects.
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-5)
Example 3.3 STRUCTURED TYPES IN SQL
What is a Structured Type?
A structured type (also called a row type or
user-defined type (UDT)) is a custom data type
that groups multiple attributes into a single
composite unit.
It is similar to a record or object in
programming. It can hold multiple fields
(attributes) of different data types.
Why Use Structured Types?
To model real-world entities more naturally
Usage : Modeling relationships (like foreign keys To promote reusability and modularity
in relational DBs).
To reduce the complexity of tables and improve
3.2.3 Benefits of Complex Data Types organization
Benefit Description
3.3.1 Syntax Example (Using
PostgreSQL-like Syntax)
Closer representation of real-world
Data modeling
objects
Fewer joins, faster retrieval of
Efficiency
related data
Promotes reuse through user-defined
Modularity
types
Easier to manage structured data in a
Maintainability
compact form
3.2.4 Challenges in Using Complex
Data Types
Challenge Explanation
Query Nested and structured queries are
complexity: harder to write Accessing Fields of a Structured Type
Difficult to index deeply nested or You can access specific fields using dot notation:
Indexing:
complex structures
Less portable between different
Portability:
DBMSs 3.3.2 Inheritance in SQL
Limited support in traditional SQL
Tool support: UQ. Explain inheritance for PL/SQL objects with
tools
examples (Q.
Storage Can be less efficient in terms of 5(C), 6 Marks)
overhead: storage and performance
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-6)
What is Inheritance in SQL? Advantages of Inheritance in SQL
Inheritance allows one table (child table) to Feature Benefit
inherit columns and constraints from another table Code reuse Avoids redundancy by reusing column
(parent table). This concept is similar to class definitions
inheritance in OOP. Logical Models real-world relationships (e.g.,
Primarily supported in PostgreSQL. hierarchy Employee → Manager)
Types of Inheritance Ease of Add new types with minimal changes
Single Inheritance: One table inherits from a extension
single parent. Limitations
Multiple Inheritance: A table can inherit from
1. Not widely supported across all SQL-based
more than one table (PostgreSQL supports this).
databases (mainly PostgreSQL).
Syntax Example (PostgreSQL) 2. Foreign key and unique constraints do not
automatically propagate to child tables.
3. Managing inheritance in complex systems may get
tricky.
3.4 TABLE INHERITANCE IN SQL
UQ. Explain table inheritance in SQL
(Q. 4(E), W-19, 4 Marks)
Table Inheritance is a feature primarily
supported by PostgreSQL (and partially by some
object-relational databases) that allows a table to
inherit the structure of another table, similar to
class inheritance in object-oriented programming.
In this example, Manager automatically gets the
1. What is Table Inheritance?
columns:
Table inheritance means a child table
emp_id
automatically receives all columns (and optionally
name data) from a parent table.You can also add new
salary columns to the child table, and the child table can be
along with its own column department queried through the parent.
Querying Inherited Tables 2. Syntax (PostgreSQL Style)
By default, queries on the parent table include
rows from child tables:
To exclude child rows:
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-7)
In this example, the Student table has the following
columns:
id
name All three tables (Employee, Manager, Intern)
birth_date share common columns.
student_id You can query all employees, including managers
course and interns, using:
3. Querying Inherited Tables
Query the Parent (Includes All Children by
Default) 5. Advantages of Table Inheritance
Advantage Explanation
No need to redefine shared columns
This returns rows from both Person and Student Code Reuse
in child tables.
tables.
Logical Helps model real-world relationships
Query Only the Parent Table
Hierarchy (e.g., Employee → Manager).
Flexible
Query parent table to get all subtypes.
Queries
This returns rows only from the Person table,
6. Limitations
excluding children.
4. Use Case Example Limitation Details
Consider a system where you manage all people in
Not standard Mostly supported only in
an institution:
SQL: PostgreSQL.
Primary keys, foreign keys, and
Constraints do
unique constraints are not
not propagate:
automatically inherited.
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-8)
Limitation Details
No automatic You must manage relationships
joins: manually between parent and child.
Triggers and Must be defined separately for
rules: each table.
3.6 ARRAYS
1. Array Type in SQL
What is an Array Type?
An array is a data type that allows storing
multiple values of the same data type in a single
column of a table. Arrays are ordered collections, and
elements can be accessed by their index.
Supported in: PostgreSQL, Oracle (as VARRAY),
Informix
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-9)
3.6.1 Syntax (PostgreSQL) Feature Benefit
Natural :Good for use cases like storing
Mapping scores, tags, or coordinates
3.6.6 Limitations of Arrays
Poor support in standard SQL (only a few DBMSs
support arrays natively)
Not suitable for large, relationally complex data
3.6.2 Inserting Data into Array Difficult to index and query efficiently for large
Columns arrays
3.7 MULTISET TYPE IN SQL
What is a Multiset?
A multiset (also called a collection or nested table) is
a set-like structure that:
3.6.3 Accessing Array Elements
Allows duplicate elements
Has no specific order
It is used in SQL to store collections of values,
especially in object-relational databases like Oracle.
3.7.1 Multiset vs Set
3.6.4 Updating Array Elements Feature Set Multiset
Duplicates Not allowed Allowed
Order Not defined Not defined
3.7.2 Oracle Example: Defining and
Using a Multiset
Step 1: Create a Nested Table Type
3.6.5 Advantages of Arrays
Step 2: Use the Type in a Table
Feature Benefit
Store multiple values in a single
Compact:
row/column
Reduces need for JOINs in some
Performance:
cases
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-10)
Step 3: Insert Data
Querying Multisets
3.7.3 Advantages of Multisets
Feature Benefit
Flexible Supports duplicate values
Supports Can be manipulated using multiset
Subqueries operations
Useful in Nested Good for storing collections in
Data object-relational designs
3.7.4 Multiset Operations in Oracle
Operation Description
MULTISET UNION Combines two collections
Elements in one but not the
MULTISET EXCEPT
other
MULTISET
Elements common to both
INTERSECT
Example
3.7.5 Limitations of Multisets
Complex to use in standard SQL
Limited support outside Oracle
Harder to query and optimize compared to
normalized tables
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-11)
3.8 COMPARISON: OBJECT-ORIENTED DATABASE VS. OBJECT-RELATIONAL
DATABASE
Aspect Object-Oriented Database (OODB) Object-Relational Database (ORDB)
Based on objects, classes, and methods Based on relational model (tables and rows)
Data Model
(similar to OOP languages) with added object-oriented features
Structure Uses tables with support for user-defined
Uses classes to define object structure
Representation types (UDTs) and inheritance
Stores objects directly with identity, Stores data in tables; extended types allow
Storage Unit
attributes, and behavior storage of complex structures
Uses Object Query Language (OQL) or Uses SQL with extensions (e.g., structured
Query Language
language-specific APIs (e.g., Java, C++) types, REF, ARRAY, MULTISET)
Supported natively (each object has a Supported via references (REFs) or foreign
Object Identity
unique ID) keys
Supported (data and behavior stored Limited or simulated (methods not stored in
Encapsulation
together in objects) tables, only data)
Fully supported (class-based inheritance Partially supported (mostly type inheritance,
Inheritance
and method overriding) not table-level in many DBMSs)
Fully supported (e.g., same method with
Polymorphism Limited or not natively supported
different behavior in subclasses)
Accessed via programming language
Data Access Accessed using SQL queries
objects
Integration with High — directly stores and retrieves Moderate — requires mapping between SQL
OOP programming language objects and OOP (e.g., using ORM frameworks)
Easier to evolve class definitions More rigid; requires schema modification
Schema Evolution
dynamically through SQL DDL
Complex Data Natively supports complex objects, Supports complex types through UDTs,
Types images, multimedia, etc. arrays, and nested tables
Standards and No widely accepted standard; limited SQL-based and standardized; widely adopted
Adoption adoption in enterprise systems
Efficient for object-oriented applications; May require extra processing to map objects
Performance
no impedance mismatch to tables (object-relational mapping)
Tool and Vendor Limited tool support; niche vendors (e.g., Strong support by major DBMSs (e.g.,
Support ObjectDB, db4o) Oracle, PostgreSQL, IBM DB2)
CAD/CAM, AI systems, simulations, Enterprise systems, ERP, CRM, web
Use Cases
multimedia, real-time systems applications needing complex data handling
Example Databases ObjectDB, db4o, GemStone, Versant PostgreSQL, Oracle, IBM DB2, Informix
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-12)
Aspect Object-Oriented Database (OODB) Object-Relational Database (ORDB)
3.9 WHAT IS XML?
XML stands for eXtensible Markup Language. It is a markup language used to store, structure, and transport
data in a human-readable and machine-readable format.
Unlike HTML, which defines how data is displayed, XML focuses on describing the data itself.
3.9.1 Key Characteristics of XML
Feature Description
You can define your own custom tags (not limited to predefined
Extensible
tags)
Self-descriptive Tags describe the data they hold, making it easy to understand
Structured Data is stored in a hierarchical (tree-like) structure
Platform-independent Can be used across different systems and platforms
Text-based Data is stored in plain text format, making it easy to share and parse
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-13)
3.9.2 Basic XML Syntax
3.9.5 Important Concepts Related to
XML
Concept Description
DTD (Document Type Defines the structure and
Definition) legal elements/attributes in
an XML document
XSD (XML Schema A more powerful way to
Definition) define XML structure and
<student> is the root element
data types
<name>, <rollno>, <department> are child
XSLT (XML Used to transform XML
elements
Stylesheet Language data into other formats like
Data is stored inside tags Transformations) HTML or text
3.9.3 Why Use XML? 3.10 STRUCTURE OF XML DATA
Data Exchange: Common format for exchanging
UQ. Describe structure of XML with example.
data between systems (e.g., web services, APIs)
(Q. 4(3), ,S-22, 4 Marks)
Data Storage: Used for configuration files, data
An XML document follows a tree-like
backups, and structured storage
hierarchical structure, which consists of nested
Interoperability: Language-neutral and widely elements. The structure defines how data is organized,
supported by many applications labeled, and related within the document.
3.9.4 Common Applications of XML 3.10.1 Basic Components of XML
Structure
Area Example
Component Description
Used in SOAP (Simple
Optional line that defines XML
Web Services Object Access Protocol) for Declaration:
version and encoding
exchanging messages
Root The top-level (single) element
.xml files used in software to Element: that contains all other elements
Configuration Files
store settings
:Nested tags inside the root,
Child
Between databases, representing data fields or sub-
Elements
Data Interchange spreadsheets, and structures
applications Provide additional information
Attributes:
within tags
Used with XSLT and DTD
Document Formatting for formatting and validating Text The actual data stored inside
XML data Content: elements
Comments: Notes that are ignored by the
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-14)
Component Description
3.10.2 Hierarchical (Tree) Structure
XML parser
The data is organized in a parent-child structure:
Example XML Document
Rules for XML Structure
1. One root element only (everything must be
inside it)
2. Tags must be properly nested
3. Every opened tag must be closed
4. Tags are case-sensitive
5. Attributes must be quoted
3.11 XML DOCUMENT SCHEMA
Detailed Breakdown
Part Description UQ. Explain XML document schema.
<?xml XML Declaration: Specifies the (Q.-2(D) ,W-19, 4 Marks)
version="1.0"?> version and encoding An XML Schema defines the structure, content,
Root element: Every XML and data types of an XML document. It ensures that
<university> the XML document is valid and follows the rules
document must have one root
defined in the schema.
Child element: Represents a
<student> record (has nested sub- It acts like a blueprint for XML documents.
elements) There are two main types of XML schemas:
Attribute: Additional data for an Type Description
id="101"
element (student ID) DTD (Document Older, simpler way to define
<name>John Type Definition) XML structure
Text content inside an element
Doe</name> XSD (XML Schema XML-based and more
<!-- This is a Definition) powerful schema language
Optional comment in XML
comment -->
Why Use an XML Schema?
To validate XML documents
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-15)
To define what elements and attributes are Explanation
allowed
XSD Element Description
To enforce data types (e.g., integer, string, date)
xs:element Defines an element
To specify element order, occurrence, and
nesting xs:complexType Groups multiple child elements
3.11.1 XML Schema Definition (XSD) Specifies the order of child
xs:sequence
elements
XSD is written in XML syntax and is widely
Built-in data types in XML
used. xs:string, xs:int
Schema
Sample XML
3.11.2 Document Type Definition
(DTD)
DTD is an older method, not written in XML
syntax.
Corresponding XSD is given below
#PCDATA = Parsed Character Data (text)
Does not support data types (like int, date)
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-16)
3.11.3 Advantages of XML Schema over DTD
Sr. Aspect XML Schema (XSD) DTD
No.
1. Syntax Written in XML syntax, so it is machine- Written in a non-XML syntax,
and human-readable which is harder to parse and less
consistent
2. Data Types Support Supports built-in data types (e.g., xs:string, Does not support data types—
xs:integer, xs:date) and allows custom data everything is just parsed character
types data (#PCDATA)
3. Namespace Support Fully supports XML Namespaces, allowing No namespace support
for better integration with other XML
vocabularies
4. Stronger Validation Allows for detailed validation such as value Only validates element order and
ranges, string lengths, enumerations, and structure, not content
patterns (regex)
5. Object-Oriented Supports inheritance, complex types, Lacks such features; elements and
Features element reuse, and type extension attributes must be redefined
manually
6. Tool Support Better supported by modern XML parsers, Limited support in modern
IDEs, and web services tools development environments
7. Type Checking Enforces strict type-checking to ensure data No data typing, so type-related
integrity errors are harder to catch
. Attribute Data Allows setting specific types for attributes Attributes are always treated as text
Types (e.g., xs:int, xs:ID)
9. Extensibility and Can define modular schemas and Not modular or reusable
Reuse import/include other schema files
10. Compatibility with Preferred in modern Web Services Rarely used in current standards or
Web Standards (SOAP/WSDL) and data exchange APIs
protocols
3.12 WHAT IS XPATH? expressions (similar to navigating files in a
folder).
XPath stands for XML Path Language. It is a Why is XPath Important?
query language used to navigate, select, and
extract parts of an XML document. XPath is a core component of other XML
technologies like XSLT, XQuery, and XPointer.
Think of it as a way to find elements or
attributes in an XML document using path-like Used for filtering, searching, and extracting
specific elements or values from XML.
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-17)
Often used in programming languages and XPath Expression Meaning
automation tools for processing XML files (e.g.,
Java, Python, Selenium, etc.). elements)
Basic Syntax of XPath
XPath uses path expressions to select nodes in an
XML document.
Example XML
Example XPath Queries
XPath Expression Meaning
Selects the root
/university
element <university>
Selects all <student>
/university/student elements under
<university>
Selects all <name>
elements that are
//student/name
children of <student>
anywhere
Selects the first
/university/student[1]
student
/university/
Selects the last student
student[last()]
Selects the student
//student[name='Jane']
whose name is Jane
//@rollno Selects all rollno
attributes (if written as
attributes instead of
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-18)
XPath Node Types
3.13 XQUERY
Node Type Description
XQuery stands for XML Query Language. It is a
Element Tag like <student>, <name>
powerful functional query language designed to
Attribute Inside tags, like id="101" query, transform, and manipulate XML data.
Text Actual content like John, Jane XQuery is to XML what SQL is to databases —
it allows you to search, extract, and modify data
Comment Ignored by the parser (<!-- comment -->)
stored in XML documents.
Namespace Defines XML namespaces if used Key Features of XQuery
Axes in XPath
Feature Description
XPath allows selection of nodes relative to the
current node using axes: XML-native Works directly with XML
documents and data
Axis Description
Query + Can extract data and also
child:: Selects children (default axis) Transformation transform or restructure it
parent:: Selects the parent node Functional Uses expressions and functions
Selects all ancestors (parents, Language like map/filter
ancestor::
grandparents) Typed Data Can work with data types
descendant:: Selects all descendants Support defined in XML Schema
following- Supports XPath XQuery is built on top of XPath,
Siblings after the current node so it uses XPath expressions
sibling::
preceding- Why Use XQuery?
Siblings before the current node
sibling:: To search specific data within large XML files
Example: child::student = /university/student To transform XML into other XML, HTML, or
Functions in XPath plain text
XPath includes many built-in functions: To generate reports from XML databases
Function Description To combine multiple XML documents
text() Selects text content Basic Syntax
XQuery is often written as an expression with
last() Selects the last element in a node set
clauses like:
position() Returns position of current node
contains() Checks if a string contains a substring
Checks if a string starts with a
starts-with()
substring Explanation
string- Part Meaning
Returns length of a string
length()
doc("students.xml") Loads the XML file
Example : //student[contains(name, 'Jo')] → selects
students with names that include “Jo” Iterates through each <student>
for
element
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-19)
Part Meaning 3.14 FLWOR EXPRESSION?
Filters students based on a
where FLWOR stands for:
condition
FOR
Outputs the matching data
return LET
(student names)
WHERE
Example XML File: students.xml
ORDER BY
RETURN
FLWOR expressions are the core structure in
XQuery for querying and transforming XML data.
They are similar to SQL’s SELECT-FROM-WHERE
clause.
Purpose of FLWOR
FLWOR expressions allow you to:
Iterate over elements
Assign variables
Filter based on conditions
Sort results
Return custom output
FLWOR Expression Syntax
Each clause is optional except for for and return.
Breakdown of Each Clause
XQuery Examples Clause Description Example
1. Get all student names
for for $x in
Iterates over a
doc("students.xml")/university/studen
sequence of nodes
t
let Binds a variable to a let $marks := $x/marks
2. Get names of students with marks value (without looping)
above 80 where Filters the result using where $marks > 80
a condition
order order by $marks descending
Sorts the result
by
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-20)
Clause Description Example
return Constructs the output return $x/name
Example XML (students.xml)
FLWOR Example 3: Order students by marks
Result
FLWOR Example 1: Names of students with
marks > 80
3.15 JOINS IN XQUERY
UQ. Define Join. Explain types of joins in SQL with
example. (Q.
5(A), S-22, 6 Marks)
Result
Definition
A Join in XQuery is a process of combining data
from two or more XML documents (or XML
elements) based on a common attribute or element
FLWOR Example 2 : Return name and marks in
value (such as an ID or name). It is similar to SQL
custom XML
joins used in relational databases.
Purpose
To relate and merge information from different
XML structures.
Commonly used in data integration tasks where
data is distributed across multiple documents.
How it works:
Joins are implemented using multiple for clauses
Result and a where clause to match conditions.
Scenario Example
Imagine we have two XML documents:
students.xml
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-21)
3.15.1 Types of Joins in SQL
marks.xml UQ. Enlist any four types of join.
(Q. 1(E), W-22, 2 Marks)
There are several types of joins in SQL, and each
returns different results depending on how the tables
are related:
1. INNER JOIN
Description: Returns only those records that have
matching values in both tables.
Use Case: When you want to find data that is
common to both tables.
Example
XQuery Join Example
Result: Only employees who are assigned to a
department will appear.
2. LEFT JOIN (or LEFT OUTER JOIN)
Description: Returns all records from the left
table, and the matched records from the right
Output table. If no match is found, NULL is returned
from the right side.
Use Case: When you want all records from the
left table, even if there's no match in the right.
Example
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-22)
Result : All employees are shown, even those who are Example
not assigned to a department (with NULL in
dept_name).
3. RIGHT JOIN (or RIGHT OUTER JOIN)
Description : Returns all records from the right
table, and the matched records from the left table.
If no match is found, NULL is returned from the Result : If there are 5 students and 3 courses, the result
left side. will have 15 rows.
6. SELF JOIN
Use Case : When you want all records from the
right table, even if they have no match in the left. Description: A self join is a regular join, but the
table is joined with itself.
Example
Use Case: Useful for comparing rows within the
same table.
Example
Result : All departments are listed, even if no
employee is assigned to them.
4. FULL JOIN (or FULL OUTER JOIN)
Description : Returns all records when there is a
match in either the left or right table. Non- Result : Shows each employee with their respective
matching rows from both tables will have NULL manager's name.
values.
Use Case : When you want to retrieve all data 3.16 NESTED QUERIES IN XQUERY
from both tables, regardless of whether a match
exists. UQ. Give syntax and example for Nested query
Example (Q. 1(G), S-22, 2 Marks)
Definition
A Nested Query in XQuery refers to the use of
one XQuery expression inside another, typically
within the return clause of a FLWOR expression.
Purpose
Result : All employees and all departments, including
To handle hierarchical XML data
those with no match.
To query related elements under each result of the
Note : Not all database systems (e.g., MySQL) support
outer query
FULL OUTER JOIN directly. You may simulate it using
UNION. Helps in grouping data and generating structured
5. CROSS JOIN outputs
How it works
Description : Returns the Cartesian product of
the two tables. That means every row of the first The outer query retrieves a main set of nodes,
table is combined with every row of the second. and for each node, the inner query retrieves
Use Case : Used for generating combinations or related sub-elements or values.
testing. Nested queries involve placing one FLWOR
expression inside another. Useful when querying
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-23)
hierarchical data or when one query depends on
the result of another.
EXAMPLE
#THIS IS A CODE
<university>
<student>
<name>John</name>
<rollno>101</rollno>
<marks>
<subject>Math</subject>
<score>88</score>
</marks>
</student> 3.17 SORTING IN XQUERY
<student>
<name>Jane</name>
Definition
<rollno>102</rollno>
Sorting in XQuery refers to the arrangement of
<marks>
XML data in a specific order (ascending or
<subject>Math</subject>
descending) based on one or more elements or
<score>92</score>
attributes.
</marks>
</student> It is primarily done using the order by clause in a
</university> FLWOR expression.
#END OF CODE Purpose of Sorting in XQuery
XQuery with Nested Query To display XML data in a desired sequence
To organize results for reports, tables, or user
interfaces
To support logical ordering for analysis (e.g.,
highest scores, alphabetical names)
Output
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-24)
Syntax of Sorting in XQuery
This sorts first by department (ascending), then by
salary (descending).
3.18 FUNCTIONS AND TYPES
Default order
If not specified, the default is ascending. Here is a detailed explanation of Functions and
Types in XQuery, suitable for theoretical
Sorting Functions in XQuery
understanding and academic use:
XQuery provides a set of functions and
expressions to perform sorting. Sorting is not done Functions in XQuery
using a specific "function" like in some programming Definition
languages, but via the order by clause in combination
Functions in XQuery are reusable blocks of logic
with path expressions and value extraction.
that perform specific operations on XML data. They
Common usage help in simplifying queries and improving modularity
and readability.
Types of Functions in XQuery
Examples Type Description Example
Example 1: Sort students by name Predefined in fn:count(),
Built-in
XQuery, available fn:substring(),
Functions
for use directly fn:upper-case()
User- Custom functions declare function
defined created by users for local:getName()
This will return students alphabetically by name. Functions specific tasks {...}
Example 2: Sort students by marks in Commonly Used Built-in Functions
descending order Function Purpose Example
Counts number
fn:count() count(/students/student)
of items
Adds numeric sum(/students/student/
fn:sum()
values marks)
Calculates avg(/students/student/
fn:avg()
average marks)
This will return students with highest marks first. fn:substring(
Extracts part of a substring("XQuery", 2,
Multiple Sorting Keys str, start,
string 3) → Que
length)
You can sort by multiple elements:
xquery Checks if string
contains("hello", "ell")
fn:contains() contains
CopyEdit → true()
substring
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications
Advance Database Management(MSBTE) (Object Based Database & XML) ….Page No. (3-25)
Function Purpose Example Type Description Example Value
Checks if string xs:string Text string "John"
fn:starts-
starts with given starts-with("hello", "he")
with() xs:integer Whole number 100
text
xs:decimal Decimal number 99.5
fn:upper- Converts text to
upper-case("xquery") →
case() / uppercase/lowerc xs:boolean Boolean value true(), false()
XQUERY
lower-case() ase
xs:date Date format 2025-04-04
fn:distinct- Removes distinct-values((10, 20,
xs:time Time format 14:30:00
values() duplicates 10)) → 10 20
Sequence Types
User-defined Function Example:
XQuery treats all data as sequences (even single
items).
Syntax Meaning
item? Zero or one occurrence
item* Zero or more occurrences
item+ One or more occurrences
Example
xs:integer+ means one or more integers.
Node Types
Types in XQuery
Definition Type Description
Types in XQuery refer to the data types that element() Any XML element
define the kind of values (string, integer, boolean, etc.)
attribute() Any attribute
that variables, functions, or elements can hold or
return. text() Text node
Basic Atomic Types
Any node (element, text, comment,
node()
etc.)
Chapter Ends…
(MSBTE-K-SCHEME-Sem 5-Comp/IT)-Academic Year 2025-2026) Tech-Neo Publications