SlideShare a Scribd company logo
XML
(eXtensible Markup Language)
Introduction:
• XML stands for eXtensible Markup Language and it is used
for storing and transferring data.
• XML doesn’t depend on the platform and the software
(programming language). i.e. we can able to write a program
in any language on any platform (Operating System) to send,
receive or store data using XML.
• XML is a simple document with the data, which can be used to
store and transfer data between any systems irrespective of
their hardware and software compatibilities.
• It is so much easier to read the data from XML and display it
on a GUI (graphical user interface) using markup language
like HTML.
HTML Vs XML
HTML(Hyper Text Markup Language) XML(eXtensible Markup Language)
HTML is not a case sensitive language XML is case sensitive language
HTML is mainly concerned with the
presentation of data
XML is mainly used for storing and
transporting the data
HTML is static XML is dynamic
In HTML the closing tag in optional In XML the closing tag is mandatory
HTML uses predefined tags such as <b>,
<br>, <img> etc.
XML uses the user-defined tags that we
create while writing the XML document.
HTML does not preserve white space. XML preserves white space.
HTML Attribute Values Quoting is
optional.
XML Attribute Values Must Always be
Quoted.
Simple XML document example
A XML document structure looks like this:
<root>
<child>
<subchild>.....</subchild>
</child>
<child>
<subchild>.....</subchild>
</child>
</root>
• <?xml version="1.0" encoding="UTF-8"?> is called XML Prolog.
• It is optional, however when we include it in the XML document, it
should always be the first line of the document. XML Prolog defines the
XML version and the encoding used in the XML document.
• The XML code can be written on a simple notepad and should be saved as
“filename.xml”.
Students.xml
<?xml version="1.0" encoding="UTF-8"?>
<students>
<student>
<num>527</num>
<name>Ravi</name>
<age>20</age>
</student>
<student>
<num>572</num>
<name>Dev</name>
<age>23</age>
</student>
</students>
• In the above XML document we have the details of the few students.
Here <students> is the root element, <student> is the child element and
num,name and age are sub-child elements.
Output:
XML Syntax
Root Element is mandatory in XML
• XML document must have a root element. A root element can
have child elements and sub-child elements.
• For example: In the following XML document, <message> is the
root element and <to>, <from>, <subject> and <text> are child
elements.
<?xml version="1.0" encoding="UTF-8"?>
<message>
<to>Durga</to>
<from>Madhu</from>
<subject>Message from teacher to Student</subject>
<text>You have an exam tomorrow at 10:00 AM</text>
</message>
XML Syntax Contd…
XML is case sensitive
XML is a case sensitive language.
For example:
<from>madhu</from>  This is valid
<from>Prasad</FROM>  This is invalid
• All letters of closing tag is in capital while all letters of opening
tag is in small, this is an example of invalid XML.
XML Prolog
<?xml version="1.0" encoding="UTF-8"?>
• This line is called the XML Prolog. It is an optional line, however
it should be the first line when you mention it. It specifies the
XML version and the encoding used in the XML document.
XML Syntax Contd…
Elements should not overlap
• All the elements in XML should be properly nested and they should not
overlap.
<class><teacher>Madhu</class></teacher> -->Wrong (Not nested properly)
<class><teacher>Durga</teacher></class> -->Correct (Correctly nested)
XML elements must have a closing tag
• All XML documents must have a closing tag.
<text category = message>hello</text> -->correct
<text category = message>hello -->wrong
Comments in XML
• This is how a comment should look like in XML document.
<!-- This is just a comment -->
XMLAttributes
• XML elements can have attributes. By the use of attributes we can
add the additional information about the element.
• XML attributes are a way to add additional data to the XML
element. Attributes contain data in form of name & value pairs.
• XML attributes are used to enhance the properties of the elements.
Note: XML attributes must always be quoted. We can use single or
double quote.
Example:
<book category="computers">
<price>1000rs</price>
<publisher>Tata McGraw Hill</publisher>
</book>
XMLAttributes Contd…
XML attributes vs XML Sub Elements:
• The Data can be stored in attributes or in child elements. But there are
some limitations in using attributes, over child elements.
Same information can be represented in two ways:
1st Way:
<book category="computers">
<price>1000rs</price>
<publisher>Tata McGraw Hill</publisher>
</book>
2nd Way:
<book>
<category>computers </category>
<price>1000rs</price>
<publisher>Tata McGraw Hill</publisher>
</book>
XMLAttributes Contd…
• In the first way category is used as an attribute and in the second
way category is used as an element.
• Both examples provide the same information but it is good practice
to avoid attribute in XML and use elements instead of attributes.
Because
• Attributes cannot contain multiple values but child elements can
have multiple values.
• Attributes cannot contain tree structure but child element can.
• Elements are easy to be handled by the programming language
compared to the attributes.
XML Validation
Document Type Definition
(DTD)
XML – Validation
• Validation is a process by which an XML document is validated.
• An XML document with correct syntax is known as valid XML
document.
Let‟s see few important rules to check for syntax errors.
• All XML documents must have a root element.
• XML is a case sensitive language so you should be careful with the
case while opening and closing tags.
• All XML tags must have a closing tag.
• XML attribute name should not be quoted while its value must be
quoted.
• There are two ways to check whether the XML document is valid.
1 XML DTD (Document Type Definition)
2 XML Schema
Document Type Definition (DTD)
• DTD stands for Document Type Definition. It is used to define
document structure with a list of legal elements and attributes.
• Document Type Definition (DTD) is a certain piece of code,
which can defines structure of XML document.
• Each DTD contains a list of elements, which specifies the rules
for structuring a given XML document.
• Each DTD specifies the relationship between root element, child
elements and sub child elements.
• An XML document is considered “well formed” and “valid” if it
is successfully validated against DTD.
Document Type Definition (DTD) Contd..
• DTD‟s are optional in XML, but recommended for clarity
purpose.
• DTD‟s can be declared internally (With in XML doc) and as an
external file (with in a separate file with “.dtd” extension).
Basic Building Blocks:
There are 4 building blocks to build a XML document with DTD.
those are
1.Tags
2.Elements
3.Attributes
4.Entities
Document Type Definition (DTD) Contd..
1. Tags:
– The XML allows the user to create own tags.Useally the tag
<tagname> is an Opening tag, </tagname> refers to its equivalent
closing tag.
Example:
<book>Let us C</book>
<author> Yashwant Kanetkar </ author >
– In XML the tags are case sensitive . And closing tag is mandatory.
– All the elements in XML should be properly nested and they
should not overlap.
Document Type Definition (DTD) Contd..
2. Elements in DTD:
– The DTD document is composed with various elements. These
elements are used to represent the tags in XML document.
Declaration:
<!ELEMENT name-of-element(context)>
– To declare an empty element
Syntax:
<!ELEMENT name-of-element(EMPTY)>
– To declare an element, this carries data
Syntax:
<!ELEMENT name-of-element(#PCDATA)>
(or)
<!ELEMENT name-of-element(#CDATA)>
Document Type Definition (DTD) Contd..
– To declare an element, this contains child elements
Syntax:
<!ELEMENT name-of-element(child-names)>
Examples:
<!ELEMENT student(id,name,age)>
<!ELEMENT name(#PCDATA)>
<!ELEMENT age(EMPTY)>
3.Attributes:
• These are used to provide the additional information along with
elements.
• In DTD, the attributes are declared by using “ATTLIST” Keyword.
Syntax:
<! ATTLIST name-of-element name-of-attribute
attribute-type [default-value]>
Document Type Definition (DTD) Contd..
• In the above syntax, the field „attribute-type‟ can specifies the
following pre-defined values.
• ID:It is a value which remains unique.
• CDATA: The value supplied here is nothing but character data.
• ENTITY: The value supplied in this case is nothing but an entity.
• In the same way, the filed „default-value‟ can specifies the following
pre-defined values.
 #REQUIRED: It means the value for the attribute is required.
 #IMPLIED: It means the attribute is not required.
 #FIXED: Here a fixed value is supplied.
 Default-value: It is a default value of given attribute.
Example:
<! ATTLIST student address CDATA #REQUIRED>
Document Type Definition (DTD) Contd..
4. Entities:
• Some markup elements can contain complex data; these types of
elements are called as Entities.
• These are used to create small piece of data which you want you use
repeatedly throughout your schema.
Syntax:
<! ENTITY name-of-entity “value”>
Example:
<! ENTITY Book “Web Technologies”>
Used as
<author> the &Book author is Uttam K Roy</author>
Document Type Definition (DTD) Contd..
• DTD‟s can be declared internally (With in XML doc) and as an
external file (with in a separate file with “.dtd” extension)
Example with external DTD:
• Create a DTD for a remainder; it has following remainder as root
element and child elements-heading, to, from, message.
“remainder.dtd”
<!ELEMENT remainder(heading,to,from,message)>
<!ELEMENT heading(#PCDATA)>
<!ELEMENT to(#PCDATA)>
<!ELEMENT from(#PCDATA)>
<!ELEMENT message(#PCDATA)>
Document Type Definition (DTD) Contd..
“remainder.xml”
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "remainder.dtd">
<remainder>
<heading>Final Remainder</heading>
<to>Mr.Madhu</to>
<from> Ravi Gupta</from>
<message> Date of joining is 5th Feb</message>
</remainder>
Output:
Document Type Definition (DTD) Contd..
Example with internal DTD:
“remainderdemo.xml”
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT remainder (heading,to,from,message)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT message (#PCDATA)>
]>
<remainder>
<heading>Final Remainder</heading>
<to>Mr.Madhu</to>
<from> Ravi Gupta</from>
<message> Date of joining is 5th Feb</message>
</remainder>
Document Type Definition (DTD) Contd..
Example:
• Create a DTD for a catalog of four stroke engine motorbikes where
each motor bike has the following child elements: make, model,
year, color, engine, chassis number and accessories. The engine
element has child elements those are – engine number, number of
cylinders, type of fuel. The accessories elements has the attributes
like disk break, auto start and radio, each of which required and has
the possible values ‘YES’ and ‘NO’ . Entities must be declared for the
names of the popular motorbike makes.
Document Type Definition (DTD) Contd..
“bikecatalog.dtd”
<!ELEMENT catalog (motorbike)*>
<!ELEMENT motorbike (make, model,year,color,engine, chasis_num, accessories)>
<!ELEMENT make (#PCDATA)>
<!ELEMENT model (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT color (#PCDATA)>
<!ELEMENT engine (engine_num,cylinder_num,fuel_type)>
<!ELEMENT engine_num (#PCDATA)>
<!ELEMENT cylinder_num (#PCDATA)>
<!ELEMENT fuel_type (#PCDATA)>
<!ELEMENT chasis_num (#PCDATA)>
<!ELEMENT accessories (#PCDATA)>
<!ATTLIST accessories diskbrake (Yes|No) #REQUIRED autostart (Yes|No)
#REQUIRED radio (Yes|No) #REQUIRED>
Document Type Definition (DTD) Contd..
<?xml version="1.0"?> “bikecatalog.xml”
<!DOCTYPE catalog SYSTEM "bikecatalog.dtd">
<catalog>
<motorbike>
<make>Hero</make>
<model>Glammur 120cc</model>
<year>2014</year>
<color>Red-Black</color>
<engine>
<engine_num>564789</engine_num>
<cylider_num>32</cylider_num>
<fuel_type>PreMimum</fuel_type>
</engine>
<chasis_num>546</chasis_num>
<accessories discbrake="Yes" autostart="Yes" radio="No"/>
</motorbike>
</catalog>
XML Validation
XML Schema
XML Schema (Or) XML Schema Definition (XSD)
• XML Schema mainly used for structuring XML documents.
Similar to DTD, XML Schema is also used to check whether
the given XML document is “well formed” and “valid”.
• XML Schema can be defined root element, child elements,
their number as well as their order.
• It defines data types, default and fixed values for the
elements and attributes.
• For this purpose, it has the form of XML schema language
which is also known as Xml Schema Definition (XSD).
XML Schema Contd...
• XML schemas are created by using XML syntax, where
DTD use a separate syntax.
• XML Schemas specify the type of textual data that can be
used with in attributes and elements.
• If we use the XML Schema for complex and large
operations, then the processing of XML document may slow
down.
• The XML document can’t be displayed if the corresponding
schema file is absent.
XML Schema Contd...
Data Types in XML Schema:
• Binary data type: It includes the binary data (0’s or 1’s).
• Boolean data type: It includes either “true” or “false”.
• Number data type: There are 3 main number data types those are
o float : It contains 32-bit floating point values.
o double: It contains 64-bit floating point values.
o decimal: It includes the decimal numbers either +ve or –ve.
• Date data type: It specifies the current date (YYYY-MM-DD).
• Time data type: It specifies the current time (HH:MM:SS).
• String data type: It includes series of characters such as strings.
• Example: The following example is an XML schema file called
“remainder.xsd” that defines the elements of XML document.
“remainder.xsd”
<?xml version = "1.0" encoding = "UTF-8"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
<xs:element name="remainder">
<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="msg" type="xs:string">
</xs:sequence>
</xs:complextype>
</xs:schema>
“remaind.xml”
<?xml version = "1.0" encoding = "UTF-8"?>
<remainder schemaLocation="remainder.xsd">
<to>Madhu</to>
<from>Durga</from>
<heading>Notice</heading>
<msg>This is My Last Remainder</msg>
</remainder>
Output:
XHTML-
(eXtensible HyperText Markup Language)
• XHTML stands for EXtensible HyperText Markup
Language.
• XHTML is almost identical to HTML but it is stricter
than HTML. XHTML is HTML defined as an XML
application. It is supported by all major browsers.
• Although XHTML is almost the same as HTML but It is
more important to create your code correctly,
because XHTML is stricter than HTML in syntax and
case sensitivity.
• XHTML was developed to make HTML more
extensible and standard.
Let's take an example,
 The following HTML code works fine in most browsers (even if
it does not follow the HTML rules).
“Bad.html”
<html>
<head>
<title>This is an example of bad HTML</title>
<body>
<h1>This is a heading
<p>This is a paragraph
</body>
 The above HTML code doesn't follow the HTML rule although
it runs.
 XHTML doesn't facilitate you to make badly formed code(like
missing out a closing tag).
There are some changes in XHTML as compared to HTML, those
are
Changes in Document Structure
• All documents must have a DOCTYPE.
• The xmlns attribute in <html> is mandatory and must specify
the xml namespace for the document.
• <html>, <head>, <title>, and <body> are mandatory with their
respective closing tags.
Changes in XHTML Tags
• All XHTML tags must be in lower case.
• All XHTML tags must be closed.
• All XHTML tags must be properly nested.
• All XHTML attributes must be in lower case.
• The name attribute has changed as id.
• XHTML attribute values must be quoted.
• All XHTML documents must contain a DOCTYPE declaration at the
start.
– Example: <!DOCTYPE html>
• XHTML is case-sensitive markup language. So, all the XHTML tags
and attributes must be written in lower case.
– Example:
<!-- Invalid in XHTML -->
<A Href=“file.html“>Click here</A>
<!-- Valid in XHTML -->
<a href=“file.html“>Click here </a>
• An XHTML must have an equivalent closing tag.
– Example:
<!-- Invalid in XHTML -->
<p>This paragraph not valid in XHTML.
<!-- Valid in XHTML -->
<p> This paragraph valid in XHTML. </p>
• All the XHTML attribute's values must be quoted.
– Example:
<!-- Invalid in XHTML -->
<img src=“xhtml.gif" width=250 height=50 />
<!-- Valid in XHTML -->
<img src=“xhtml.gif" width="250" height="50" />
• The id attribute is used to replace the name attribute. Instead of
using name = "name", XHTML prefers to use id = "id".
– Example:
<!-- Invalid in XHTML -->
<input type=“text“ name=“txtuname” />
<!-- Valid in XHTML -->
< input type=“text“ id=“txtuname” />
Example:
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title of document</title>
</head> Output:
<body bgcolor=“cyan”>
some content
</body>
</html>
XML Parsers
(DOM & SAX)
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 document and
create a way(interface or API) for programs to use XML.
XML Parsers
Two Types of parsers
DOM Parser
SAX Parser
DOM (Document Object Model)
• DOM is a platform that allows programs and scripts to
dynamically access and update the content and structure of a
XML documents.
• The Document Object Model (DOM) is a programming API
for HTML and XML documents. It defines the logical
structure of documents and provides interface(API) for
access documents.
• The Document Object Model can be used with any
programming language.
• DOM exposes the whole document to applications.
DOM (Document Object Model)
• The XML DOM defines a standard way for accessing and
manipulating XML documents. It presents an XML document
as a tree-structure.
• The tree structure makes easy to describe an XML document. A
tree structure contains root element (as parent), child element
and so on.
• The XML DOM makes a tree-structure view for an XML
document.
• We can access all elements through the DOM tree. We can
modify or delete their content and also create new elements.
DOM (Document Object Model)
<?xml version="1.0"?>
<college>
<student>
<firstname>Durga</firstname>
<lastname>Madhu</lastname>
<contact>999123456</contact>
<email>dm@abc.com</email>
<address>
<city>Hyderabad</city>
<state>TS</state>
<pin>500088</pin>
</address>
</student>
</college>
DOM (Document Object Model)
Let's see the tree-structure representation of the above example.
DOM (Document Object Model)
• We need a parser to read XML document into memory and
converts into XML DOM Object that can be accesses with
any programming language (here we can use PHP).
• The DOM parser functions are part of the PHP core. There is
no installation needed to use these functions.
• To load XML document in PHP
$xmlDoc = new DOMDocument();
this statement creates an object.
$xmlDoc->load("note.xml");
this statement loads a xml file by using object.
DOM (Document Object Model)
These are some typical DOM properties in php:
• X -> nodeName - the name of X
• X -> nodeValue - the value of X
• X->parentNode - the parent node of X
• X->childNodes - the child nodes of X
• X->attributes - the attributes nodes of X
Where X is Node object.
“note.xml”
<?xml version="1.0" encoding="UTF-8"?>
<student>
<num>521</num>
<name>xyz</name>
<age>30</age>
</student>
DOM (Document Object Model)
“Note.php”
<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("note.xml");
$x = $xmlDoc->documentElement;
foreach ($x->childNodes AS $item) {
print $item->nodeValue . "<br>";
}
?>
Output:
SAX
Simple API for XML
XML Parsers
What is an XML parser?
– 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 Parsers
Two types of parser
– SAX (Simple API for XML)
• Event driven API
• Sends events to the application as the document is read
– DOM (Document Object Model)
• Reads the entire document into memory in a tree
structure
Simple API for XML
SAX Parser
When should I use it?
– Large documents
– Memory constrained devices
– If you need not to modify the document
SAX Parser
Which languages are supported?
– Java
– Perl
– C++
– Python
SAX Implementation in Java
• Create a class which extends the SAX event handler
Import org.xml.sax.*;
import org.xml.sax.helpers.ParserFactory;
Public class SaxApplication extends HandlerBase {
public static void main(String args[]) {
}
}
SAX Implementation in Java
• Create a SAX Parser
public static void main(args[]) {
String parserName = “org.apache.xerces.parsers.SAXParser”;
try {
SaxApplication app = new SaxApplication();
Parser parser = ParserFactory.makeParser(parserName);
parser.setDocumentHandler(app);
parser.setErrorHandler(app);
parser.parse(new InputSource(args[0]));
} catch (Throwable t) {
// Handle exceptions
}
}
SAX Implementation in Java
• Most important methods to parse
– void startDocument()
• Called once when document parsing begins
– void endDocument()
• Called once when parsing ends
– void startElement(...)
• Called each time an element begin tag is encountered
– void endElement(...)
• Called each time an element end tag is encountered
– void error(...)
• Called once when parsing error occurred.
DOM SAX
Tree model parser (Object based) (Tree
of nodes).
Event based parser (Sequence of
events).
DOM loads the file into the memory and
then parse- the file.
SAX parses the file as it reads it, i.e.
parses node by node.
Has memory constraints since it loads
the whole XML file before parsing.
No memory constraints as it does not
store the XML content in the memory.
DOM is read and write (can insert or
delete nodes).
SAX is read only i.e. can’t insert or
delete the node.
If the XML content is small, then prefer
DOM parser.
Use SAX parser when XML content is
large.
Backward and forward search is possible
for searching the tags and evaluation of
the information inside the tags.
SAX reads the XML file from top to
bottom and backward navigation is not
possible.
Slower at run time. Faster at run time.
Ad

More Related Content

Similar to II UNIT PPT NOTES.pdf this is the data structures (20)

Unit-III_JQuery.pptx engineering subject for third year students
Unit-III_JQuery.pptx engineering subject for third year studentsUnit-III_JQuery.pptx engineering subject for third year students
Unit-III_JQuery.pptx engineering subject for third year students
MARasheed3
 
Unit iv xml
Unit iv xmlUnit iv xml
Unit iv xml
smitha273566
 
Web Technology Part 4
Web Technology Part 4Web Technology Part 4
Web Technology Part 4
Thapar Institute
 
distributed system concerned lab sessions
distributed system concerned lab sessionsdistributed system concerned lab sessions
distributed system concerned lab sessions
milkesa13
 
Xml
XmlXml
Xml
soumya
 
Web Security Extensible Markup Language.pptx
Web Security Extensible Markup Language.pptxWeb Security Extensible Markup Language.pptx
Web Security Extensible Markup Language.pptx
SidduSKamatar
 
Xml 1
Xml 1Xml 1
Xml 1
pavishkumarsingh
 
web design technology- mark up languages
web design technology- mark up languagesweb design technology- mark up languages
web design technology- mark up languages
ssuser2efca7
 
XML-Unit 1.ppt
XML-Unit 1.pptXML-Unit 1.ppt
XML-Unit 1.ppt
ssuseree7dcd
 
Xml intro1
Xml intro1Xml intro1
Xml intro1
Alfonso Gabriel López Ceballos
 
Xml
XmlXml
Xml
baabtra.com - No. 1 supplier of quality freshers
 
Xml
XmlXml
Xml
Santosh Pandey
 
Unit-2_XMxvvxvxvxvLccccccccccccccccccccccccccc.pptx
Unit-2_XMxvvxvxvxvLccccccccccccccccccccccccccc.pptxUnit-2_XMxvvxvxvxvLccccccccccccccccccccccccccc.pptx
Unit-2_XMxvvxvxvxvLccccccccccccccccccccccccccc.pptx
VikasTuwar1
 
chapter 4 web authoring unit 4 xml.pptx
chapter 4 web authoring  unit 4 xml.pptxchapter 4 web authoring  unit 4 xml.pptx
chapter 4 web authoring unit 4 xml.pptx
amare63
 
XML Schema.pptx
XML Schema.pptxXML Schema.pptx
XML Schema.pptx
JohnsonDcunha1
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
Pradeep Rapolu
 
Internet_Technology_UNIT V- Introduction to XML.pptx
Internet_Technology_UNIT V- Introduction to XML.pptxInternet_Technology_UNIT V- Introduction to XML.pptx
Internet_Technology_UNIT V- Introduction to XML.pptx
shilpar780389
 
Xml schema
Xml schemaXml schema
Xml schema
Akshaya Akshaya
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
Tony Nguyen
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
James Wong
 
Unit-III_JQuery.pptx engineering subject for third year students
Unit-III_JQuery.pptx engineering subject for third year studentsUnit-III_JQuery.pptx engineering subject for third year students
Unit-III_JQuery.pptx engineering subject for third year students
MARasheed3
 
distributed system concerned lab sessions
distributed system concerned lab sessionsdistributed system concerned lab sessions
distributed system concerned lab sessions
milkesa13
 
Web Security Extensible Markup Language.pptx
Web Security Extensible Markup Language.pptxWeb Security Extensible Markup Language.pptx
Web Security Extensible Markup Language.pptx
SidduSKamatar
 
web design technology- mark up languages
web design technology- mark up languagesweb design technology- mark up languages
web design technology- mark up languages
ssuser2efca7
 
Unit-2_XMxvvxvxvxvLccccccccccccccccccccccccccc.pptx
Unit-2_XMxvvxvxvxvLccccccccccccccccccccccccccc.pptxUnit-2_XMxvvxvxvxvLccccccccccccccccccccccccccc.pptx
Unit-2_XMxvvxvxvxvLccccccccccccccccccccccccccc.pptx
VikasTuwar1
 
chapter 4 web authoring unit 4 xml.pptx
chapter 4 web authoring  unit 4 xml.pptxchapter 4 web authoring  unit 4 xml.pptx
chapter 4 web authoring unit 4 xml.pptx
amare63
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
Pradeep Rapolu
 
Internet_Technology_UNIT V- Introduction to XML.pptx
Internet_Technology_UNIT V- Introduction to XML.pptxInternet_Technology_UNIT V- Introduction to XML.pptx
Internet_Technology_UNIT V- Introduction to XML.pptx
shilpar780389
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
James Wong
 

Recently uploaded (20)

sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt
rakshaiya16
 
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation RateModeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Journal of Soft Computing in Civil Engineering
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning ModelsMode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Journal of Soft Computing in Civil Engineering
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
introduction technology technology tec.pptx
introduction technology technology tec.pptxintroduction technology technology tec.pptx
introduction technology technology tec.pptx
Iftikhar70
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt
rakshaiya16
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
Ad

II UNIT PPT NOTES.pdf this is the data structures

  • 2. Introduction: • XML stands for eXtensible Markup Language and it is used for storing and transferring data. • XML doesn’t depend on the platform and the software (programming language). i.e. we can able to write a program in any language on any platform (Operating System) to send, receive or store data using XML. • XML is a simple document with the data, which can be used to store and transfer data between any systems irrespective of their hardware and software compatibilities. • It is so much easier to read the data from XML and display it on a GUI (graphical user interface) using markup language like HTML.
  • 3. HTML Vs XML HTML(Hyper Text Markup Language) XML(eXtensible Markup Language) HTML is not a case sensitive language XML is case sensitive language HTML is mainly concerned with the presentation of data XML is mainly used for storing and transporting the data HTML is static XML is dynamic In HTML the closing tag in optional In XML the closing tag is mandatory HTML uses predefined tags such as <b>, <br>, <img> etc. XML uses the user-defined tags that we create while writing the XML document. HTML does not preserve white space. XML preserves white space. HTML Attribute Values Quoting is optional. XML Attribute Values Must Always be Quoted.
  • 4. Simple XML document example A XML document structure looks like this: <root> <child> <subchild>.....</subchild> </child> <child> <subchild>.....</subchild> </child> </root> • <?xml version="1.0" encoding="UTF-8"?> is called XML Prolog. • It is optional, however when we include it in the XML document, it should always be the first line of the document. XML Prolog defines the XML version and the encoding used in the XML document.
  • 5. • The XML code can be written on a simple notepad and should be saved as “filename.xml”. Students.xml <?xml version="1.0" encoding="UTF-8"?> <students> <student> <num>527</num> <name>Ravi</name> <age>20</age> </student> <student> <num>572</num> <name>Dev</name> <age>23</age> </student> </students>
  • 6. • In the above XML document we have the details of the few students. Here <students> is the root element, <student> is the child element and num,name and age are sub-child elements. Output:
  • 7. XML Syntax Root Element is mandatory in XML • XML document must have a root element. A root element can have child elements and sub-child elements. • For example: In the following XML document, <message> is the root element and <to>, <from>, <subject> and <text> are child elements. <?xml version="1.0" encoding="UTF-8"?> <message> <to>Durga</to> <from>Madhu</from> <subject>Message from teacher to Student</subject> <text>You have an exam tomorrow at 10:00 AM</text> </message>
  • 8. XML Syntax Contd… XML is case sensitive XML is a case sensitive language. For example: <from>madhu</from>  This is valid <from>Prasad</FROM>  This is invalid • All letters of closing tag is in capital while all letters of opening tag is in small, this is an example of invalid XML. XML Prolog <?xml version="1.0" encoding="UTF-8"?> • This line is called the XML Prolog. It is an optional line, however it should be the first line when you mention it. It specifies the XML version and the encoding used in the XML document.
  • 9. XML Syntax Contd… Elements should not overlap • All the elements in XML should be properly nested and they should not overlap. <class><teacher>Madhu</class></teacher> -->Wrong (Not nested properly) <class><teacher>Durga</teacher></class> -->Correct (Correctly nested) XML elements must have a closing tag • All XML documents must have a closing tag. <text category = message>hello</text> -->correct <text category = message>hello -->wrong Comments in XML • This is how a comment should look like in XML document. <!-- This is just a comment -->
  • 10. XMLAttributes • XML elements can have attributes. By the use of attributes we can add the additional information about the element. • XML attributes are a way to add additional data to the XML element. Attributes contain data in form of name & value pairs. • XML attributes are used to enhance the properties of the elements. Note: XML attributes must always be quoted. We can use single or double quote. Example: <book category="computers"> <price>1000rs</price> <publisher>Tata McGraw Hill</publisher> </book>
  • 11. XMLAttributes Contd… XML attributes vs XML Sub Elements: • The Data can be stored in attributes or in child elements. But there are some limitations in using attributes, over child elements. Same information can be represented in two ways: 1st Way: <book category="computers"> <price>1000rs</price> <publisher>Tata McGraw Hill</publisher> </book> 2nd Way: <book> <category>computers </category> <price>1000rs</price> <publisher>Tata McGraw Hill</publisher> </book>
  • 12. XMLAttributes Contd… • In the first way category is used as an attribute and in the second way category is used as an element. • Both examples provide the same information but it is good practice to avoid attribute in XML and use elements instead of attributes. Because • Attributes cannot contain multiple values but child elements can have multiple values. • Attributes cannot contain tree structure but child element can. • Elements are easy to be handled by the programming language compared to the attributes.
  • 13. XML Validation Document Type Definition (DTD)
  • 14. XML – Validation • Validation is a process by which an XML document is validated. • An XML document with correct syntax is known as valid XML document. Let‟s see few important rules to check for syntax errors. • All XML documents must have a root element. • XML is a case sensitive language so you should be careful with the case while opening and closing tags. • All XML tags must have a closing tag. • XML attribute name should not be quoted while its value must be quoted. • There are two ways to check whether the XML document is valid. 1 XML DTD (Document Type Definition) 2 XML Schema
  • 15. Document Type Definition (DTD) • DTD stands for Document Type Definition. It is used to define document structure with a list of legal elements and attributes. • Document Type Definition (DTD) is a certain piece of code, which can defines structure of XML document. • Each DTD contains a list of elements, which specifies the rules for structuring a given XML document. • Each DTD specifies the relationship between root element, child elements and sub child elements. • An XML document is considered “well formed” and “valid” if it is successfully validated against DTD.
  • 16. Document Type Definition (DTD) Contd.. • DTD‟s are optional in XML, but recommended for clarity purpose. • DTD‟s can be declared internally (With in XML doc) and as an external file (with in a separate file with “.dtd” extension). Basic Building Blocks: There are 4 building blocks to build a XML document with DTD. those are 1.Tags 2.Elements 3.Attributes 4.Entities
  • 17. Document Type Definition (DTD) Contd.. 1. Tags: – The XML allows the user to create own tags.Useally the tag <tagname> is an Opening tag, </tagname> refers to its equivalent closing tag. Example: <book>Let us C</book> <author> Yashwant Kanetkar </ author > – In XML the tags are case sensitive . And closing tag is mandatory. – All the elements in XML should be properly nested and they should not overlap.
  • 18. Document Type Definition (DTD) Contd.. 2. Elements in DTD: – The DTD document is composed with various elements. These elements are used to represent the tags in XML document. Declaration: <!ELEMENT name-of-element(context)> – To declare an empty element Syntax: <!ELEMENT name-of-element(EMPTY)> – To declare an element, this carries data Syntax: <!ELEMENT name-of-element(#PCDATA)> (or) <!ELEMENT name-of-element(#CDATA)>
  • 19. Document Type Definition (DTD) Contd.. – To declare an element, this contains child elements Syntax: <!ELEMENT name-of-element(child-names)> Examples: <!ELEMENT student(id,name,age)> <!ELEMENT name(#PCDATA)> <!ELEMENT age(EMPTY)> 3.Attributes: • These are used to provide the additional information along with elements. • In DTD, the attributes are declared by using “ATTLIST” Keyword. Syntax: <! ATTLIST name-of-element name-of-attribute attribute-type [default-value]>
  • 20. Document Type Definition (DTD) Contd.. • In the above syntax, the field „attribute-type‟ can specifies the following pre-defined values. • ID:It is a value which remains unique. • CDATA: The value supplied here is nothing but character data. • ENTITY: The value supplied in this case is nothing but an entity. • In the same way, the filed „default-value‟ can specifies the following pre-defined values.  #REQUIRED: It means the value for the attribute is required.  #IMPLIED: It means the attribute is not required.  #FIXED: Here a fixed value is supplied.  Default-value: It is a default value of given attribute. Example: <! ATTLIST student address CDATA #REQUIRED>
  • 21. Document Type Definition (DTD) Contd.. 4. Entities: • Some markup elements can contain complex data; these types of elements are called as Entities. • These are used to create small piece of data which you want you use repeatedly throughout your schema. Syntax: <! ENTITY name-of-entity “value”> Example: <! ENTITY Book “Web Technologies”> Used as <author> the &Book author is Uttam K Roy</author>
  • 22. Document Type Definition (DTD) Contd.. • DTD‟s can be declared internally (With in XML doc) and as an external file (with in a separate file with “.dtd” extension) Example with external DTD: • Create a DTD for a remainder; it has following remainder as root element and child elements-heading, to, from, message. “remainder.dtd” <!ELEMENT remainder(heading,to,from,message)> <!ELEMENT heading(#PCDATA)> <!ELEMENT to(#PCDATA)> <!ELEMENT from(#PCDATA)> <!ELEMENT message(#PCDATA)>
  • 23. Document Type Definition (DTD) Contd.. “remainder.xml” <?xml version="1.0"?> <!DOCTYPE note SYSTEM "remainder.dtd"> <remainder> <heading>Final Remainder</heading> <to>Mr.Madhu</to> <from> Ravi Gupta</from> <message> Date of joining is 5th Feb</message> </remainder> Output:
  • 24. Document Type Definition (DTD) Contd.. Example with internal DTD: “remainderdemo.xml” <?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT remainder (heading,to,from,message)> <!ELEMENT heading (#PCDATA)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT message (#PCDATA)> ]> <remainder> <heading>Final Remainder</heading> <to>Mr.Madhu</to> <from> Ravi Gupta</from> <message> Date of joining is 5th Feb</message> </remainder>
  • 25. Document Type Definition (DTD) Contd.. Example: • Create a DTD for a catalog of four stroke engine motorbikes where each motor bike has the following child elements: make, model, year, color, engine, chassis number and accessories. The engine element has child elements those are – engine number, number of cylinders, type of fuel. The accessories elements has the attributes like disk break, auto start and radio, each of which required and has the possible values ‘YES’ and ‘NO’ . Entities must be declared for the names of the popular motorbike makes.
  • 26. Document Type Definition (DTD) Contd.. “bikecatalog.dtd” <!ELEMENT catalog (motorbike)*> <!ELEMENT motorbike (make, model,year,color,engine, chasis_num, accessories)> <!ELEMENT make (#PCDATA)> <!ELEMENT model (#PCDATA)> <!ELEMENT year (#PCDATA)> <!ELEMENT color (#PCDATA)> <!ELEMENT engine (engine_num,cylinder_num,fuel_type)> <!ELEMENT engine_num (#PCDATA)> <!ELEMENT cylinder_num (#PCDATA)> <!ELEMENT fuel_type (#PCDATA)> <!ELEMENT chasis_num (#PCDATA)> <!ELEMENT accessories (#PCDATA)> <!ATTLIST accessories diskbrake (Yes|No) #REQUIRED autostart (Yes|No) #REQUIRED radio (Yes|No) #REQUIRED>
  • 27. Document Type Definition (DTD) Contd.. <?xml version="1.0"?> “bikecatalog.xml” <!DOCTYPE catalog SYSTEM "bikecatalog.dtd"> <catalog> <motorbike> <make>Hero</make> <model>Glammur 120cc</model> <year>2014</year> <color>Red-Black</color> <engine> <engine_num>564789</engine_num> <cylider_num>32</cylider_num> <fuel_type>PreMimum</fuel_type> </engine> <chasis_num>546</chasis_num> <accessories discbrake="Yes" autostart="Yes" radio="No"/> </motorbike> </catalog>
  • 29. XML Schema (Or) XML Schema Definition (XSD) • XML Schema mainly used for structuring XML documents. Similar to DTD, XML Schema is also used to check whether the given XML document is “well formed” and “valid”. • XML Schema can be defined root element, child elements, their number as well as their order. • It defines data types, default and fixed values for the elements and attributes. • For this purpose, it has the form of XML schema language which is also known as Xml Schema Definition (XSD).
  • 30. XML Schema Contd... • XML schemas are created by using XML syntax, where DTD use a separate syntax. • XML Schemas specify the type of textual data that can be used with in attributes and elements. • If we use the XML Schema for complex and large operations, then the processing of XML document may slow down. • The XML document can’t be displayed if the corresponding schema file is absent.
  • 31. XML Schema Contd... Data Types in XML Schema: • Binary data type: It includes the binary data (0’s or 1’s). • Boolean data type: It includes either “true” or “false”. • Number data type: There are 3 main number data types those are o float : It contains 32-bit floating point values. o double: It contains 64-bit floating point values. o decimal: It includes the decimal numbers either +ve or –ve. • Date data type: It specifies the current date (YYYY-MM-DD). • Time data type: It specifies the current time (HH:MM:SS). • String data type: It includes series of characters such as strings.
  • 32. • Example: The following example is an XML schema file called “remainder.xsd” that defines the elements of XML document. “remainder.xsd” <?xml version = "1.0" encoding = "UTF-8"?> <xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"> <xs:element name="remainder"> <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="msg" type="xs:string"> </xs:sequence> </xs:complextype> </xs:schema>
  • 33. “remaind.xml” <?xml version = "1.0" encoding = "UTF-8"?> <remainder schemaLocation="remainder.xsd"> <to>Madhu</to> <from>Durga</from> <heading>Notice</heading> <msg>This is My Last Remainder</msg> </remainder> Output:
  • 35. • XHTML stands for EXtensible HyperText Markup Language. • XHTML is almost identical to HTML but it is stricter than HTML. XHTML is HTML defined as an XML application. It is supported by all major browsers. • Although XHTML is almost the same as HTML but It is more important to create your code correctly, because XHTML is stricter than HTML in syntax and case sensitivity. • XHTML was developed to make HTML more extensible and standard.
  • 36. Let's take an example,  The following HTML code works fine in most browsers (even if it does not follow the HTML rules). “Bad.html” <html> <head> <title>This is an example of bad HTML</title> <body> <h1>This is a heading <p>This is a paragraph </body>  The above HTML code doesn't follow the HTML rule although it runs.  XHTML doesn't facilitate you to make badly formed code(like missing out a closing tag).
  • 37. There are some changes in XHTML as compared to HTML, those are Changes in Document Structure • All documents must have a DOCTYPE. • The xmlns attribute in <html> is mandatory and must specify the xml namespace for the document. • <html>, <head>, <title>, and <body> are mandatory with their respective closing tags. Changes in XHTML Tags • All XHTML tags must be in lower case. • All XHTML tags must be closed. • All XHTML tags must be properly nested. • All XHTML attributes must be in lower case. • The name attribute has changed as id. • XHTML attribute values must be quoted.
  • 38. • All XHTML documents must contain a DOCTYPE declaration at the start. – Example: <!DOCTYPE html> • XHTML is case-sensitive markup language. So, all the XHTML tags and attributes must be written in lower case. – Example: <!-- Invalid in XHTML --> <A Href=“file.html“>Click here</A> <!-- Valid in XHTML --> <a href=“file.html“>Click here </a> • An XHTML must have an equivalent closing tag. – Example: <!-- Invalid in XHTML --> <p>This paragraph not valid in XHTML. <!-- Valid in XHTML --> <p> This paragraph valid in XHTML. </p>
  • 39. • All the XHTML attribute's values must be quoted. – Example: <!-- Invalid in XHTML --> <img src=“xhtml.gif" width=250 height=50 /> <!-- Valid in XHTML --> <img src=“xhtml.gif" width="250" height="50" /> • The id attribute is used to replace the name attribute. Instead of using name = "name", XHTML prefers to use id = "id". – Example: <!-- Invalid in XHTML --> <input type=“text“ name=“txtuname” /> <!-- Valid in XHTML --> < input type=“text“ id=“txtuname” />
  • 40. Example: <!DOCTYPE html > <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Title of document</title> </head> Output: <body bgcolor=“cyan”> some content </body> </html>
  • 42. 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 document and create a way(interface or API) for programs to use XML.
  • 43. XML Parsers Two Types of parsers DOM Parser SAX Parser
  • 44. DOM (Document Object Model) • DOM is a platform that allows programs and scripts to dynamically access and update the content and structure of a XML documents. • The Document Object Model (DOM) is a programming API for HTML and XML documents. It defines the logical structure of documents and provides interface(API) for access documents. • The Document Object Model can be used with any programming language. • DOM exposes the whole document to applications.
  • 45. DOM (Document Object Model) • The XML DOM defines a standard way for accessing and manipulating XML documents. It presents an XML document as a tree-structure. • The tree structure makes easy to describe an XML document. A tree structure contains root element (as parent), child element and so on. • The XML DOM makes a tree-structure view for an XML document. • We can access all elements through the DOM tree. We can modify or delete their content and also create new elements.
  • 46. DOM (Document Object Model) <?xml version="1.0"?> <college> <student> <firstname>Durga</firstname> <lastname>Madhu</lastname> <contact>999123456</contact> <email>dm@abc.com</email> <address> <city>Hyderabad</city> <state>TS</state> <pin>500088</pin> </address> </student> </college>
  • 47. DOM (Document Object Model) Let's see the tree-structure representation of the above example.
  • 48. DOM (Document Object Model) • We need a parser to read XML document into memory and converts into XML DOM Object that can be accesses with any programming language (here we can use PHP). • The DOM parser functions are part of the PHP core. There is no installation needed to use these functions. • To load XML document in PHP $xmlDoc = new DOMDocument(); this statement creates an object. $xmlDoc->load("note.xml"); this statement loads a xml file by using object.
  • 49. DOM (Document Object Model) These are some typical DOM properties in php: • X -> nodeName - the name of X • X -> nodeValue - the value of X • X->parentNode - the parent node of X • X->childNodes - the child nodes of X • X->attributes - the attributes nodes of X Where X is Node object. “note.xml” <?xml version="1.0" encoding="UTF-8"?> <student> <num>521</num> <name>xyz</name> <age>30</age> </student>
  • 50. DOM (Document Object Model) “Note.php” <?php $xmlDoc = new DOMDocument(); $xmlDoc->load("note.xml"); $x = $xmlDoc->documentElement; foreach ($x->childNodes AS $item) { print $item->nodeValue . "<br>"; } ?> Output:
  • 52. XML Parsers What is an XML parser? – 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.
  • 53. XML Parsers Two types of parser – SAX (Simple API for XML) • Event driven API • Sends events to the application as the document is read – DOM (Document Object Model) • Reads the entire document into memory in a tree structure
  • 55. SAX Parser When should I use it? – Large documents – Memory constrained devices – If you need not to modify the document
  • 56. SAX Parser Which languages are supported? – Java – Perl – C++ – Python
  • 57. SAX Implementation in Java • Create a class which extends the SAX event handler Import org.xml.sax.*; import org.xml.sax.helpers.ParserFactory; Public class SaxApplication extends HandlerBase { public static void main(String args[]) { } }
  • 58. SAX Implementation in Java • Create a SAX Parser public static void main(args[]) { String parserName = “org.apache.xerces.parsers.SAXParser”; try { SaxApplication app = new SaxApplication(); Parser parser = ParserFactory.makeParser(parserName); parser.setDocumentHandler(app); parser.setErrorHandler(app); parser.parse(new InputSource(args[0])); } catch (Throwable t) { // Handle exceptions } }
  • 59. SAX Implementation in Java • Most important methods to parse – void startDocument() • Called once when document parsing begins – void endDocument() • Called once when parsing ends – void startElement(...) • Called each time an element begin tag is encountered – void endElement(...) • Called each time an element end tag is encountered – void error(...) • Called once when parsing error occurred.
  • 60. DOM SAX Tree model parser (Object based) (Tree of nodes). Event based parser (Sequence of events). DOM loads the file into the memory and then parse- the file. SAX parses the file as it reads it, i.e. parses node by node. Has memory constraints since it loads the whole XML file before parsing. No memory constraints as it does not store the XML content in the memory. DOM is read and write (can insert or delete nodes). SAX is read only i.e. can’t insert or delete the node. If the XML content is small, then prefer DOM parser. Use SAX parser when XML content is large. Backward and forward search is possible for searching the tags and evaluation of the information inside the tags. SAX reads the XML file from top to bottom and backward navigation is not possible. Slower at run time. Faster at run time.
  翻译: