XML Tutorial for Beginners
XML Tutorial for Beginners
What is XML?
XML stands for eXtensible Markup Language.
It is a language (not> a programming
language) that uses the markup and can
extend. It is derived from Standard
Generalized Markup Language(SGML). XML
also uses DTDs (Document Type Definitions)
to define the XML document structure.
What is XML?
History of XML
XML Features
XML Encoding
XML Syntax
XML Declaration
XML Comments
XML Tags and Elements
XML Attributes
Attribute versus Element
XML Entities
HTML versus XML
https://www.guru99.com/xml-tutorials.html#11 1/28
4/21/23, 11:19 PM XML Tutorial for Beginners
History of XML
XML started way back in 1996 and was first published in 1998. World Wide Web Consortium
(W3C) is the developer of XML, and it became a W3C recommendation in 1998.
1. XML 1.0
2. XML 1.1
XML 1.1 is the latest version. Yet, XML 1.0 is the most used version.
EXPLORE MORE
Learn Java
Programming with
Beginners Tutorial
08:32
What is Integration
Testing Software Testing
Editors of XML are:
https://www.guru99.com/xml-tutorials.html#11 2/28
4/21/23, 11:19 PM XML Tutorial for Beginners
Tim Bray,
Jean Paoli,
C. M. Sperberg,
Eve Maler,
François Yergeau.
XML Features
Here are some important features of XML:
XML Encoding
Encoding is the conversion of Unicode characters to their binary representation. UTF is use
for XML encoding. UTF stands for UCS (UCS stands for Universal Character Set)
Transformation Format.
https://www.guru99.com/xml-tutorials.html#11 3/28
4/21/23, 11:19 PM XML Tutorial for Beginners
2. UTF-16
Example:
You can use encoding inside the XML declaration. UTF-8 is the default encoding in XML.
XML Syntax
The below code segment shows the basic XML syntax.
XML Declaration
XML declaration consists of the XML version, character encoding or/and standalone status.
The declaration is optional.
https://www.guru99.com/xml-tutorials.html#11 4/28
4/21/23, 11:19 PM XML Tutorial for Beginners
If the XML declaration is present, it must be the first thing that appears.
The XML declaration is case sensitive, and it must start with the lowercased <?xml.
It has no closing tag.
XML Comments
Comments are optional. Adding comments help to understand the document content.
Tag names are enclosed in <>. For a particular tag pair, the start and end tags must be
identical except the end tag has / after the <.
https://www.guru99.com/xml-tutorials.html#11 5/28
4/21/23, 11:19 PM XML Tutorial for Beginners
<name>...</name>
Note: Elements may also contain attributes. You will learn the attributes very soon.
<age>20</age>
If there is no content between the tags, as shown below, it referred to as empty tags.
<result></result>
https://www.guru99.com/xml-tutorials.html#11 6/28
4/21/23, 11:19 PM XML Tutorial for Beginners
Example:
Correct:
___
<age>20</age>
Wrong:
<age>20</Age>
Note: AGE, Age, and age are three different names in XML.
Example:
https://www.guru99.com/xml-tutorials.html#11 7/28
4/21/23, 11:19 PM XML Tutorial for Beginners
Correct:
Wrong:
XML Attributes
Attribute for an element is placed after the tag name in the start tag. You can add more than
one attribute for a single element with different attribute names.
There are two attributes in the company element, i.e. name and location.
Also, note that in the above example, the company is the root element.
Document A:
<teacher subject="English">
<name>Mr. John</name>.
<qualification>Graduate</qualification>
</teacher>
Document B:
<teacher>
<subject>English</subject>
<name>Mr. John</name>
<qualification>Graduate</qualification>
</teacher>
XML Entities
https://www.guru99.com/xml-tutorials.html#11 9/28
4/21/23, 11:19 PM XML Tutorial for Beginners
In simple terms, entities are a way of representing special characters. Entities are also
known as entity references.
For example, the < and > symbols a used for tags. You cannot directly type from the
keyboard for less than and greater than signs. Instead, you need to use entities.
Example:
<friend>
<name>My friends are Alice & Jane.</name>
</friend>
https://www.guru99.com/xml-tutorials.html#11 10/28
4/21/23, 11:19 PM XML Tutorial for Beginners
HTML XML
Structural
Not provided. Provided.
details
Tag limit A limited number of tags are available. Tags are extensible.
https://www.guru99.com/xml-tutorials.html#11 11/28
4/21/23, 11:19 PM XML Tutorial for Beginners
HTML XML
Namespace
Not supported. Supported.
support
Parsing in
Not needed any extra application. Need DOM implementation.
JavaScript
Filename
.html or .htm .xml
Extension
Quotes are not required for attribute Required for XML attribute
Quotes
values. values.
https://www.w3.org/TR/xml1
Website https://html.spec.whatwg.org/
1/
https://www.guru99.com/xml-tutorials.html#11 12/28
4/21/23, 11:19 PM XML Tutorial for Beginners
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
https://www.guru99.com/xml-tutorials.html#11 13/28
4/21/23, 11:19 PM XML Tutorial for Beginners
<title>Document</title>
</head>
<body>
<p>Book</p>
<p>Name: Anna Karenina</p>
<p>Author: Leo Tolstoy</p>
<p>Publisher: The Russian Messenger</p>
</body>
</html>
With XML
https://www.guru99.com/xml-tutorials.html#11 14/28
4/21/23, 11:19 PM XML Tutorial for Beginners
JSON XML
Data types of Supports text and number Support many data types (text,
support data types only. numbers, images, so on)
AJAX toolkit
Supported. Not fully supported.
support
https://www.guru99.com/xml-tutorials.html#11 15/28
4/21/23, 11:19 PM XML Tutorial for Beginners
JSON XML
Display
No display capabilities. Offer display capabilities.
capabilities
Filename
.json .xml
Extension
https://www.json.org/json-e
Website https://www.w3.org/TR/xml11/
n.html
{string:value, .......}
{"books":[
{"name":"Anna Karenina", "author":"Leo Tolstoy"},
{"name":"One Hundred Years of Solitude", "author":"Gabriel Garcia
Marquez"},
{"name":"The Great Gatsby", "author":"Scott Fitzgerald"},
https://www.guru99.com/xml-tutorials.html#11 16/28
4/21/23, 11:19 PM XML Tutorial for Beginners
With XML
XML DTD
What is DTD?
DTD stands for Document Type Definition. It defines the structure of an XML document using
some legal elements. XML DTD is optional.
DTD Rules
Following list shows DTD rules.
https://www.guru99.com/xml-tutorials.html#11 17/28
4/21/23, 11:19 PM XML Tutorial for Beginners
If DTD is present, it must appear at the start of the document (only the XML declaration
can appear above the DTD).
The element declaration must start with an ! mark.
The DTD name and element type of the root element must be the same.
Examples of DTD
Example of an internal DTD:
!DOCTYPE student indicates the beginning of the DTD declaration. And the student is
the root element of the XML document.
!ELEMENT student indicates the student element must contain firstname, lastname and
school elements.
!ELEMENT firstname indicates the firstname element is of type #PCDATA (Parsed
Character Data).
!ELEMENT lastname indicates the lastname element is of type #PCDATA.
!ELEMENT school indicates the school element is of type #PCDATA.
https://www.guru99.com/xml-tutorials.html#11 18/28
4/21/23, 11:19 PM XML Tutorial for Beginners
XML DOM
What is DOM?
DOM stands for Document Object Model. It defines a standard manner of accessing and
manipulating XML documents. DOM has a (hierarchical) tree structure.
Example of DOM
Let’s consider the below XML document.
https://www.guru99.com/xml-tutorials.html#11 19/28
4/21/23, 11:19 PM XML Tutorial for Beginners
</student>
</school>
The tree structure of the above XML file would look like the following image.
XML Validation
XML Namespaces
Why Namespaces?
Namespaces help to avoid element name conflicts.
Namespace Declaration
https://www.guru99.com/xml-tutorials.html#11 20/28
4/21/23, 11:19 PM XML Tutorial for Beginners
<element xmlns:name="URL">
Examples of Namespaces
Following code segment shows an example of namespaces.
XML Editors
There are several XML editors available. Any text editor (such as notepad and so on) can use
as an XML editor.
The following list shows some of the popular XML editors in 2021.
1) XML Notepad:
XML Notepad is an open-source editor for XML . It has a tree view and XSL Output on the left
pane and node text on the right. It has an error-debugging window at the bottom.
Key Statistics:
Link: http://microsoft.github.io/XmlNotepad/
2) Stylus Studio:
Stylus Studio is an IDE written in C++ for Extensible Markup Language ( XML ). It allows a user
to edit and transform XML documents, data such as electronic data interchange(EDI), CSV,
and relational data.
Key Statistics:
Link: http://www.stylusstudio.com/
3) Altova XMLSpy:
XMLSpy is primarily marketed as a JSON and XML Editor. It has a built-in schema designer
and editor. It includes Visual Studio And Eclipse integration.
Key Statistics:
Link: https://www.altova.com/xmlspy-xml-editor
https://www.guru99.com/xml-tutorials.html#11 22/28
4/21/23, 11:19 PM XML Tutorial for Beginners
Key Statistics:
Link: https://www.oxygenxml.com/
5) Xmplify:
Xmplify XML Editor provides a fully XML-aware editing environment with DTD and XML
Schema-based auto, automatic document validation, etc.
Key Statistics:
Link: http://xmplifyapp.com/
XML Parsers
An XML parser is a software library that provides an interface to work with XML documents. It
checks whether the format of the XML document is correct. Some parsers can also validate
the XML documents. Modern-day browsers come with XML parsers.
SAX
SAX stands for Simple API for XML. It is an application program interface (API) for parsing XML
documents. They behave similarly to the event handlers in Java.
https://www.guru99.com/xml-tutorials.html#11 23/28
4/21/23, 11:19 PM XML Tutorial for Beginners
Here are some important differences between the SAX and DOM.
SAX DOM
Document
Simple API
Stands for Object
for XML
Model
Cannot ins
Insert/upd Can insert/
ert/updat
ate/delete update/del
e/delete n
nodes ete nodes
odes
Good
Memory
memory Varies
efficiency
efficiency
Slower
Faster than
Speed than DOM
SAX Parser
Parser
https://www.guru99.com/xml-tutorials.html#11 24/28
4/21/23, 11:19 PM XML Tutorial for Beginners
XML schema-based data binding: Corresponding XML classes are created based on the
schema.
Class-based data binding: A corresponding XML schema is created based on classes.
Mapping-based data binding: It describes how an existing XML schema maps to a set of
classes (and vice-versa).
Examples:
gSOAP
xStream
XML data binding is easy with frameworks. The data binding framework generates a large
amount of code for you. You need to feed in a DTD or XML schema.
XML Schemas
XML schema (also known as XML schema definition or XSD) use to describe the XML
document structure. It is an alternative to DTD.
DTD XSD
DTD XSD
Advantages of XML
Here, pros/benefits of XML:
https://www.guru99.com/xml-tutorials.html#11 26/28
4/21/23, 11:19 PM XML Tutorial for Beginners
Makes documents transportable across systems and applications. With the help of XML,
you can exchange data quickly between different platforms.
XML separates the data from HTML.
Disadvantages of XML
Here are the cons/drawback of using XML:
Summary
XML stands for eXtensible Markup Language. XML is a language (not a programming
language) that uses the markup and can extend.
The main goal is to transport data, not to display data.
XML 1.1 is the latest version. Yet, XML 1.0 is the most used version.
Tags work as pairs except for declarations.
Opening tag + content + closing tag = an element
Entities are a way of representing special characters.
DTD stands for Document Type Definition. It defines the structure of an XML document
using some legal elements. XML DTD is optional.
DOM stands for Document Object Model. It defines a standard manner of accessing and
manipulating XML documents.
Well-formed XML documents are XML documents with correct syntax.
Valid XML documents are well-formed and also conform to the DTD rules.
Namespaces help to avoid element name conflicts.
About
About Us
Advertise with Us
Write For Us
Contact Us
Career Suggestion
SAP Career Suggestion Tool
Software Testing as a Career
Interesting
eBook
Blog
Quiz
SAP eBook
Execute online
Execute Java Online
Execute Javascript
Execute HTML
Execute Python
https://www.guru99.com/xml-tutorials.html#11 28/28