| XML Definition Tag |
As you might have noticed, XML is a Markup Language just like HTML, but the difference is XML is extensible, meaning there is no limitation on what element tags you can use. Element tags can be called what ever you like, as long as the syntax adheres to the rules of XML.
While I am mentioning the syntax of XML, I would like to point out that it is very strict for security and performance purposes. Some of these rules are:
- Every element must be represented with and opening and closing tag.
- Every parent element must contain the same child elements.
- Every attribute value must be surrounded with double quotes.
- XML is strictly case sensitive (if it wasn't, it would be 50% slower).
- An XML file must have a single Root element.
But what does XML actually do?
Well...Basically XML doesn't do anything really, it alone, will not display anything in the browser or carry out any processing.
XML is actually a data structure, designed to store data in a self-descriptive way and transport it.
To create an XML file, you don't require any special software or IDE, all you need is a simple text editor and save the file format as ".XML".
So you might be wondering, what does its syntax look like then! What you can see below is a simple example of an XML file:
<?xml version="1.0"?>
<playerList>
<user type="developer">
<name>Clifford Grech</name>
<score>20</score>
<rank>2</rank>
<lastBeatenBy>Rebecca Scerri</lastBeatenBy>
</user>
<user>
<name>Wayne Grech</name>
<score>15</score>
<rank>3</rank>
<lastBeatenBy>Clifford Grech</lastBeatenBy>
</user>
<user>
<name>Rebecca Scerri</name>
<score>25</score>
<rank>1</rank>
<lastBeatenBy>null</lastBeatenBy>
</user>
</playerList>
In the XML code above, the first line simply explains to the browser that this is XML version 1.0, the rest is the actual XML code and as you can see, we have a root element tag named 'playerList', which has 3 child elements named 'user'.
These 'user' elements are also parent elements as each and every one of them has the following set of child elements; 'name','score','rank' and 'lastBeatenBy'.
But as you may have noticed the first 'user' element has an attribute called 'type' and a value has been assigned to this. Attributes don't follow the same rule of elements, meaning if one parent element has an attribute, the others don't have to have the same attribute. This is a good way to store extra information in an element.
You will be able to see more use of XML in my later posts as I will be using it to store the necessary information to implement; login and scoring functionality in my paper tossing game, which I wrote about in previous posts.
No comments:
Post a Comment