0% found this document useful (0 votes)
10 views

Unit-III

The document provides an overview of XML (Extensible Markup Language), highlighting its characteristics, differences from HTML, and its structure. It explains XML's role in data storage and transport, its use of user-defined tags, and the importance of XML parsers and DTDs (Document Type Definitions). Additionally, it discusses XML namespaces to avoid name conflicts and outlines key components such as elements, attributes, and comments.

Uploaded by

tejaskohad07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Unit-III

The document provides an overview of XML (Extensible Markup Language), highlighting its characteristics, differences from HTML, and its structure. It explains XML's role in data storage and transport, its use of user-defined tags, and the importance of XML parsers and DTDs (Document Type Definitions). Additionally, it discusses XML namespaces to avoid name conflicts and outlines key components such as elements, attributes, and comments.

Uploaded by

tejaskohad07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

WEB TECHNOLOGY AND

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)

XML stands for eXtensible Markup Language


XML is a markup language much like HTML
XML was designed to store and transport data
XML was designed to be self-descriptive
XML is a W3C Recommendation
This note, is a note to Tove from Jani, stored as XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
It has sender information
It has receiver information
It has a heading
It has a message body

But still, the XML above does not DO anything. XML is just information wrapped in tags.
XML Does Not Use Predefined Tags

• The XML language has no predefined tags.


• The tags in the example above (like <to> and <from>) are not
defined in any XML standard. These tags are "invented" by the
author of the XML document.

• 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:

XML was designed to carry data - with focus on what data is

HTML was designed to display data - with focus on how data looks

XML tags are not predefined like HTML tags are


XML Simplifies Things
 XML simplifies data sharing
 XML simplifies data transport
 XML simplifies platform changes
 XML simplifies data availability
• Many computer systems contain data in incompatible formats. Exchanging data
between incompatible systems (or upgraded systems) is a time-consuming task
for web developers. Large amounts of data must be converted, and incompatible
data is often lost.
• XML stores data in plain text format. This provides a software- and hardware-
independent way of storing, transporting, and sharing data.
• XML also makes it easier to expand or upgrade to new operating systems, new
applications, or new browsers, without losing data.
• With XML, data can be available to all kinds of "reading machines" like people,
computers, voice machines, news feeds, etc.
An Example XML Document
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
XML Tree Structure
• XML documents are formed as element trees.
• An XML tree starts at a root element and branches from the root to child elements.
• All elements can have sub elements (child elements):

<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

• The following code shows the syntax for XML declaration


• <?xml version="version_number,"
encoding="character_encoding" standalone="yes_or_no" ?>
XML Comments

• Comments are optional. Adding comments to a document can


help you comprehend it better.
• <?xml version="1.0" encoding="utf-8"?> <!-- This is XML
Declaration-->
XML Tags and Elements
Except for declarations, tags work in pairs. An opening tag and a closing tag make
up each tag pair
<> is used to enclose tag names. The start and end tags for a tag pair
must be identical, except that the end tag must have / after the <.
<employee>
<firstname>John</firstname>
<lastname>Doe</lastname>
<title>Engineer</title>
<division>Materials</division>
</employee>
In the above example, employee, firstname, lastname, title and division are tags.
Tag names are also referred to as elements.
XML Attributes

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

XML Namespaces provide a method to avoid element name conflicts.


Name Conflicts
In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from
different XML applications.
This XML carries HTML table information:
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
This XML carries information about a table (a piece of furniture):
<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements
have different content and meaning.A user or an XML application will not know how to handle these differences
Solving the Name Conflict Using a Prefix
Name conflicts in XML can easily be avoided using a name prefix.
This XML carries information about an HTML table, and a piece of furniture:
< h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>

<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.

The XML DOM


All XML elements can be accessed through the XML DOM.
Books.xml
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author> Example
<year>2005</year> txt = xmlDoc.getElementsByTagName("title")
<price>30.00</price>
[0].childNodes[0].nodeValue;
</book>
<book category="children">
The XML DOM is a standard for how to get, change, add, and delete XML
<title lang="en">Harry Potter</title> elements.
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
This code retrieves the text value of the first <title> element in an XML document:
XML DTD
• What is a DTD?
DTD stands for Document Type Definition.
A DTD defines the structure and the legal elements and attributes of an XML document.
An XML document with correct syntax is called "Well Formed".
An XML document validated against a DTD is both "Well Formed" and "Valid".
Valid XML Documents
• A "Valid" XML document is "Well Formed", as well as it conforms to the rules of a DTD:
• <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>Tove</to>
<from>Jim</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
• The DOCTYPE declaration above contains a reference to a DTD file. The
purpose of a DTD is to define the structure and the legal elements and
attributes of an XML document
• Note.dtd:
• <!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
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"
Tip: #PCDATA means parseable character data.
Use of XML
XML is used for mainly these purposes:
 Data transfer: XML can be used to create APIs that allow different applications
to exchange data over the Internet.
 Formatting documents: XML can be used to define the structure and
appearance of documents, such as web pages, ebooks, and reports.
 Creating layouts: XML can be used to describe the layout of graphical user
interfaces, such as menus, buttons, and windows.
 XML is used in many aspects of web development.
 XML is often used to separate data from presentation.
XML key components
1. XML declaration:
a. The XML declaration is an optional component that specifies the
version of XML used in the document, as well as the character encoding.
b. It is typically placed at the beginning of an XML document and
enclosed in angle brackets.
2. Elements:
a. Elements are the building blocks of an XML document.
b. They define the structure and meaning of the data in the document.
c. Each element is enclosed in angle brackets and consists of an
opening tag, content, and a closing tag.
d. For example, <title>The Catcher in the Rye</title> is an element
with the tag name "title" and the content "The Catcher in the Rye".
3. Attributes:
a. Attributes provide additional information about an element.
b. They are specified within the opening tag of an element and
consist of a name and a value separated by an equals sign.
c. For example, <book isbn="0-316-76953-3"> specifies the
attribute "isbn" with the value "0-316-76953-3".
4. Text:
a. Text is the content within an element that is not enclosed in other
tags.
b. For example, in <title>The Catcher in the Rye</title>, "The
Catcher in the Rye" is the text content of the "title" element.
5. Comments:
a. Comments are used to provide annotations and explanations
within an XML document.
b. They are enclosed in <!-- and --> and are ignored by XML
processors.

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

An XML Schema describes the structure of an XML document, just like a


DTD.

An XML document with correct syntax is called "Well Formed".

An XML document validated against an XML Schema is both "Well


Formed" and "Valid".
XML Schema is an XML-based alternative to DTD
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
The Schema above is interpreted like this:
<xs:element name="note"> defines the element called "note"
<xs:complexType> the "note" element is a complex type
<xs:sequence> the complex type is a sequence of elements
<xs:element name="to" type="xs:string"> the element "to" is of
type string (text)
<xs:element name="from" type="xs:string"> the element "from"
is of type string
XML Schemas
XML Schemas are More Powerful than DTD
 XML Schemas are written in XML
 XML Schemas are extensible to additions
 XML Schemas support data types
 XML Schemas support namespaces
What are the Applications of XML Tools?
• Extensible Markup Language (XML) is the underlying technology in thousands of applications,
from simple productivity tools like word processing to book publishing software and even
complex application configuration systems.

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

As a data type, XML is supported by a wide range of programming languages.


You can easily write programs in other languages that work directly with XML
files with this support.
XML (eXtensible Markup Language) is a versatile tool that can be used in
various applications for different purposes. Here are some common ways to use
XML in applications:
1. Data Exchange: XML is often used to exchange data between different
systems, such as web services and APIs. It provides a standard format that
can be easily parsed and processed by different applications.
2. Configuration Files: Many applications use XML files for configuration
settings. These files are easy to read and update, making them ideal for
storing application settings and preferences.
3. Database Interactions: XML can be used to store and retrieve data from databases. It
can also be used to generate SQL queries or to describe the structure of database tables.
4. Document Storage: XML is often used for storing documents, such as HTML, XHTML,
and other types of structured documents. It allows for easy formatting and presentation of
data.
5. Data Serialization: XML can be used to serialize objects, making it easy to store and
transmit complex data structures. This is particularly useful in applications that need to
save or transfer object states.
6. Communication Protocols: Some communication protocols, such as SOAP (Simple
Object Access Protocol), use XML to encode messages sent over a network. This ensures
that the messages are platform-independent and can be understood by different systems.
7. Integration with Web Technologies: XML is often used in conjunction with other web
technologies, such as XSLT (Extensible Stylesheet Language Transformations) for
transforming XML documents, and XPath for navigating through XML documents.

You might also like