0% found this document useful (0 votes)
3 views27 pages

Introduction to XML updated.pptx

The document provides an introduction to XML, discussing its structure, advantages, and disadvantages compared to HTML. It covers XML's role in data storage and transport, the use of DTDs for defining XML document structure, and XSLT for transforming XML documents. Key elements of XML and XSLT, along with examples, are also included to illustrate their functionalities.

Uploaded by

hhi175886
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
3 views27 pages

Introduction to XML updated.pptx

The document provides an introduction to XML, discussing its structure, advantages, and disadvantages compared to HTML. It covers XML's role in data storage and transport, the use of DTDs for defining XML document structure, and XSLT for transforming XML documents. Key elements of XML and XSLT, along with examples, are also included to illustrate their functionalities.

Uploaded by

hhi175886
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 27

Introduction to XML

UNIT II
Syllabus
XML: Comparing XML with HTML,
Advantages and Disadvantages of XML
Structure of an XML Document,
XML Entity References,
DTD,
XSLT: XSLT
Elements and Attributes - xsl:template, xsl:apply-templates, xsl:import, xsl:call-
template, xsl:include, xsl:element, xsl:attribute, xsl:attribute-set, xsl:value-of
Introduction to XML

Xml (extensible Markup Language) is a markup language.


XML is designed to store and transport data.
Xml was released in late 90’s. It was created to provide an easy to use
and store self-describing data.
XML DTD and XML Schema define rules to describe data
XML is not a replacement for HTML.
XML is designed to be self-descriptive.
XML is designed to carry data, not to display data.
XML tags are not predefined. You must define your own tags.
XML is platform independent and language independent.

A markup language is a modern system for highlight or underline a document.

Platform Independent and Language Independent


Comparing XML with HTML

HTML XML

HTML is used to display data and focuses on XML is a software and hardware independent tool
how data looks. used to transport and store data. It focuses on
what data is.
HTML is a markup language itself. XML provides a framework to define markup
languages.
HTML is not case sensitive. HTML is case sensitive.
HTML is a presentation language. XML is neither a presentation language nor a
programming language.
HTML is static because it is used to display XML is dynamic because it is used to transport
data data

HTML has its own predefined tags You can define tags according to use a closing
tags
Advantages and Disadvantages of XML
XML separates data from HTML
With XML, data can be stored in separate XML files. This way you can focus on using HTML/CSS for display and layout, and be sure that changes in the
underlying data will not require any changes to the HTML.

XML simplifies data sharing

XML data is stored in plain text format. This provides a software- and hardware-independent way of storing data.This makes it much easier to create

data that can be shared by different applications.

XML simplifies data transport

for developers is to exchange data between incompatible systems over the Internet.

XML simplifies Platform change

Upgrading to new systems (hardware or software platforms), is always time consuming. Large amounts of data must be converted and incompatible
data is often lost.

XML increases data availability

Different applications can access your data, not only in HTML pages, but also fromXML data sources.

XML can be used to create new internet languages

A lot of new Internet languages are created with XML.

XHTML: Extensible HyperText Markup Language

WSDL: Web Services Description Language. WSDL for describing available web services

RSS(Really Simple Syndication): languages for news feeds

SMIL(Synchronized Multimedia Integration Language )for describing multimedia for the web
Disadvantages

XML syntax is expansive and redundant compared to other text-based data transmission
formats such as JSON.
JSON stands for JavaScript Object Notation. It's a text-based format for storing and
exchanging data.
The redundancy in syntax of XML causes higher storage and transportation cost when the
volume of data is large.
XML document is less readable compared to other text-based data transmission formats
such as JSON.
XML doesn’t support array.
XML file sizes are usually very large due to its verbose nature, it is totally
dependent on who is writing it.
Structure of an XML Document
XML documents form a tree structure that starts at "the root" and branches to "the
leaves".
<root>
<child>
<subchild>.....</subchild>
</child>
</root>

The terms parent, child, and sibling are used to describe the relationships between
elements.Parents have children. Children have parents. Siblings are children on the
same level(brothers and sisters).

first line is the XML declaration. It defines the XML version1.0.


Next line shows the root element (college) of the document.
Inside that there is one more element (student).
Student element contains five branches named <firstname>, <lastname>, <contact>, <Email> and
<address>.<address> branch contains 3 sub-branches named <city>, <state> and <pin>.
XML Entity References

An entity reference is a group of characters used in text as a substitute for a


single specific character that is also a markup delimiter in XML.
Using the entity reference prevents a literal character from being mistaken for
a markup delimiter
For example, if an attribute must contain a left angle bracket (<), you can substitute the entity
reference "&lt;". Entity references always begin with an ampersand (&) and end with a semicolon
(;).
You can also substitute a numeric or hexadecimal reference. The entities
predefined in XML are identified in the following table.
Declaring entities:
You can declare entities in a DTD in the following format:
<!ENTITY name "text">
where name is the name of the entity and text is the referenced text that appears
where the entity is used.
Example

This example declares an entity named 'dotto' and uses it and the
predefined 'lt'
entity in an XML document:
DTD (Document Type Declaration)

The XML Document Type Declaration, commonly known as DTD, is a way to describe XML
language precisely.
DTDs check vocabulary and validity of the structure of XML documents against grammatical
rules of appropriate XML language.
An XML DTD can be either specified inside the document, or it can be kept in a separate
document and then liked separately.
Syntax:
The DTD starts with <! DOCTYPE delimiter.
An element tells the parser to parse the document from the specified
root
element.
DTD identifier is an identifier for the document type definition, which may
!>
be the path to a file on the system or URL to a file on the internet. If the DTD
is pointing to external path, it is called External Subset.
The square brackets [ ] enclose an optional list of entity declarations
called Internal Subset.
Internal DTD

A DTD is referred to as an internal DTD if


elements are declared within the XML
files.
To refer it as internal DTD, standalone
attribute in XML declaration must be set
to yes.( the declaration works
independent of an external source.)
External DTD

In external DTD elements are declared outside the XML file. They are accessed by
specifying the system attributes which may be either the legal .dtd file or a valid URL.
To refer it as external DTD, standalone attribute in the XML declaration must be set as no.
(declaration includes information from the external source.)

Types
You can refer to an external DTD by using
either system identifiers or public
identifiers.
System Identifiers
A system identifier enables you to specify the
location of an external file containing
DTD declarations. Syntax is as follows −
<!DOCTYPE name SYSTEM "address.dtd" [...]>

Public Identifiers
Public identifiers provide a mechanism to locate DTD
resources.
XSLT:
XSL stands for Extensible Stylesheet Language. It is a styling language for XML just like CSS is a
styling language for HTML.
XSLT stands for XSL Transformation. It is used to transform XML documents into other formats
(like transforming XML into HTML).
What is XSL
In HTML documents, tags are predefined but in XML documents, tags are not predefined. World
Wide Web Consortium (W3C) developed XSL to understand and style an XML document, which
can act as XML based Stylesheet Language. An XSL document specifies how a browser should
render an XML document.
An XSL document specifies how a browser should render an XML document.
How XSLT Works

The XSLT stylesheet is written in XML format. It is used to define the


transformation rules to be applied on the target XML document.
The XSLT processor takes the XSLT stylesheet and applies the transformation
rules on the target XML document and then it generates a formatted
document in the form of XML, HTML, or text format. At the end it is used by
XSLT formatter to generate the actual output and displayed on the
end-user.
Advantage of XSLT
XSLT provides an easy way to merge XML data into presentation because it applies user defined
transformations to an XML document and the output can be HTML, XML, or any other structured
document.
XSLT provides Xpath to locate elements/attribute within an XML document. So it is more
convenient way to traverse an XML document rather than a traditional way, by using scripting
language.
XSLT is template based. So it is more resilient to changes in documents than low level DOM and
SAX.
By using XML and XSLT, the application UI script will look clean and will be easier to maintain.
XSLT templates are based on XPath pattern which is very powerful in terms of performance to
process the XML document.
XSLT can be used as a validation language as it uses tree-pattern-matching approach.
You can change the output simply modifying the transformations in XSL files.
Create an XML file named employee.xml, having the following cod
Employee.xml

<?xml version = "1.0"?>

<class>

<employee id = "001">

<firstname>Aryan</firstname>

<lastname>Gupta</lastname>

<nickname>Raju</nickname>

<salary>30000</salary>

</employee>

<employee id = "024">

<firstname>Sara</firstname>

<lastname>Khan</lastname>

<nickname>Zoya</nickname>

<salary>25000</salary>

</employee>

<employee id = "056">

<firstname>Peter</firstname>

<lastname>Symon</lastname>

<nickname>John</nickname>

<salary>10000</salary>

</employee>

</class>
XSLT Elements
Element Description

apply-imports Applies a template rule from an imported style sheet


apply- Applies a template rule to the current element or to the current
templates element's child nodes
attribute Adds an attribute

attribute-set Defines a named set of attributes

Call template Call template name

comment Creates a comment node in the result tree

copy Creates a copy of the current node (without child nodes and

attributes)
copy-of Creates a copy of the current node (with child nodes and attributes)

decimal-format Defines the characters and symbols to be used when converting


numbers into strings, with the format-number() function
xsl:template

An XSL style sheet consists of one or more set of rules that are called
templates.
A template contains rules to apply when a specified node is matched.
The <xsl:template> element is used to build templates.
The match attribute is used to associate a template with an XML element. The
match attribute can also be used to define a template for the entire XML
document. The value of the match attribute is an XPath expression (i.e.
match="/" defines the whole document).
<xsl:apply-templates>

The <xsl:apply-templates> element applies a template rule to the current


element or to the current element's child nodes.
The <xsl:apply-templates> element applies a template to the current element
or to the current element's child nodes.
If we add a "select" attribute to the <xsl:apply-templates> element, it will
process only the child elements that matches the value of the attribute. We can
use the "select" attribute to specify in which order the child nodes are to be
processed.
xsl:import

The XSLT <xsl:import> element is used to import the content of one


stylesheet to another stylesheet.
The importing stylesheet has higher precedence over imported stylesheet.
xsl:call-template

The xsl:call-template element is used to invoke a template by name.


By invoke, we mean that the named template is called and applied to the
source document. If a template does not have a name, it cannot be
called by this element.
xsl:include

The <xsl:include> element is a top-level element that includes the contents


of one style sheet into another.
An included style sheet has the same precedence as the including style
sheet.
This element must appear as a child node of <xsl:stylesheet> or
<xsl:transform>.
xsl:element

The <xsl:element> element is used to create an element node in the output


document.
<xsl:attribute-set>

The <xsl:attribute-set> element creates a named set of attributes.


The attribute-set can be applied as whole to the output document.
End

You might also like