Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Acropolis Institute of Technology &

Research, Indore
www.acropolis.in
Department of Computer Science and
Engineering

Unit-IV
XML

By: Gajendra Chouhan

December 13, 2023 gajendrachouhan@acropolis.in 2


About the Lecture
❖ Introduction to XML
❖ Uses of XML
❖ Understand simple XML
❖ Introduction to XML key components
❖ DTD

December 13, 2023 gajendrachouhan@acropolis.in 3


XML

December 13, 2023 gajendrachouhan@acropolis.in 4


XML : Introduction
❖ XML is a mark-up language which is used for storing and
transporting data.

❖ XML doesn’t depend on the platform and the software


(programming language).

❖ You can write a program in any language on any platform


(Operating System) to send, receive or store data using XML.

December 13, 2023 gajendrachouhan@acropolis.in 5


XML Declaration Examples
1. XML declaration with no parameter:
<?xml>
2. XML declaration with version definition:
<?xml version=”1”>
3. XML declaration with all parameters defined:
<?xml version=”1” encoding=”UTF-8” standalone=”no” ?>
4. XML declaration with all parameters defined in single quotes:
<?xml version=’1’ encoding=’iso-8859-1’ standalone=’no’ ?>

December 13, 2023 gajendrachouhan@acropolis.in 6


XML syntax
<?xml version="1.0" encoding="UTF-8"?>
(A prologue specifies the XML version as well as the character encoding)
<message>
<to> ABC </to>
<from> XYZ </from>
<msg>Welcome to XML Programming</msg>
</message>

December 13, 2023 gajendrachouhan@acropolis.in 7


Example
<?xml version="1.0" encoding="UTF-8"?> <title lang="en">Harry Potter</title>
<bookstore> <author>J K. Rowling</author>
<book category="novel"> <price>295.99</price>
<title lang="en">Two States</title> </book>
<author>Chetan Bhagath</author> <book category="web">
<year>2005</year> <title lang="en">Learning XML</title>
<price>300.00</price>
<author>Erik T. Ray</author>
<year>2003</year>
</book>
<price>339.95</price>
<book category="children">
</book>
<year>2005</year>
</bookstore>
December 13, 2023 gajendrachouhan@acropolis.in 8
Use of XML
❖ JavaScript usage has now extended to mobile app development, desktop app
development, and game development. This opens many opportunities for you
as Javascript Programmer.
❖ Due to high demand, there is tons of job growth and high pay for those who
know JavaScript. You can navigate over to different job sites to see what having
JavaScript skills looks like in the job market.
❖ Great thing about Javascript is that you will find tons of frameworks and
Libraries already developed which can be used directly in your software
development to reduce your time to market.
❖ There could be 1000s of good reasons to learn Javascript Programming. But one
thing for sure, to learn any programming language, not only Javascript, you just
need to code, and code and finally code until you become expert.
December 13, 2023 gajendrachouhan@acropolis.in 9
Features of XML
❖ It represents an extensible markup language.
❖ There are no predefined XML tags. You must define your
personalized tags.
❖ XML was created to transport data, not to display that data.
❖ The mark-up code of XML is simple for a human to understand.
❖ The structured format, on the other hand, is simple to read and
write from programmers.
❖ XML, like HTML, is an extensible markup language.

December 13, 2023 gajendrachouhan@acropolis.in 10


HTML and XML
❖XML is extensible, while HTML is not.
❖Both XML and HTML are markup languages.
❖XML was invented to backlog and convey data, while HTML
is meant for publishing and visualizing data.
❖HTML tags are more defined than XML tags.

December 13, 2023 gajendrachouhan@acropolis.in 11


XML Key Components
❖ XML Base
 Override the default URI of a document or any part of a document starting at a
given element;
❖ Stylesheets in XML
 Associate an XSLT transformation with an XML document, for example so that a
Web browser will format it;
❖ XLink
 A vocabulary for hypertext in XML;
❖ xml:id
 Identify an XML attribute or element as containing a name that can be used as
a unique identifier within a document
December 13, 2023 gajendrachouhan@acropolis.in 12
Cont..
❖ XInclude
 Include all or part of other text or XML documents, or duplicate part of the current XML
document;
❖ XPointer
 This is a framework for different ways to point into XML documents, and is used by XLink;
❖ XForms
 A more powerful cousin to HTML forms;
❖ XML Events, XHTML Modularization
 Specifications primarily relating to the use of XML in Web browsers or other DOM- based
systems;
❖ XML Fragments
 Listed here only for completeness; this specification is not in widespread use.

December 13, 2023 gajendrachouhan@acropolis.in 13


Displaying XML with XSLT
❖ XSLT (eXtensible Stylesheet Language Transformations) is the
recommended style sheet language for XML.
❖ XSLT is far more sophisticated than CSS. With XSLT you can
add/remove elements and attributes to or from the output file.
❖ XSLT uses XPath to find information in an XML document.

December 13, 2023 gajendrachouhan@acropolis.in 14


XML Example
<? <food>
xml version="1.0" encoding="UTF- <name>Strawberry Belgian Waffles</name>
8"?> <price>$7.95</price>
<breakfast_menu> <description>Light Belgian waffles covered
with strawberries and whipped
<food> cream</description>
<name>Belgian Waffles</name> <calories>900</calories>
<price>$5.95</price> </food>
<description>Two of our famous <food>
Belgian Waffles with plenty of real <name>Berry-Berry Belgian Waffles</name>
maple syrup</description> <price>$8.95</price>
<calories>650</calories> <description>Light Belgian waffles covered
</food> with an assortment of fresh berries and
December 13, 2023 whipped cream</description> 15
gajendrachouhan@acropolis.in
Contd….
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>

<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash
browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
December 13, 2023 gajendrachouhan@acropolis.in 16
Transform the XML document with XSLT
<?xml version="1.0" encoding="UTF-8"? <xsl:value-of select="price"/>
> </div>
<html xsl:version="1.0" xmlns:xsl="http: <div style="margin-left:20px;margin-
//www.w3.org/1999/XSL/Transform"> bottom:1em;font-size:10pt">
<body style="font-family:Arial;font- <p>
size:12pt;background-color:#EEEEEE"> <xsl:value-of select="description"/>
<xsl:for-each select="breakfast_menu/ <span style="font-
food"> style:italic"> (<xsl:value-
<div style="background- of select="calories"/> calories per
color:teal;color:white;padding:4px"> serving)</span>
<span style="font- </p> </div></xsl:for-each></body><
weight:bold"><xsl:value- /html>
of select="name"/> - </span>
December 13, 2023 gajendrachouhan@acropolis.in 17
DTD
❖ The purpose of a DTD (Document Type Definition) is to define the structure
of an XML document. It defines the structure with a list of legal elements:

<!DOCTYPE note [
<!ELEMENT note ( to, from, heading, body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
December 13, 2023 gajendrachouhan@acropolis.in 18
Cont….
❖ The DTD above is interpreted like this:
▪ !DOCTYPE note defines that the root element of the document is note
▪ !ELEMENT note defines that the note element must contain the
elements: "to, from, heading, body"
▪ !ELEMENT to defines the to element to be of type "#PCDATA“
▪ !ELEMENT from defines the from element to be of type "#PCDATA"
▪ !ELEMENT heading defines the heading element to be of type
"#PCDATA"
▪ !ELEMENT body defines the body element to be of type "#PCDATA"

December 13, 2023 gajendrachouhan@acropolis.in 19


Using XML with Application
The Extensible Markup Language (XML) is a subset of SGML designed
to enable generic SGML to be served, received, and processed on the
Web easily and efficiently.
Because its format is not fixed, XML enables you to design your own
customized markup languages with which to create various types of
documents.
In the IDE, XML documents are represented by XML nodes.
The IDE provides tools to assist you in creating, editing, checking, and
validating the various XML document types it supports.

December 13, 2023 gajendrachouhan@acropolis.in 20


Cont…
❖ The IDE supports several types of XML documents, including:
▪ Cascading Style Sheet. A CSS provides a simple mechanism for
formatting and adding style to HTML and XML documents.
▪ Document Type Definition. A DTD describes the grammar that can be
used in an XML file and indicates the valid arrangement of the file's
tags. It can exist as a prologue to an XML file (internal DTD) or as a
separate file (external DTD).
▪ Parsed Entity Objects. Parsed entity nodes represent parsed entity
(.ent) files. If several of your XML documents refer to a single piece of
information, you can store that information in a parsed entity. Any
changes you make to the parsed entity are then automatically reflected
in all of the documents that reference it.
December 13, 2023 gajendrachouhan@acropolis.in 21
Cont…
❖ The IDE supports several types of XML documents, including:
▪ XML Catalogs. XML catalogs provide mapping information that
maps an external entity in an XML document to the actual
location of the document being referenced. You can use a catalog
to redirect mappings for an external entity, such as a DTD or XML
file, to a different location.
▪ XSL Style sheet. XSL style sheets define transformation rules for
your XML documents. You can perform an XML transformation to
transform the data in an XML document into the output of your
choice, such as formatted HTML or a text file.

December 13, 2023 gajendrachouhan@acropolis.in 22


Acknowledgement and Disclaimer
 This presentation is the culmination of content extracted from a variety of sources namely
lecture notes, presentations, books and websites. In many cases, the identity of the original
contributor is not available with the author. The author wish to take this opportunity to thank
individual contributors of these extracts.
 The author wishes to record that this presentation is solely used for education purpose and
copyright violation if any, is unintentional. The author is willing to remove any such extract
from the presentation with immediate effect.
 The materials available at referred sites are not maintained by Acropolis Institute and we are
not responsible for the contents thereof.
 All trademarks, service marks, and trade names used in this presentation are the marks of the
respective owner(s). Gajendra
Chouhan
Asst. Professor, CSE
Acropolis Institute(AITR), Indore
December 13, 2023 gajendrachouhan@acropolis.in gajendrachouhan@acropolis.in
23
Q&A
December 13, 2023 gajendrachouhan@acropolis.in 24
THANKS
December 13, 2023 gajendrachouhan@acropolis.in 25

You might also like