XML In plain English

mbvissers.eth
Analytics Vidhya
Published in
2 min readJan 27, 2021

XML is still widely used, so let’s learn the basics!

Photo by Pankaj Patel on Unsplash

What is XML?

XML stands for Extensible Markup Language. It is most commonly used as a way to store data or for building pages in HTML which is very similar in some ways.

XML on itself doesn’t do anything by itself. It is just a way of storing data. Programs can use XML files to store or retrieve data or some programs use it for things such as defining layouts.

Why should I use XML

XML as a data format is widely used and very easy to learn to write. XML as a data format can handle more advanced data than CSV can for example. This might be useful if the data has more depth.

XML is also used in Android Development for styling the app’s pages. It is very similar to HTML which is used in web development, and it can be easily parsed to another data format if needed via certain websites.

Basic syntax

Let’s begin with a very basic XML document. We will create a very simple person data file.

if you’re familiar with XML already or with HTML you already know this format. We create data with so called tags. like <person></person> . Tags must have an opening and a closing tag with the data in between.

In HTML we can close a opening tag like <br /> , but in regular XML this isn’t allowed.

But what if we need more complex data? Let’s check that out.

Nesting

You can insert tags within tags to create more complex data structures. Let’s take a look at one of these.

This person now has a jobs tag with two job tags in between.

Also note the <?xml?> tag at the top. This tells any program or webpage that we’re working with XML. You can see the same with HTML where you would write DOCTYPE html . This is always the same and you can just copy and paste it.

Attributes

Let’s take a look at the following XML file.

Instead of a tag for gender we use an attribute. These are very common in XML and HTML. In HTML we would add tags for style .

An attribute has to be quoted in single or double quotes.

there are no rules about when to use attributes, and when to use nested elements. In HTML they are very useful, but in XML it is best to avoid them.

I hope this has helped.

Have a good day!

--

--

mbvissers.eth
Analytics Vidhya

I occasionally write about programming. Follow me on Twitter @0xmbvissers