On this lesson, I will provide knowledge about some simple concept, syntax, and basics of XML that a beginner must know.
XML is a meta-markup language that stands for Extensible Markup Language. It was developed by W3C (World Wide Web Consortium). It is used to provide a structure (design) to website pages.
What is a markup language?
Markup languages are such type of languages that are designed for the layout, structure, and design of text and can be understood by both human and machine. They give shape, size, and decoration to texts and web content. HTML and XML are examples of markup languages.
The use of XML is found in Blogspot (Blogger) templates where designers use this language to create a beautiful theme and provide a new look to their websites. It is saved in .xml format but can be stored in other text formats like .txt by specifying its Unicode. So, you can understand that XML is widely used in web designing.
But be clear that XML is not a programming language. It is not used to develop any programs, software or algorithms as it does not qualify and neither does it performs any calculations nor follows any rules of programming.
Basics Components of XML That Beginners Must Know
Coding in XML is easy. But it has its own set of components and rules that we should be follow.
Before learning about syntax and advanced things, you must learn how to start and end a document which I will make you clear on this lesson.
1. XML Elements
A XML document is made by various XML nodes, also known as XML tags or XML elements that are enclosed by brackets “<” and “>”. Take a look:
An XML node must be closed by placing slash before or after of the element to make it valid. Example:
Remember that XML elements are case sensitive. For example <element> and <Element> are different.
One XML element may contain many other XML elements called its “children elements” that should not overlap. The following is incorrect form of XML:
The above XML can be corrected in following ways:
This syntax rule is called nesting of elements.
In above example, <contact-info>…</contact-info> and <name>…</name> are the XML tags that set the start and end of document whereas “Max Dai” is the text value.
2. XML Declaration
An XML document starts by specifying version and encoding which is called its declaration. It should be written in the first line of XML document. It is your choice whether you declare an XML document or not but whenever you do so write it on top of document in first line.
Following is an example of XML declaration:
<?xml version=”1.0″ encoding=”UTF-8″ ?>
In above xml declaration, every element like xml, version and encoding are case sensitive which should be written in lower-case. However, their values can be written in upper case. For example “UTF-8” is the element value of “version” that can be written in upper case. XML Declaration is always optional.
Note: The value of element or tag must be enclosed in quotes (double inverted commas).
A word is formed by a combination of various characters. For example, the word “He” is formed by two alphabets “H” and “e” which are technically called characters. Characters make words and different words form a sentence. This is quite a set of rule in grammar.
But the machine does not understand the script we use to write those characters. Be clear that I am indicating about the font used. For example, the Devanagari and Chinese script.
If you type such characters without specifying encoding then the output will be garbage. You will find some bunch of misconfigured words on the screen. The machine is so stupid without human assistance that it does not understand English as well.
So to help the machine understand, we use character encoding declaration for a different font. They convert various codes into words. For example, to write the Devanagari alphabet “क” we use “UTF-16” encoding. If we write “क” without specifying its Unicode then the machine will show different output. But if we specify its unicode before writing the document, then the output will be fair i.e. “क” will be displayed. Generally, we write our XML document in “UTF-8” encoding.
Hope you guys like this article. On future, I shall write about XML attributes and document. If you find this informatics, please let me know your feedback in comments section below. Be sure to check out other useful information on Advanced Blog.