Introduction to XML updated.pptx
Introduction to XML updated.pptx
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
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 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
for developers is to exchange data between incompatible systems over the Internet.
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.
Different applications can access your data, not only in HTML pages, but also fromXML data sources.
WSDL: Web Services Description Language. WSDL for describing available web services
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).
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
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
<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
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)
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>