0% found this document useful (0 votes)
10 views23 pages

XML: Features, Applications, and Schema

XML (Extensible Markup Language) is a W3C standard for storing and sharing data that is both human-readable and machine-readable. Key features include extensibility, self-descriptiveness, platform independence, and strict syntax rules. XML is widely used in web services, configuration files, document storage, and data exchange between systems.

Uploaded by

shubhammbrahaman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views23 pages

XML: Features, Applications, and Schema

XML (Extensible Markup Language) is a W3C standard for storing and sharing data that is both human-readable and machine-readable. Key features include extensibility, self-descriptiveness, platform independence, and strict syntax rules. XML is widely used in web services, configuration files, document storage, and data exchange between systems.

Uploaded by

shubhammbrahaman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Introduction to XML (Extensible Markup

Language)
XML stands for Extensible Markup Language, a standard created by W3C for storing,
transporting, and sharing data across different systems. It is both human-readable and machine-
readable.

Key Features of XML

1. Extensible:
Users can create their own tags (unlike HTML which has predefined tags).
2. Self-descriptive:
XML describes data with meaningful tags.
Example:

<student>
<name>Rahul</name>
<roll>101</roll>
</student>

3. Platform & Language Independent:


XML data can be used in any programming language or operating system.
4. Structured Data Format:
Represents hierarchical data using nested tags.
5. Supports Data Transportation:
Widely used in web services (SOAP, REST), APIs, configuration files, and databases.
6. Strict Syntax Rules:
o Every tag must have a closing tag
o Tags are case-sensitive
o Proper nesting is required
o A single root element must be present
7. Separation of Data from Presentation:
XML stores data only; formatting is done using XSL / XSLT.

Components of XML

 Elements: Represent data


 Attributes: Provide additional information
 Prolog: Declares XML version
 <?xml version="1.0" encoding="UTF-8"?>
 Comments:
<!-- This is a comment -->
Applications of XML

 Web services (SOAP)


 Configuration files (Android Manifest, [Link])
 Data exchange between systems
 Document storage (DOCX, PPTX use XML internally)
 RSS feeds
 Databases (XML databases)

XML documents form a tree structure that starts at "the


root" and branches to "the leaves".

The XML Tree Structure

An Example XML Document


The image above represents books in this XML:

<?xml version="1.0" encoding="UTF-8"?>


<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

Uses of XML
XML (Extensible Markup Language) is widely used for data storage, data transfer,
configuration, communication, and document structuring. Its platform-independent and self-
descriptive nature makes it suitable across many technologies.

✅ 1. Data Storage and Data Exchange

 XML is used to store and share data between heterogeneous systems.


 Independent of software, hardware, or programming language.
 Commonly used by APIs, databases, and enterprise systems.

✅ 2. Web Services (SOAP & REST)


 SOAP uses XML to format request and response messages.
 Ensures secure and structured data exchange over networks.

✅ 3. Configuration Files

Many software and frameworks use XML for configuration:

 Android: [Link], layout XML files


 Java EE: [Link]
 .NET: [Link]
 Spring Framework: [Link]

✅ 4. Document File Formats

Modern document formats are XML-based, including:

 DOCX (MS Word)


 PPTX (PowerPoint)
 XLSX (Excel)
 ODT, SVG, etc.

✅ 5. Data Representation on Web

Used in:

 RSS feeds
 Atom feeds
 [Link] (used by Google for indexing websites)

✅ 6. Databases

 XML databases store data in hierarchical structure.


 Relational DBs like SQL Server and Oracle support XML columns.

✅ 7. Communication Between Applications


 Middleware, message brokers, and enterprise systems use XML for structured
communication.
 Widely used in banking, telecom, healthcare, etc.

✅ 8. Graphic and UI Representation

 Scalable Vector Graphics (SVG) uses XML to describe images.


 Android UI layouts use XML for screen design.

✅ 9. Software Development Tools

 Build tools use XML configuration


o Maven → [Link]
o Ant → [Link]

Key Components of XML


XML documents are made up of several basic components that define structure and
meaning.
The main components are:

 ✅ 1. XML Declaration
 Appears at the top of the XML file.
It tells the version and encoding used.
 Example:
 <?xml version="1.0" encoding="UTF-8"?>

 ✅ 2. Elements
 Elements are the main building blocks of XML.
They contain data.
 Example:
 <name>Riya</name>

 ✅ 3. Attributes
 Attributes give extra information about elements.
 Example:
 <student id="101">
 Here id is an attribute.

 ✅ 4. Tags
 Tags are the names inside < >.
They mark the beginning and end of elements.
 Example:
<name> is a start tag, </name> is an end tag.

 ✅ 5. Text Content
 The actual data inside an element.
 Example:
In <roll>21</roll>, the text content is 21.

 ✅ 6. Root Element
 Every XML document must have one single root element that contains all other
elements.
 Example:
 <student> ... </student>

 ✅ 7. Comments
 Used to write notes for developers.
 Example:
 <!-- This is a comment -->

 ✅ 8. Processing Instructions
 Used to give instructions to applications.
 Example:
 <?xml-stylesheet type="text/xsl" href="[Link]"?>

DTD in XML (Document Type Definition)


1. What is DTD?

DTD (Document Type Definition) is a set of rules that defines the structure, elements,
attributes, and order of data in an XML document.
It is used to validate whether an XML document follows the specified format.
2. Why DTD is used?
✔ To ensure the XML file is structured correctly
✔ To enforce allowed elements, sequence, nesting, and attributes
✔ Helpful for data exchange between applications
✔ Prevents errors in XML by validating before processing

3. Types of DTD
(a) Internal DTD

Defined inside the XML document.

(b) External DTD

Stored in a separate .dtd file and linked to XML using SYSTEM or PUBLIC identifiers.

4. Internal DTD – Example


<?xml version="1.0"?>
<!DOCTYPE student [
<!ELEMENT student (name, roll, branch?)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT roll (#PCDATA)>
<!ELEMENT branch (#PCDATA)>
<!ATTLIST student id ID #REQUIRED>
]>
<student id="S1">
<name>Riya</name>
<roll>101</roll>
<branch>CSE</branch>
</student>

Explanation:

 #PCDATA means simple text.


 branch? means branch element is optional.
 id attribute must be provided (#REQUIRED).
5. External DTD – Example
XML file ([Link])
<?xml version="1.0"?>
<!DOCTYPE student SYSTEM "[Link]">
<student id="S1">
<name>Riya</name>
<roll>101</roll>
</student>

External DTD file ([Link])


<!ELEMENT student (name, roll)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT roll (#PCDATA)>
<!ATTLIST student id ID #REQUIRED>

6. DTD Syntax Elements


(i) Element Declaration
<!ELEMENT elementName contentType>

Examples:

<!ELEMENT name (#PCDATA)> <!-- text -->


<!ELEMENT student (name, roll)> <!-- sequence -->
<!ELEMENT colors (color+)> <!-- one or more -->

(ii) Attribute Declaration


<!ATTLIST elementName attributeName attributeType defaultType>

Types:

 CDATA – normal text


 ID – unique value
 IDREF – reference to an ID
 #REQUIRED – must appear
 #IMPLIED – optional
 #FIXED – fixed value
(iii) Special Operators

 ? → optional element (0 or 1)
 * → zero or more
 + → one or more

7. Advantages of DTD
 Easy and simple to write
 Fast validation
 Supported by almost all XML parsers
 Good for simple document structures

8. Limitations of DTD
 Not written in XML (separate syntax)
 No data types (everything is text)
 Cannot validate numbers, date formats, ranges
 No namespace support
 Not suitable for complex/modern applications

XML Schema (XSD) – Explained in Detail


1. What is XML Schema?

XML Schema (commonly called XSD – XML Schema Definition) is a powerful, XML-based
language used to define the structure and data types of an XML document.

It checks:

 What elements should appear


 What attributes are allowed
 Data types (string, integer, date, boolean, etc.)
 Order of elements
 Constraints like min/max values, patterns, restrictions

XML Schema is more powerful than DTD because it supports data types and namespaces.
2. Why XML Schema? (Purpose)
XML Schema is used to:
✔ Validate XML documents
✔ Define data types (integer, date, boolean)
✔ Define constraints (length, range, pattern)
✔ Ensure data is accurate and consistent
✔ Support complex structures needed in web services

3. XML Schema File Extension


Schema files are stored as:

*.xsd

4. Basic Structure of an XML Schema


<xs:schema xmlns:xs="[Link]

<xs:element name="student">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="roll" type="xs:int"/>
<xs:element name="branch" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>

</xs:schema>

Explanation:

 xs:schema → root element of XSD


 xs:element → declares XML elements
 xs:complexType → element contains children or attributes
 xs:sequence → order of child elements
 minOccurs="0" → optional
 xs:attribute → declares attributes
5. XML Schema Data Types
(a) Simple Data Types
 xs:string
 xs:int
 xs:decimal
 xs:date
 xs:boolean
 xs:time
 xs:duration

(b) User-Defined Data Types

You can restrict or extend existing types.

Example: Mobile number pattern

<xs:simpleType name="MobileNumberType">
<xs:restriction base="xs:string">
<xs:pattern value="\d{10}"/>
</xs:restriction>
</xs:simpleType>

6. Complex Types in XML Schema


Complex types define elements that contain other elements or attributes.

Example:

<xs:complexType name="StudentType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="roll" type="xs:int"/>
</xs:sequence>
</xs:complexType>

Used as:

<xs:element name="student" type="StudentType"/>


7. Occurrence Constraints
Control how many times an element appears.

Attribute Meaning

minOccurs="0" Optional

minOccurs="1" Required

maxOccurs="1" Only once

maxOccurs="unbounded" Any number of times

Example:

<xs:element name="course" type="xs:string" maxOccurs="unbounded"/>

8. Facets (Restrictions)
Used to set limits on values.

Examples:

Length restriction
<xs:restriction base="xs:string">
<xs:minLength value="3"/>
<xs:maxLength value="15"/>
</xs:restriction>

Range for numbers


<xs:restriction base="xs:int">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="100"/>
</xs:restriction>

9. XML Schema vs DTD


Feature DTD XML Schema (XSD)

Syntax Not XML XML-based

Data types No Yes

Constraints Weak Strong

Namespaces No Yes

Reusability Limited Very good

Industry usage Older Modern standard

10. XML Document Example Validated by


XSD
<student id="S1"
xmlns:xsi="[Link]
xsi:noNamespaceSchemaLocation="[Link]">

<name>Riya</name>
<roll>101</roll>
<branch>CSE</branch>
</student>

11. Advantages of XML Schema


✔ Supports strong data types
✔ Written in XML
✔ Supports namespaces
✔ Precise validation
✔ Allows inheritance, reuse, modules
✔ Used in Web Services (SOAP, WSDL)

12. Disadvantages
❌ More complex than DTD
❌ Verbose and lengthy
❌ Difficult for beginners

Using XML with Applications


XML is widely used for data storage, data exchange, configuration, and communication
between systems.

Below are key applications and how XML is used in them.

(A) XML with Web Applications

1. Data Exchange Between Server and Client

 XML is used to send and receive data in web services.


 Earlier AJAX used XML (Asynchronous JavaScript and XML).
 Still used in SOAP-based systems.

2. Configuration in Web Apps

Example: Java web apps use [Link] for deployment configuration.

(B) XML with Databases

1. Storing and Retrieving Data

Databases like Oracle and SQL Server support:

 XML data type


 XML indexing
 XML queries (XQuery, XPath)

Example:

<employee id="101">
<name>Ravi</name>
<salary>50000</salary>
</employee>

2. Data Interchange
XML is used to export/import between:

 Oracle ↔ MySQL
 Excel ↔ Database
 ERP ↔ CRM systems

(C) XML with Java

Java provides JAXP APIs:

 DOM Parser
 SAX Parser
 StAX

Use cases:

 Reading XML
 Writing XML
 Transforming with XSLT

Example:

DocumentBuilderFactory factory = [Link]();

(D) XML with .NET

.NET includes classes like:

 XmlDocument
 XmlReader
 XmlWriter

Used for configuration and data transfer.

(E) XML in Web Services

1. SOAP (Simple Object Access Protocol)

 Uses XML to structure request/response messages.


 Used in banking, government, enterprise services.
2. WSDL (Web Services Description Language)

 Defines web service operations.


 Written in XML.

(F) XML in Android

Android apps use XML for:

 Layout design (activity_main.xml)


 App configuration ([Link])
 Resource files (colors, strings, themes)

Example:

<TextView
android:id="@+id/title"
android:text="Hello"/>

(G) XML in Office Applications

 MS Word, Excel, PowerPoint internally use XML.


 .docx, .xlsx, .pptx = zipped XML files.
 Used for structured storage of documents.

(H) XML in Configuration Files

Many systems use XML for settings:

 Maven [Link]
 Spring [Link]
 Tomcat [Link]

Example:

<configuration>
<port>8080</port>
</configuration>
XML, XSL and XSLT.
1. XML (Extensible Markup Language)
What is XML?

XML is a markup language used to store and transport data.


It is self-descriptive, meaning the data describes itself through tags.

Key Features

 Platform independent
 Human-readable
 Supports nested structures
 Self-descriptive tags
 Used for data exchange between systems

Example
<student>
<name>Riya</name>
<roll>101</roll>
<branch>CSE</branch>
</student>

✅ 2. XSL (Extensible Stylesheet Language)


What is XSL?

XSL is a family of technologies used to display, transform, and style XML documents.

XSL contains three parts:

1. XSLT – For transforming XML


2. XPath – For navigating inside XML
3. XSL-FO – For formatting output (PDF, printed pages)

Purpose of XSL
 To format XML for display (HTML, PDF)
 To convert XML into another XML structure
 To apply templates and styling rules

✅ 3. XSLT (Extensible Stylesheet Language


Transformations)
What is XSLT?

XSLT is a powerful language used to transform XML documents into:

 HTML
 Another XML
 Plain text
 PDF (via XSL-FO)

XSLT is rule-based:

 Uses templates
 Uses XPath to select elements
 Applies transformations

⭐ How XSLT Works


1. XML is the source data.
2. XSLT is the transformation stylesheet.
3. XSLT processor (browser or parser) applies rules from XSLT to XML.
4. Output can be HTML/XML/text.

Diagram (conceptually):

XML + XSLT → (Processor) → Output (HTML/XML/Text)

🔹 XSLT Basic Structure


<xsl:stylesheet version="1.0"
xmlns:xsl="[Link]
<xsl:template match="/">
<!-- Output goes here -->
</xsl:template>

</xsl:stylesheet>

📝 Example — XML to HTML using XSLT


XML File
<student>
<name>Riya</name>
<roll>101</roll>
</student>

XSLT File ([Link])


<xsl:stylesheet xmlns:xsl="[Link]
version="1.0">
<xsl:template match="/">
<html>
<body>
<h2>Student Details</h2>
<p>Name: <xsl:value-of select="student/name"/></p>
<p>Roll: <xsl:value-of select="student/roll"/></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Linking XML with XSLT


<?xml-stylesheet type="text/xsl" href="[Link]"?>

🧠 XPath in XSLT
Used to select nodes in XML.

Examples:

 Select element → /student/name


 Select all items → //item
 Select attributes → @id
 Conditions → student[roll > 100]
🟦 XSLT Elements (Important for Exam)
XSLT Tag Purpose

<xsl:template match=""> Defines a rule

<xsl:value-of select=""> Displays value

<xsl:for-each select=""> Looping

<xsl:apply-templates> Apply matching templates

<xsl:if> Conditional

<xsl:choose> Switch-case style

<xsl:sort> Sorting

🟩 XSLT Example: Loop Through XML List


XML:
<books>
<book>Java</book>
<book>Python</book>
<book>XML</book>
</books>

XSLT:
<xsl:for-each select="books/book">
<p><xsl:value-of select="."/></p>
</xsl:for-each>

📌 Advantages of XML + XSLT


XML

 Standard data storage format


 Platform and language independent
 Easy to read and parse

XSL/XSLT

 Separates data (XML) from presentation (HTML/PDF)


 Powerful transformation capabilities
 Widely used in web services

1. Introduction to XSL
XSL (eXtensible Stylesheet Language) is a family of languages used to transform and format
XML documents.
It consists of three main parts:

1. XSLT (XSL Transformations)


o Used to transform XML into HTML, text, or another XML document.
2. XPath (XML Path Language)
o Used inside XSLT to locate and select nodes in XML.
3. XSL-FO (XSL Formatting Objects)
o Used for formatting XML for output (PDF, print layout).

Purpose of XSL:

 Display XML data in a human-readable format


 Convert XML to web pages (HTML)
 Extract, rearrange, and filter XML data
 Transform XML into other structured formats

2. XML Transformation – Simple Example


XML File: [Link]
<students>
<student>
<name>Rahul</name>
<age>22</age>
</student>
<student>
<name>Sanjay</name>
<age>21</age>
</student>
</students>
XSL File: [Link]
<?xml-stylesheet type="text/xsl" href="[Link]"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="[Link]

<xsl:template match="/students">
<html>
<body>
<h2>Student List</h2>
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<xsl:for-each select="student">
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="age" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

Output (HTML Page Generated):


Student List
-------------------------
Name | Age
-------------------------
Rahul | 22
Sanjay | 21

3. XSL Elements (Important for Exams)


XSL Element Purpose
<xsl:stylesheet> / <xsl:transform> Root element of XSLT file
<xsl:template>
Defines how a matched XML element is
displayed
<xsl:value-of> Extracts and displays node value
<xsl:for-each> Loop through elements (like items in a list)
<xsl:if> Conditional formatting
<xsl:choose>, <xsl:when>,
<xsl:otherwise>
Multi-condition logic
XSL Element Purpose
<xsl:apply-templates> Applies templates to XML nodes
<xsl:sort> Sorts output
<xsl:attribute> Dynamically creates an HTML/XML attribute

4. Transforming XML With XSLT (How It


Works)
Step 1: Create XML

Contains raw data.

Step 2: Create XSLT stylesheet

Defines how XML should be displayed or transformed.

Step 3: Link XML to XSLT

In XML header:

<?xml-stylesheet type="text/xsl" href="[Link]"?>

Step 4: Load XML in browser or processor

The browser applies the transformation and shows formatted output.

You might also like