Teaching Kids Programming – Introduction to XML Data Format


Teaching Kids Programming: Videos on Data Structures and Algorithms

XML Teaching Kids Programming - Introduction to XML Data Format XML

XML Data Format

What is XML?

XML – short for eXtensible Markup Language. XML is a simple-to-understand data format that we use to store and transform the data. With XML, users can define the tags (meta data) and store the data inside the tags or as attributes.

XML stores the data only, and is not responsible for how the data is displayed or interpreted. In XML, users can use their own tags (meta data). XML is human and machine friendly.

Here is a simple XML:

1
2
3
4
5
<?xml version="1.0" encoding="utf-8">
<Person> title="Mr">
  <name>Eric</name>
  <age>10</age>
</Person>>
<?xml version="1.0" encoding="utf-8">
<Person> title="Mr">
  <name>Eric</name>
  <age>10</age>
</Person>>

XML Prolog

As shown above, the first line is the XML Prolog which is optional, but if present, has to be at the begining of the XML document. It declares the version and encoding, and Doctype.

Comments in XML

JSON does not support comments, but in XML, we could have comments (not part of the data or syntax) in the following format:

1
<!-- This is a XML Comment -->
<!-- This is a XML Comment -->

XML Elements

XML elements are represented by tags. In XML, the tags need to be in pairs, one opening tag should match a closing tag. A XML element could contain attributes (see below), other element(s), comments (could be part of anywhere in XML doc)

XML Attributes

Each XML tag/element can contain optional attributes for example:

1
<data a="1" b="2' />
<data a="1" b="2' />

Here, the XML tag/element data has two attributes (key value pairs), a and b respectively.

Escaping XML tags

In JSON, we need to escape double quotes with back slash so that it is not causing trouble as JSON might confuse the double quotes with the syntax.

In XML, we need to escape the tag symbols < and > so XML is not treating them as tags:

1
2
3
<data>
  &lt;This is not a tag&gt;
</data>
<data>
  &lt;This is not a tag&gt;
</data>

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
498 words
Last Post: Teaching Kids Programming - Count Days Spent Together (Intersection of Two Intervals + Line Sweep Algorithm)
Next Post: Simple Bearer Token Credential Wrapper for C# (Azure SDK)

The Permanent URL is: Teaching Kids Programming – Introduction to XML Data Format

Leave a Reply