XML 1
XML 1
1 2
HTML XML
HTML is used to display XML is a software and hardware XML Template
data and focuses on how data independent tool used to <root>
looks. transport and store data. It
focuses on what data is. <child>
HTML is a markup XML provides a framework to <subchild>.....</subchild>
language itself. define markup languages.
HTML is not case sensitive. XML is case sensitive.
</child>
HTML is a presentation language. XML is neither a presentation </root>
language nor a programming • XML documents must contain a root element.
language.
• This element is "the parent" of all other elements.
HTML has its own predefined You can define tags according
• The elements in an XML document form a document tree.
tags. to your need.
• The tree starts at the root and branches to the lowest level of the
In HTML, it is not necessary to XML makes it mandatory to use
use a closing tag. a closing tag.
tree.
HTML is static because it is used XML is dynamic because it is used
• All elements can have sub elements (child elements)
to display data. to transport data. • The terms parent, child, and sibling are used to describe the
HTML does not preserve XML preserve whitespaces. relationships between elements. Parent elements have children.
whitespaces. Children on the same level are called siblings (brothers or sisters).
3 4
5 6
1
12/6/2019
7 8
9 10
DTD and XML schema both are used to form a well formed
Rules for well formed XML XML document.
11 12
2
12/6/2019
<!DOCTYPE employee :
XML DTD It defines that the root element of the document is employee.
Valid and well-formed XML document with DTD
employee.xml <!ELEMENT employee:
<?xml version="1.0"?> It defines that the employee element contains 3 elements
<!DOCTYPE employee SYSTEM "employee.dtd"> "firstname, lastname and email".
<employee>
<firstname>Tom</firstname> <!ELEMENT firstname:
<lastname>brian</lastname> It defines that the firstname element is #PCDATA typed.
<email>[email protected]</email>
(parse-able data type).
</employee>
employee.dtd
<!ELEMENT lastname: It defines that the lastname element is
<!ELEMENT employee (firstname,lastname,email)> #PCDATA typed. (parse-able data type).
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT lastname (#PCDATA)>
<!ELEMENT email (#PCDATA)> <!ELEMENT email: It defines that the email element is #PCDATA
typed. (parse-able data type).
13 14
15 16
</xs:schema>
17 18
3
12/6/2019
19 20
DTD XSD CDATA: (Unparsed Character data): CDATA contains the text
DTDs are derived XSDs are written in XML.
which is not parsed further in an XML document. Tags inside
from SGML syntax. the CDATA text are not treated as markup and entities will not
be expanded.
DTD doesn't support datatypes. XSD supports datatypes for
elements and attributes. Let's take an example for CDATA:
DTD doesn't support namespace. XSD supports namespace. <?xml version="1.0"?>
<!DOCTYPE employee SYSTEM "employee.dtd">
DTD doesn't define order for child XSD defines order for child
elements. elements. <employee>
<![CDATA[
DTD is not extensible. XSD is extensible. <firstname>tom</firstname>
<lastname>brian</lastname>
DTD is not simple to learn. XSD is simple to learn because you <email>[email protected]</email>
don't need to learn new language. ]]>
DTD provides less control on XML XSD provides more control on XML </employee>
structure. structure. In the above CDATA example, CDATA is used just after the element employee to
make the data/text unparsed, so it will give the value of employee:
<firstname>tom</firstname><lastname>brian</lastname><email>[email protected]</email>
21 22
PCDATA: (Parsed Character Data): XML parsers are used to parse all the text
in an XML document. PCDATA stands for Parsed Character data. PCDATA is
XML Parsers
the text that will be parsed by a parser. Tags inside the PCDATA will be treated An XML parser is a software library or package that provides
as markup and entities will be expanded. interfaces for client applications to work with an XML document.
In other words you can say that a parsed character data means the XML parser The XML Parser is designed to read the XML and create a way for
examine the data and ensure that it doesn't content entity if it contains that will programs to use XML.
be replaced. XML parser validates the document and check that the document
Let's take an example for CDATA: is well formatted.
<?xml version="1.0"?> Let's understand the working of XML parser by the figure given
<!DOCTYPE employee SYSTEM "employee.dtd"> below:
<employee> These are the two main types of XML Parsers:
<firstname>tom</firstname>
1. DOM 2. SAX
<lastname>brian</lastname>
<email>[email protected]</email>
</employee> XML Client
In the above example, the employee element contains 3 more elements 'firstname', Document XML Parser API’s Application
'lastname', and 'email', so it parses further to get the data/text of firstname,
lastname and email to give the value of employee as:
tom brian [email protected]
23 24
4
12/6/2019
XML Namespace
Example :
<book
xmlns:lit=‘http://www.literature.com/schema’>
</book>
<
25