Notes Lec 2.docx

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

XML Languages & And Applications

Extensible Markup Language (XML) is a markup language that is a core part of web
technology and is used to store and share data across systems:

• Data storage
XML is a way to store data in a format that can be searched, shared, and stored.
• Data exchange
XML allows for the exchange of information between systems such as websites,
databases, and third-party applications.
• Data definition
XML is a flexible way to create information formats and define data. Users can define
their own tags to meet their needs.
• Data sharing
XML is platform-independent and language-independent, so it can be processed by
any modern language on any operating system.
• Data presentation
XML is used in web services to format and exchange data, such as user information,
product details, and transactions.
XML is similar to HTML, but it is more universal and does not have predefined
tags. XML documents are stored as American Standard Code for Information
Interchange (ASCII) files and can be edited using any text editor.

Difference between HTML & XML:

HTML: (Hyper Text Markup Language) is used to create web pages and web
applications. It is a markup language. By HTML we can create our static page. It is used
for displaying the data not to transport the data.
HTML is a combination of Hypertext and Markup language. Hypertext defines the link
between the web pages. A markup language is used to define the text document within the
tag which defines the structure of web pages. This language is used to annotate (make
notes for the computer) text so that a machine can understand it and manipulate text
accordingly

Syed Iqbal Haider Kazmi


XML Languages & And Applications
Example:
<!DOCTYPE html>
<html>

<head>
<title>WEB TECHNOLOGY</title>
</head>

<body>
<h1 style="color: green;">
WEB TECHNOLOGY
</h1>
<p>
A Computer Science Subject
</p>
</body>

</html>

XML: (Extensible Markup Language) is a versatile markup language designed for


carrying and storing data. It allows users to define their custom tags, making it highly
flexible. XML is often used for data interchange between different systems, enabling the
sharing of structured information.
XML is also used to create web pages and web applications. It is dynamic because it is
used to transport the data not for displaying the data. The design goals of XML focus on
simplicity, generality, and usability across the Internet. It is a textual data format with
strong support via Unicode for different human languages. Although the design of XML
focuses on documents, the language is widely used for the representation of arbitrary data
structures such as those used in web services.
Example:

<?xml version = "1.0"?>

<contactinfo>

<address category = "college">

<name>FG College</name>

<College>WEB Technology</College>

<mobile>2345456767</mobile>

</address>

</contactinfo>

Syed Iqbal Haider Kazmi


XML Languages & And Applications

Difference between HTML and XML


HTML XML

It was written in 1993. It was released in 1996.

HTML stands for Hyper Text Markup XML stands for Extensible Markup
Language. Language.

HTML is static in nature. XML is dynamic in nature.

It was developed by Worldwide Web


It was developed by WHATWG.
Consortium.

It is neither termed as a presentation nor a


It is termed as a presentation language.
programming language.

XML provides a framework to define


HTML is a markup language.
markup languages.

HTML can ignore small errors. XML does not allow errors.

It has an extension of .html and .htm It has an extension of .xml

HTML is not Case sensitive. XML is Case sensitive.

HTML tags are predefined tags. XML tags are user-defined tags.

There are limited number of tags in HTML. XML tags are extensible.

HTML does not preserve white spaces. White space can be preserved in XML.

HTML tags are used for displaying the XML tags are used for describing the data
data. not for displaying.

In HTML, closing tags are not necessary. In XML, closing tags are necessary.

HTML is used to display the data. XML is used to store data.

Syed Iqbal Haider Kazmi


XML Languages & And Applications
HTML XML

XML carries the data to and from the


HTML does not carry data it just displays it.
database.

IN XML, the objects are expressed by


HTML offers native object support.
conventions using attributes.

XML document size is relatively large as


HTML document size is relatively small. the approach of formatting and the codes
both are lengthy.

An additional application is not required for DOM(Document Object Model) is required


parsing of JavaScript code into the HTML for parsing JavaScript codes and mapping
document. of text.

Some of the tools used for HTML are:


Some of the tools used for XML are:
• Visual Studio Code
• Oxygen XML
• Atom
• XML Notepad
• Notepad++
• Liquid Studio
• Sublime Text

XML Features
As a markup language and a file format, XML offers a multitude of features that make it
versatile for encoding, storing, and transporting data:

• Human and machine readability: XML data is stored in plain text format, facilitating
interpretation by both humans and machines.

• Self-descriptive: XML documents are self-descriptive. The tags in XML provide a general
idea of the type of data they contain.

• Extensible: XML, true to its name, permits users to define their own tags, thereby offering
flexibility to represent a wide range of data structures.

• Platform and language independence: XML data can be processed by any system that
can process XML, making it an excellent choice for data interchange.

In a way, XML itself does not achieve anything. Instead, it serves as a means to structure
and describe data. Developers then use this structured data in various applications for
different purposes, such as data exchange, configuration files, message passing in
distributed systems, and much more.
Syed Iqbal Haider Kazmi
XML Languages & And Applications

XML namespaces:
XML namespaces prevent naming conflicts between elements and attributes in XML
documents, especially when various XML vocabularies are joined or elements with the
same name come from different sources.

Default Namespace Declaration:


Default Namespace Declaration in XML namespaces assigns a default namespace to all
un-prefixed components inside a given scope. This signifies that elements without a prefix
are presumed from the given namespace. The "xmlns" element is used to declare the
default namespace.

Syntax:
<root xmlns="http://example.com/ns">
<child>Content</child>
</root>

Example
<?xml version="1.0" encoding="UTF-8"?> <--Unicode Transformation Format-8-bit -->
<library
xmlns="http://example.com/library">
<book>
<title>XML Basics</title>
<author>John Doe</author>
</book>
<book>
<title>Advanced XML</title>
<author>Jane Smith</author>
</book>
</library>

Syed Iqbal Haider Kazmi


XML Languages & And Applications

Prefixed Namespace Declaration


In XML namespaces, the Prefixed Namespace Declaration method assigns a prefix to a
namespace URI. This allows elements and attributes from that namespace to be identified
with the specified prefix. Prefixed namespaces are especially beneficial when items from
different namespaces appear in the same XML document.
Syntax:
<root xmlns:prefix="http://example.com/ns">
<prefix:child>Content</prefix:child>
</root>
Example:
<?xml version="1.0" encoding="UTF-8"?>
<catalog
xmlns:bk="http://example.com/books"
xmlns:auth="http://example.com/authors">
<bk:book>
<bk:title>XML Basics</bk:title>
<auth:author>John Doe</auth:author>
</bk:book>
<bk:book>
<bk:title>Advanced XML</bk:title>
<auth:author>Jane Smith</auth:author>
</bk:book>
</catalog>

Syed Iqbal Haider Kazmi


XML Languages & And Applications

XSLT stands for Extensible Stylesheet Language Transformation. It is an


integrated concept with an XML. It is not used for Visual effects. However, it is used for
extracting or transforming data from XML and using the combination of HTML and CSS to
format them. It also has dynamic properties, where you can do iteration and conditional
statements upon a static XML file.
Uses of XSLT
• XSLT can be used for organizing large trees of XML elements, so anyone can read it.
• It is used to transform XML – to – HTML
• Since XSLT is doing the transformation on the client side. The server has to do the less
work.
XSLT Transform Syntax Declaration
• Since it is an XML file it starts with an XML declaration.
• <? xml version = "1.0" ?>
• This is the first root tag that you define within this XSLT document and it has to be
given the version. In order to access all the properties, attributes, and features you
have to include this namespace. We include a namespace xmlns and as a parameter
we pass xsl with the value “https://www.w3.org/1999/XSL/Transform”

<xsl : template match="/" >
[action]
<xsl : template>

Now XSLT document can contain one or more templates. Templates actually define the
rules that you want to place for the elements. The template has an attribute called match.
In the attribute, we try to give the Xpath expression [ match = “/” ] which tries to match
the pattern in the source XML document.
Document structure of XSLT
<? xml version = "1.0" ?>
<xsl : stylesheet version = "1.0" xmlns : xsl =
"https://www.w3.org/1999/XSL/Transform">
<xsl : stylesheet>
<xsl : template match="/" >
[action]
<xsl : template>
<xsl : template match="/" >
[action]
<xsl : template>
--------------------
</xsl : stylesheet>

Syed Iqbal Haider Kazmi


XML Languages & And Applications
Program that displays movie names using XSLT
• We create one file called movie.xml. We declare the version of XML as discussed
above. After that we include the stylesheet called movie.xsl
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "movie.xsl"?>
• We define our movies names followed by its attribute moviename, genre and year.
We pass movieId as the Xpath expression in the movie tag. All the movies details are
enclosed within <list></list> tag.
<list>
<movie movieId = "01">
<moviename>Harry Potter and the Philosopher's Stone</moviename>
<genre>Fictional</genre>
<year>2001</year>
</list>
Example:
<!-- file name- movie.xml-->
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "movie.xsl"?>
<list>
<movie movieId = "01">
<moviename>Harry Potter and the Philosopher's Stone</moviename>
<genre>Fictional</genre>
<year>2001</year>
</movie>
<movie movieId = "02">
<moviename>Harry Potter and the Chamber of Secrets</moviename>
<genre>Fictional</genre>
<year>2002</year>
</movie>
<movie movieId = "03">
<moviename>Harry Potter and the Prisoner of Azkaban </moviename>
<genre>Fictional</genre>
<year>2004</year>
</movie>
<movie movieId = "04">
<moviename>Harry Potter and the Goblet of Fire</moviename>
<genre>Fictional</genre>
<year>2005</year>
</movie>
<movie movieId = "05">
<moviename>Harry Potter and the Order of the Phoenix</moviename>
<genre>Fictional</genre>
<year>2007</year>
</movie>
<movie movieId = "06">
<moviename>Harry Potter and the Half-Blood Prince</moviename>
<genre>Fictional</genre>
<year>2009</year>
Syed Iqbal Haider Kazmi
XML Languages & And Applications
</movie>
<movie movieId = "07">
<moviename>Harry Potter and the Deathly Hallows – Part 1</moviename>
<genre>Fictional</genre>
<year>2010</year>
</movie>
<movie movieId = "08">
<moviename>Harry Potter and the Deathly Hallows – Part 2</moviename>
<genre>Fictional</genre>
<year>2011</year>
</movie>
</list>

<!-- file name movie.xsl -->


<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2>Harry Potter Movie Series</h2>
<table border = "1">
<tr bgcolor = "#81B0EE">
<th>Movie Id</th>
<th>Movie Name</th>
<th>Genre</th>
<th>Year</th>
</tr>
<xsl:for-each select="class/movie">
<tr>
<td><xsl:value-of select = "@movieId"/></td>
<td><xsl:value-of select = "moviename"/></td>
<td><xsl:value-of select = "genre"/></td>
<td><xsl:value-of select = "year"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Syed Iqbal Haider Kazmi


XML Languages & And Applications

What is DTD in XML?


DTD is a document-type definition. DTD contains a set of rules that control the structure
and elements of XML files. When any XML file refers DTD file, it validates against those
rules. DTD has validated elements and attributes that are defined inside the DTD
document. It serves as a formal specification that outlines the elements, attributes, and
their relationships within an XML document. They specify what elements can appear, their
order, which attributes they can have, and what data types those attributes can contain.
Features of DTD:
• Comprises structure, attributes, and elements of XML file
• Validate XML files that help maintain data integrity and consistency.
• Checks vocabulary of XML for grammatical rules
• DTDs have a relatively simple and human-readable syntax
• Allows to specify default values for attributes
• Support mixed content models
Types of DTD: There are two ways to specify XML DTD.
1. Internal DTD: Inside the document
2. External DTD: Specified in a separate document and linked later

Syntax
<!DOCTYPE element DTD identifier
[
declaration #1
declaration #2
.
.
declaration #n
] >

The start of the document has a doctype delimiter. DOCTYPE has two types of
declarations:
1. External subset declaration (optional)
2. Internal subset declaration (optional)
While the internal declaration is specified in the document itself as a part of DOCTYPE,
the external one is to be mentioned in a separate file. To refer to the external subset,
public identifiers are used. An element instructs to parse the document from the root
element. DTD identifier is the path to a system file or URL that points to any file on the
internet. An optional list of entity declarations is enclosed inside square brackets ([]).

Syed Iqbal Haider Kazmi


XML Languages & And Applications
Advantages of using DTD:
• Ensures consistency of XML data
• Simple and easy to understand
• Widely supported by XML parsers and applications
• Easily interchange data between systems
• Lightweight with limited file sizes and processing requirements.
• Allows the definition of entity references for reusable content and markup
Disadvantages of using DTD:
• DTDs lack built-in documentation mechanisms
• Limited support for complex data types and advanced validation rules
• DTDs do not provide native support for XML namespaces
• More complex content models.
• Do not offer built-in support for data types.
• XML Schema Definition (XSD) replaced DTDs due to its more robust features and
capabilities.
Where we can use the DTD:
• XML documents: Most commonly used to define the structure and constraints of XML
documents
• Web Development: Web development to specify the structure of HTML (Versions 4.01
and earlier)
• Configuration Files: Used to define the structure and rules for configuration file
• RSS and Atom Feeds: Define the structure of RSS (Really Simple Syndication) and
Atom feeds
• Data Interchange Format : define the structure of XML based protocols of web
services (SOAP) or data exchange formats like XML-RPC

XSD:
XSD stands for XML Schema Definition, it is like a detailed plan for organizing and
checking XML documents. It is a versatile language that provides a framework to structure
and validate XML data effectively. it is a set of guidelines and limitations designed to
ensure the reliability, consistency, and correctness of data stored in XML files. it specifies
what elements, attributes, and data types are allowed in an XML document, serving as a
rulebook that XML documents must adhere to. It also empowers developers to define
constraints, like setting the acceptable value ranges for elements and enforcing specific
formatting rules for data. XML Schema Definition (XSD) files are saved with the .xsd file
extension.

Where XSD is used?


XSD has huge applications here are some of them where we can use them.
• XML files: XSD files are used to validate that XML files conform to a certain format.
• Data exchange: XSD files can be used to describe the structure and content of data
that is exchanged between systems.
Features of XSD
• XSD lets you examine XML documents to see if they follow specific rules about how
they’re organized and what kind of data they contain.

Syed Iqbal Haider Kazmi


XML Languages & And Applications
• It also allows you to create detailed data arrangements with things like nested
elements, attributes, and different data types.
• Helps you define different kinds of data, like words, numbers, and dates, in XML
documents. It allows you to decide how this data should be structured.
• You can also decide on default values and rules for elements and attributes in your
XML documents.
• XSD is good for working with various names in XML, which is useful when you’re
creating rules for complex XML files with lots of different names.

Advantages of XSD
• XSD schemas are like user-friendly guides for XML data. They tell developers how the
data should be structured and the rules it must follow, all without needing extra
explanations.
• Helps different systems and apps work together smoothly by creating a common
language for organizing and checking data.
• Lets you set automatic values for missing parts in your data. It’s like having
placeholders ready, so if some information is missing, it gets filled in with the default
values. This keeps your data consistent.
• XSD checks data to make sure it’s correct, stopping any mistakes from getting into
XML documents.
• Provides different data types, like primitive data types, derived data types, and user-
defined data types. This variety helps keep data organized and dependable.
Disadvantages of XSD
• Creating and maintaining XSD schemas can be complex, especially for intricate XML
structures.
• Understanding and working with XSD can be challenging for those new to XML and
related technologies.
• Data validation using XSD can introduce a performance overhead, especially for large
XML documents.
Use Cases of XSD
• XSD is like a blueprint for how messages in web services should be arranged, it make
sure that the data shared between systems is neatly organized and error free.
• Helps in linking XML data with database layouts, making it easier to move data
between XML based systems and databases. It’s like a bridge that connects them.
• Lots of computer programs use setup files written in XML, and XSD helps explain how
these files should be organized and what rules they need to follow.
• XSD is really important for checking and making sure XML documents are correct,
especially in places like finance or healthcare, where getting the data right is super
important.

XSD is a powerful and versatile language that allows the users to define and validate the
XML data. It also has some disadvantages and challenges that users should aware of but
the features, advantages and uses cases of XSD are so much useful for working with XML
data that we can simply ignore the disadvantages. Nevertheless, It is an essential
technology for creating and painting the reliable, consistent, and correct XML data.

Syed Iqbal Haider Kazmi


XML Languages & And Applications
XHTM MP:
XHTML Mobile Profile (XHTML MP) is a hypertextual computer language
designed for mobile phones and other devices with limited resources. It was
developed by the Open Mobile Alliance (OMA) in collaboration with the World
Wide Web Consortium (W3C):
• Features
XHTML MP is a subset of XHTML 1.1 that includes features tailored for mobile
devices. It's derived from XHTML Basic 1.0 by adding XHTML Modules.
• Benefits
XHTML MP allowed users to browse the same site from a PC and a mobile phone. It
also made it easier to use existing development tools geared towards HTML and
XHTML 1.0.
• Superseded by XHTML Basic 1.1
XHTML Basic 1.1 became a W3C Recommendation in July 2008, superseding XHTML-
MP 1.2.

Some fundamentals of XHTML MP include: XHTML documents must be well


formed, Tags must be closed, and Elements must be properly nested.

XHTML MP is similar to "regular" XHTML in that it allows the use of Cascading


Style Sheets (CSS)

Advantages of XHTML MP
The greatest advantage brought by XHTML MP is that developers can now use the
same technologies for the development of both web sites and WAP sites. This
benefits WAP application development in the following ways:

• If you are familiar with web technologies such as HTML, XHTML, and CSS,
you can start developing your WAP site almost immediately. If you are new to
the above web technologies and now you learn XHTML MP, you learn at the
same time how to write markup code for the web.
• The same development tools can be used to develop both web sites and WAP
sites. You can stick to your web development tools to build your mobile
Internet browsing application. This results in a lower development cost (no
need to buy new development tools) and a lower time investment (no need to
learn new development tools).
• Ordinary web browsers can be used to view your WAP site during the
development process. (You should test your WAP site with emulators and real
Syed Iqbal Haider Kazmi
XML Languages & And Applications
mobile phones before the final release, since the characteristics [e.g. screen
size, number of colors supported] of real mobile devices vary considerably.)
• HTML / XHTML pages on your web site can be converted to XHTML MP
documents with minor changes or even without any changes. (However, you
have to make sure that the layout of the HTML / XHTML pages looks nicely on
a small screen and that the file size does not exceed the maximum page size
of your targeted mobile devices.)
• It becomes easier to find a developer to join your mobile Internet application
development team, since there are plenty of web developers on the job
market.

Here are some other advantages of XHTML MP:

• XHTML MP supports WAP CSS, which enables the separation of content and
presentation in different files. As you all know, mobile devices have very
different characteristics such as screen sizes. The separation of the content
and the presentation means you can write the content once, and change the
style and layout to suit different mobile devices with various WAP CSS files.
• With XHTML MP and WAP CSS, you have more control over the presentation.
For example, you can control borders, backgrounds, margins, padding, etc.
You can also specify the font sizes, font families and font colors. Such features
are not available in WML 1.x.

Syed Iqbal Haider Kazmi

You might also like