Use eXtensible Markup Language – XML

This post will examine when to use eXtensible Markup Language (XML).

XML stands for eXtensible Markup Language. Most programmers would probably prefer JSON, which is the other common wire formatting language, but XML does have advantages in certain circumstances.

XML is good for representing documents. For example, the new format of Microsoft Word and PowerPoint ends in “x”, which stands for XML.

XML
XML stands for eXtensible Markup Language.

XML is a textual representation of a tree structure with nodes. There are both simple and complex elements. Complex elements have tags within tags. Look at the picture below for an example.

XML Elements
This picture represents the difference between simple and complex elements.

Further, look at another picture for an illustration of more XML basics.

XML Basics
This picture color codes the basics of XML.

Indentation is used just for readability. In other words, white space is generally discarded.

In XML, unlike HTML, you make up the tag and attribute names to be useful in what you are describing.

XML Terminology

Indentation is often used to capture the nesting of elements.

For example:

  • In the picture below, the <a> tag has two child tags <b>, and <c>.
  • These tags are one level down from the root <a> tag. 
  • You could say <a> is the parent of <b> and <c>.
  • Also, <c> is the parent of <d> and <e>.
  • Text nodes and attribute nodes are considered children of the node itself.

XML as a tree

As a Python programmer, you could write code that traverses down tags, and pulls out information.

Leave a Reply

Your email address will not be published. Required fields are marked *