Unit-III
Unit-III
MULTIMEDIA
UNIT-III
BCCA SEM-VI
BY
DR. REVATI BANGRE
Introduction
XML stands for Extensible Markup Language. It is a text-based
markup language derived from Standard Generalized Markup
Language (SGML).
XML tags identify the data and are used to store and organize the
data, rather than specifying how to display it like HTML tags,
which are used to display the data. XML is not going to replace
HTML in the near future, but it introduces new possibilities by
adopting many successful features of HTML.
Characteristics of XML
XML is extensible − XML allows you to create your own
self-descriptive tags, or language, that suits your application.
XML carries the data, does not present it − XML allows
you to store the data irrespective of how it will be presented.
XML is a public standard − XML was developed by an
organization called the World Wide Web Consortium (W3C)
and is available as an open standard.
What is XML? (In Short)
But still, the XML above does not DO anything. XML is just information wrapped in tags.
XML Does Not Use Predefined Tags
• HTML works with predefined tags like <p>, <h1>, <table>, etc.
• With XML, the author must define both the tags and the
document structure.
The Difference Between XML and HTML
XML and HTML were designed with different goals:
HTML was designed to display data - with focus on how data looks
<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).
• All elements can have text content (Harry Potter) and attributes (category="cooking").
The XML Tree Structure
XML Declaration
In the start tag, the attribute for an element is inserted after the tag name. For a single
element, you can add many attributes with distinct names.
• There are two main rules to define an attribute -
• Attribute values must be within quotes.
• An element cannot contain several attributes with the same name.
Consider the same example as above
<employee id="be129">
<firstname>John</firstname>
<lastname>Doe</lastname>
<title>Engineer</title>
<division>Materials</division>
</employee>
Here the “id” is an attribute specific to that employee.
XML Namespaces
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
XML Namespaces - The xmlns Attribute
When using prefixes in XML, a namespace for the prefix must be defined.
The namespace can be defined by an xmlns attribute in the start tag of an
element.The namespace declaration has the following syntax. xmlns:prefix="URI".
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="https://www.w3.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>
In the example above:
• The xmlns attribute in the first <table> element gives the h: prefix a
qualified namespace.
• The xmlns attribute in the second <table> element gives the f: prefix a
qualified namespace.
• When a namespace is defined for an element, all child elements with the
same prefix are associated with the same namespace.
• Namespaces can also be declared in the XML root element:
• <root xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="https://www.w3schools.com/furniture">
Note:
• The namespace URI is not used by the parser to look up
information.
• The purpose of using an URI is to give the namespace a
unique name.
• However, companies often use the namespace as a pointer
to a web page containing namespace information.
XML Parsers
• An XML parser is a software library or package that provides interfaces for client applications to work with an
XML document. The XML Parser is designed to read the XML and create a way for programs to use XML.
• XML parser validates the document and check that the document is well formatted.
• Let's understand the working of XML parser by the figure given below:
Types of XML Parsers
DOM (Document Object Model)
• A DOM document is an object which contains all the information of an XML document. It is composed like a tree
structure. The DOM Parser implements a DOM API. This API is very simple to use.
• Features of DOM Parser
• A DOM Parser creates an internal structure in memory which is a DOM document object and the client applications get
information of the original XML document by invoking methods on this document object.
• DOM Parser has a tree based structure.
• Advantages
• 1) It supports both read and write operations and the API is very simple to use.
• 2) It is preferred when random access to widely separated parts of a document is required.
• Disadvantages
• 1) It is memory inefficient. (consumes more memory because the whole XML document needs to loaded into memory).
• 2) It is comparatively slower than other parsers.
Types of XML Parsers
SAX (Simple API (Application Program Interface for XML)
• A SAX Parser implements SAX API. This API is an event based API and less intuitive.
Features of SAX Parser
• It does not create any internal structure.
• Clients does not know what methods to call, they just overrides the methods of the API and place his own code inside
method.
• It is an event based parser, it works like an event handler in Java.
• Advantages
• 1) It is simple and memory efficient.
• 2) It is very fast and works for huge documents.
• Disadvantages
• 1) It is event-based so its API is less intuitive.
• 2) Clients never know the full information because the data is broken into pieces.
DOM
• What is the DOM?
• The Document Object Model (DOM) defines a standard for accessing and manipulating documents:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows
programs and scripts to dynamically access and update the content, structure, and style of a document."
The HTML DOM defines a standard way for accessing and manipulating HTML documents. It presents an
HTML document as a tree-structure.
The HTML DOM
• All HTML elements can be accessed through the HTML DOM.
• This example changes the value of an HTML element with id="demo":
Example
<h1 id="demo">This is a Heading</h1>
<button type="button"
onclick="document.getElementById('demo').innerHTML = 'Hello World!'">Click Me!
</button>
XML DOM
• The XML DOM defines a standard way for accessing and manipulating XML documents. It presents an XML document as a tree-structure.
6. Processing instructions:
a. Processing instructions provide instructions to XML processors
for how to process the document.
b. They are enclosed in <? and ?> and typically provide
information about how to handle the document's content.
Overall, these components work together to define the structure
and meaning of data in an XML document.
XML Schema
1. Data transmission:
Data can be transferred using XML between two systems that store the same data in different
formats. Your website, for example, stores dates in MM/DD/YYYY format, whereas an accounting
system stores dates in DD/MM/YYYY format. Using XML, it can transfer data from the website to
the accounting system. Developers can create code that converts the following automatically:
XML conversion of website data
• Data conversion from XML to accounting system data
• Returning accounting system data to XML format
• Returning XML data to website data
2. Web-based applications:
The data on web pages are structured in XML. Other website technologies, such
as HTML, collaborate with XML to provide visitors with consistent and relevant
data. Consider an e-commerce website that sells clothing. Instead of showing all
clothes to all visitors, the website uses XML to create customized web pages
based on user preferences. It shows products from specific brands by filtering the
<brand> tag.
3. Documentation:
Any technical document's structural information can be specified using XML.
Other programs then process the document structure in order to present it in a
flexible manner. A paragraph, an item in a numbered list, and a heading, for
example, all have XML tags. Other types of software use these tags to
automatically prepare the document for uses such as printing and web
publishing.
Using XML With Application