Are you looking to get a job in tech-industry? XML is good and easy to learn. I have been using XML since the day when I launched my first blog several years ago. It uses simple syntax, concept, and structure. So if you want to learn XML, sit back and start reading the lines of XML For Newbies (2017 Edition).
Before We Begin
I took help from my colleagues, expert web developers and different resources found online to collect the best information for learning XML. In addition to that, I have also added examples of my own to improve the learning experience. Despite my best efforts to make this guide the best one, some flaws may be found. I apologize to you and heartily request you to report in the comments section below or use this contact form so that I can improve the guide for everyone. I recommend you to read every line carefully so as to avoid mistakes. Also, if you already know about a part found in this guide, you are free to move on to next section and learn the new part according to your will.
The full form of XML is Extensible Markup Language. It is a markup language developed by W3C (World Wide Web Consortium) for storing data and providing structure to a web page. It can be created and used in any other programming language.
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 information useful, please let me know your feedback in the comments section below. Be sure to check out other useful information on Advanced Blog.