Introduction to XML
Start the XML series with a practical introduction to XML tags, attributes, and tree structures.
What is XML?
XML stands for Extensible Markup Language and is developed by the W3C. Starting with this article, we will look at what kinds of systems can be built with XML and why you might choose it.
In this first article, we will focus on XML tags, attributes, and tree structures.
XML is simple and flexible.
<hello>Hello, World!</hello>
An XML tag starts with <tag> and ends with </tag>. When naming tags, you cannot use characters such as !"#\$%&'()\*+,/;<=>?@[\]^`{|}~, and tag names cannot start with - or ..
XML starts with:
<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?>
<book>Yunus Emre Divani</book>
Every book has an ISBN, so we add an isbn attribute to the book element.
<?xml version="1.0" encoding="UTF-8"?>
<book isbn="9759954949">Yunus Emre Divani</book>
Now let's create a book root element and add child elements under it to form our first tree structure.
<?xml version="1.0" encoding="UTF-8"?>
<book isbn="9759954949">
<title>Yunus Emre Divani</title>
<author role="Editor">Selim Yagmur</author>
<language>Turkish</language>
<edition>8</edition>
<date>2014-04-01</date>
</book>

Now let's build a library list by adding two books to the XML tree structure.
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book isbn="9759954949">
<title>Yunus Emre Divani</title>
<author role="Editor">Selim Yagmur</author>
<language>Turkish</language>
<edition>8</edition>
<date>
<year>2014</year>
<month>04</month>
<day>01</day>
</date>
</book>
<book isbn="9753386203">
<title>Risaletun-Nushiyye Yunus Emre</title>
<author role="Translator">Prof. Dr. Umay Turkes Gunay</author>
<language>Turkish</language>
<edition>3</edition>
<date>
<year>2009</year>
<month>01</month>
<day>01</day>
</date>
</book>
</books>
We have created a simple and understandable library list. Of course, in a real project you would customize this structure according to your requirements.
For example, instead of ISBN values, you might need to list books by your own internal numbering system and build sales logic around that. XML makes changes like this easy to apply. You can start by creating your own library list.
As you continue working with XML, its flexibility will become clearer.
References:
- http://www.w3.org/TR/xml/
- http://www.w3schools.com/xml/