Unit 1
Unit 1
Unit 1
XML is a mark-up language based on tags within angled brackets, similar to HTML. Here tags
are not predefined. We need to specify our own tags. These tags are self-explanatory.
Characteristics of XML
There are many significant characteristics of XML that are beneficial for a range of systems.
i. Extensible: using XML, it is possible to create our own self-descriptive tags according
application need.
ii. carries the data, does not present it : XML allows you to store the data regardless of
how it will be displayed.
iii. Open standard: XML was created by the World Wide Web Consortium (W3C) and is
freely available as an open standard.
iv. Structured format:
It is possible to precisely determine the arrangement, organisation and expressing of
data in the file.
v. Validation: It is possible to validate XML file using document type declaration(DTD)
vi. Described format: In XML file, every piece of data has a name that is readable by both
humans and machines.
vii. discoverable format: it is possible to parse XML file and understand the structure and
relationships between the items
viii. platform independent: XML is a software and hardware-independent to send, receive
or store data.
ix. XML is a universal format.
Rules for XML Declaration/ XML document must meet these criteria:
i. XML document must begin with the XML declaration. Xml declaration start with <?xml
and end with ?>. XML declaration also contains various parameters. The sequence in
which the parameters are placed is crucial. Version, encoding, and standalone are in
the correct order.
ii. The XML declaration must be the first statement in the XML document.
iii. Elements can't overlap. In other words, element should properly nested.
iv. A document can have exactly one root element.
v. All attributes value must be put in single or double quotes
vi. Comments can’t be placed inside tags.
vii. Tag Names cannot start with a number or punctuation character. However, Tag Names
can contain letters, numbers, and other characters.
viii. Tag Names cannot contain spaces.
ix. Xml tags are case-sensitive. For example, <book>, <Book>, <BOOK> all are different.
XML declaration sets parameters for basic XML parsing. Itcontains various parameters. The
syntax of XML declaration is :
<?xml
version = "version_information"
encoding = "encoding_declaration"
standalone = "standalone_status"
?>
Here,
Encoding It specify encoding method used in the document. UTF-8, UTF-16, ISO-10646-UCS-
The default encoding is UTF-8. 2, ISO-10646-UCS-4, ISO-8859-1
to ISO-8859-9
Declaration examples:
Example 2: Following line declare XML document with version 1.0, encoding UTF-8 and
standalone = no.
<?xml
version = "1.0"
encoding = "UTF-8"
Example 3: Following example show XML declaration with all parameters defined in single
quotes
XML Tags
XML tags are the building blocks of an XML document. In XML, XML tags specify the scope of
an element. They can also be used to add comments and specify environment-specific
parameters.
XML Tag and HTML tags are similar, but XML is more flexible then HTML. HTML tags are
predefined while XML tags are user defined.
Every XML element is marked by a start-tag. It is specified using tag name within angular
brackets (< >) . For example:
<book>
Every element has end-tag. It is specified using "/" before the name of an element in
angular brackets. For example:
</book>
(1) Nothing between staring tag and closing tag. In other words, start-tag immediately
followed by an end-tag: For example
<book> </book>
(b) tag name end with "/" within angular brackets. For example:
<book />
(iv) root tag:
There is exactly one root element in any XML document. All of the other elements are
enclosed within it. The root element in HTML is the < html> element, while root element
can be anything in an XML file.
XML elements:
XML elements are the building blocks of an XML document. The XML Element is collection of
opening-tag, data and closing-tag. i.e. it contain everything from the element's start tag to
the element's end tag. Each XML document contains one or more elements.
XML document
An XML document consists of a prolog and body:
(i) prolog:
(ii)body:
Prolog Section is first and most important part of an XML Document. It indicate that
document is marked up in XML.
Example of prolog:
XML
declaration
DTD define entities or default attribute values. It supports validation, a special mode of
parsing that checks grammar and vocabulary of markup.
<Color>
<!-- this is comment -->
<Option1 Name='Blue'/>
<Option Name="Yellow"/>
<Option Name="Crimson"/>
</Color>
Example 2:
<?xml version="1.0" ?>
<address>
<street_no> 10 </street_no>
<street_name> bari faliya </street_name>
<district> bharuch </district>
</address>
Questions:
1. What is XML?
2. Write Characteristic XML.
3. Write note on XML document prolog section.
4. Write note on XML document element section
5. Write rules of XML declaration with example
MCQ
Ans: B
18. What is the correct syntax of the declaration which defines the XML version?
A. <?xml version="1.0"?>
B. <xml version="1.0" />
C. <?xml version="1.0" />
D. <xml version="1.0" ?>
A. yes B. no
Ans: A. yes