EXTENSIBLE
MARKUP
LANGUAGE
(XML)
INTRODUCTION TO XML
• What is XML?
• XML stands for eXtensible Markup Language
• XML is a markup language much like HTML
• XML was designed to store and transport data
• XML was designed to be self-descriptive
• Platform-independent and human-readable.
Key Features of XML
• Hierarchical structure with nested elements
• Uses tags to define elements and their
relationships
• Supports extensibility and flexibility
• Text-based format for easy readability and editing
XML VS HTML
XML (eXtensible Markup Language) and HTML
(Hypertext Markup Language) are both markup
languages, but they serve different purposes and have
different features.
XML is designed to store and transport data rather than
present it visually like HTML. XML allows you to define
your own tags and structure the data in a way that suits
your needs. It provides flexibility in representing complex
data hierarchies and relationships.
XML is a language-independent format, which means it
can be used with any programming language or platform
XML allows you to define your own tags and structure,
providing the ability to customize the data representation
according to your requirements , which makes it highly
extensible
XML can be easily integrated with other technologies like
databases, web services. It serves as a common format for
data exchange between these systems, enabling seamless
integration and communication.
However, it's important to note that HTML and XML
serve different purposes. HTML is primarily used for
web page rendering and presentation, while XML focuses
on data representation and exchange. In web
development, HTML is the standard for creating web
pages, while XML is commonly used for data storage,
configuration files, and other data-centric purposes.
SYNTAX OF XML:
XML is case-sensitive, and the elements, attributes, and values
should be properly closed and nested to form a valid XML
document.
XML (eXtensible Markup Language) has a specific syntax that
we need to follow when creating XML documents
Tags: XML documents are composed of tags, which enclose
elements and data. Tags are enclosed in angle brackets ("<" and
">"). There are two types of tags:
1. Start tags: They define the beginning of an element
and consist of the element name enclosed in angle
brackets ("<elementname>").
2. End tags: They define the end of an element and
consist of the element name preceded by a forward
slash enclosed in angle brackets
("</elementname>").
Elements: Elements are the building blocks of XML
documents. They consist of an opening tag, content (data
or child elements), and a closing tag. Elements can be
nested inside other elements to create a hierarchical
structure.
SYNTAX: <elementname>content</elementname>
Attributes: Attributes provide additional information
about an element. They are specified within the opening
tag of an element and consist of a name-value pair
<elementname
SYNTAX: attribute="value">content</elementname>
Comments: Comments allow you to add explanatory or
descriptive text within an XML document. They are
enclosed in "<!--" and "-->".
SYNTAX: <!-- This is a comment -->
XML Declaration: The XML declaration is optional but
often included at the beginning of an XML document. It
specifies the XML version being used and can also
contain encoding information.
<?xml version="1.0" encoding="UTF-8"?
SYNTAX:
>
XML - Documents
An XML document is a basic unit of XML information
composed of elements and other markup in an orderly package.
An XML document can contains wide variety of data. For
example, database of numbers, numbers representing molecular
structure or a mathematical equation.
<?xml version =
"1.0"?> <contact-info>
<name>Tanmay
Patil</name>
<company>TutorialsP
oint</company>
<phone>(011) 123-
4567</phone>
</contact-info>
XML - Documents
Document Prolog comes at the top of the document, before the
root element. This section contains −
• XML declaration
• Document type declaration
Document Elements
Section
Document Elements are the building blocks of XML. These
divide the document into a hierarchy of sections, each serving a
specific purpose.
The elements can be containers, with a combination of text and
other elements.
XML Namespaces
XML namespaces provide a way to avoid naming
conflicts when working with XML documents that
combine elements or attributes from different
vocabularies or sources. They enable the identification
and differentiation of elements and attributes with the
same names but from different namespaces
Namespace Declaration: The namespace declaration
associates a prefix with a namespace URI (Uniform
Resource Identifier) and is defined in the opening tag of
the XML document
xmlns:prefix="namespaceURI"
• xmlns is the reserved keyword used for
namespace declaration.
• prefix is a user-defined prefix that serves as a
shorthand for the namespace.
• namespaceURI is the unique identifier for the
namespace, typically a URL
Namespace Prefix: The prefix defined in the namespace
declaration is used as a shorthand for referencing
elements and attributes within that namespace
<prefix:elementName
attribute="value">content</prefix:elementName>
Qualified Name: A qualified name consists of the prefix
and the local name, separated by a colon. It uniquely
identifies an element or attribute within a specific
namespace.
prefix:localName
<?xml version="1.0" encoding="UTF-8"?>
<presentation
xmlns:p="http://example.com/presentation">
<p:metadata>
<p:title>Presentation Title</p:title>
Example: <p:author>John Doe</p:author>
<p:date>2023-05-16</p:date>
</p:metadata>
</presentation>
XML RECAP
STRUCTURED
FORMATTED
Common rules and syntax
XML SCHEMA
An XML Schema describes the structural framework or plan of an XML document.
The XML Schema language is also referred to as XML Schema Definition (XSD).
The purpose of an XML Schema is to define the legal building blocks of an XML
document:
• the elements and attributes that can appear in a document
• the number of (and order of) child elements
• data types for elements and attributes
• default and fixed values for elements and attributes
XML SCHEMA
DEFINITION
XML code <xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="class">
<?xml version="1.0" <xs:complexType>
encoding="UTF-8"?> <xs:sequence>
<xs:element name="student">
<class>
<xs:complexType>
<student>
<xs:sequence>
<firstname>Graham</
<xs:element type="xs:string"
firstname> name="firstname"/>
<xs:element type="xs:string"
<lastname>Bell</lastna name="lastname"/>
me> <xs:element type="xs:byte" name="age"/>
<age>20</age> </xs:sequence>
</student> </xs:complexType>
Link : </xs:element>
</class>
https://www.freeformatter.com/x </xs:sequence>
ml-formatter.html
</xs:complexType>
XML + CSS
XML document can be linked with a cascading stylesheet(CSS) to add
styles and look to the elements of XML.
XML
<?xml version="1.0" encoding="UTF- CSS
8"?>
cse{
<?xml-stylesheet href="style.css"
background-color: red;
type="text/css"?>
}
<cse>
name{
<student>
font-family: 'Courier New',
<name> poorab patel</name>
Courier, monospace;
<age>20</age>
font-size: xx-large;
<rollno> 101</rollno>
color: aqua;
</student>
}
<student>
age
<name> harsh nair</name>
{
<age>19</age>
color: yellow;
<rollno> 102</rollno>
}
</student>
XSLT
XSLT, Extensible Stylesheet Language
Transformations, provides the ability
to transform XML data from one
format to another automatically like
HTML, or text format.
Transformation can be done using XSL
which stands for EXtensible
Stylesheet Language. It is similar to
XML as CSS is to HTML. An XSL
document specifies how a browser
should render an XML document.
TRANSFORMATIONS
USING XML DATA TO MAKE HTML
DOCUMENT
<?xml version="1.0" encoding="UTF-8"?>
<class>
<student>
<firstname>Graham</
firstname>
<lastname>Bell</
lastname>
<nickname>Garry</
nickname>
</student>
<student>
<firstname>Albert</
firstname>
<lastname>Einstein</
lastname>
<nickname>Ally</
nickname>
</student>
<student>
<firstname>Thomas</
JSON - Introduction
• JSON stands for JavaScript Object Notation
• JSON is a text format for storing and transporting data
• JSON is "self-describing" and easy to understand
• Example - {"name":"John", "age":30, "car":null}
Properties of JSON:
• JSON is a lightweight data-interchange format
• JSON is plain text written in JavaScript object
notation
• JSON is used to send data between computers
• JSON is language independent *
JSON - syntax
JSON syntax is derived from JavaScript object
notation syntax:
• Data is in name/value pairs
• Data is separated by commas
• Curly braces hold objects
• Square brackets hold arrays
In JSON, values must be one of the following data
types:
4. an array
1. a string 5. a boolean
2. a number 6. null
3. an object
Thank
You!