PDF. JSON. DOC. Those are three of the many different ways in which data is stored on computers. Another one that you might have seen is XML.
If you look around your computer, you’ve probably got a few XML files lying around. But what do they do?
In this guide, we’re going to discuss what XML is and why it is used. We’ll also walk through an example of an XML file to show how it works in action.
Markup Languages: A Brief Introduction
Before you can understand how XML data works, we’ve got to take a step back and ask ourselves: what is a markup language? Markup languages allow you to add annotations or additional information to a piece of text. These are invisible to the user, but are read by the computer before the piece of text is processed.
- Career Karma matches you with top tech bootcamps
- Get exclusive scholarships and prep courses
One way to think of markup languages is like how teachers “mark up” student homework assignments. They will use a pen to describe how students should improve their work. What the teacher writes on the homework assignment is merely additional information; it’s not actually part of what the student submitted.
Perhaps the most well-known example of a markup language is HTML. HTML describes how a website should be laid out, but you’ll never see it unless you look for the raw code. Your browser turns HTML into a pretty, formatted web page.
What Is XML?
eXtensible Markup Language (XML) defines a particular type of data and how it should be structured. XML is a markup language for the internet and is often used in computer programming languages. It’s derived from another language called the Standard Generalized Markup Languages (SGML), which is the king of the castle when it comes to markup.
XML is commonly used to describe data. For instance, it may store information about a set of blog posts, a set of files on your computer, or a list of recipes in a recipe book application. Data is stored in a simple text format using tags.
XML is self-descriptive. This is because the structure of the data is associated with the data itself.
Unlike a database, you don’t need to build a separate structure to read the file. All the information you need is already available. Consider the following example of XML syntax:
<?xml version="1.0"> <post> <title>What is XML?</title> <by>James Gallagher</by> <slug>/blog/what-is-xml</slug> </post>
This is a piece of code that stores data about this blog post. You’ll see that the post is enclosed within a
<post> tag, and each piece of data about the post has its own tag. Every tag has an obvious name that describes what data it holds. XML tags look similar to HTML tags.
This code doesn’t do anything. You can’t run this file. XML is information stored within tags, and you must write a program in order to use the data you have stored.
How Does XML Work?
The most basic component of a document is an element. These elements have both a beginning and a closing tag and contain a particular piece of content. All elements inside a document are contained within a single, root element.
From our above example,
<post> was our root element. It contains all the tags with data on our blog post.
<slug> are also elements. These give us specific pieces of information about the data stored in our document.
What Tags Can I Use?
You can use whatever attributes you want! That’s right: XML doesn’t have any restrictions on what you should call your tags. This is because the primary intention of the language was to provide a way to easily markup data.
No two use cases are the same, so you need to be able to create your own tags.
The syntax for this data structure resembles that of HTML. Both these technologies use a tag-based syntax in their document types. When you are writing an XML document, all you need to do is define your data within tags. You don’t need to specify data types; an XML reader will handle processing those data types if you intend to read the data you have stored.
What Is XML Used For?
XML is everywhere on computers. Earlier on, we mentioned that you’ve probably come across an XML file at some point on your computer. We started this because XML is used commonly by applications like Microsoft Office to store data about files.
XML is used commonly for keeping track of metadata—data about data—on websites and for software applications. The advantage of storing this metadata in this format is that it can be easily exported, imported, or read across platforms. XML is a standard, so it’s platform-independent.
You’ll find that there are a lot of other markup languages based on it. XHTML, RSS, and WAP all use the XML structure.
How Do You Open an XML File?
XML stores data in plain text. This means that you can open a file with any text editor that you have installed. All you have to do is double click on a file to open it up or right-click and choose a program with which to open the file.
Most Integrated Development Environments (IDEs) used by software developers to create code support reading this language. Many of them also include tools to help you better structure your tags, such as changing the color of tags if there are errors.
XML may not be as popular as it used to be—JSON, another type of data, has largely taken over in many modern applications—but it’s still foundational to the web. A strong standard, XML provides an easy way to store data. Its simple, tag-based structure makes it easy to read and because it is a standard, there are plenty of readers out there that can help you interpret it.
Now you’re ready to start talking about XML like a professional developer!
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.