Basis of the XML Language


The elements of XML, like the elements of HTML, have a tag attributed at the beginning. The attributes will give supplementary information about the respective element

The XML attributes

You remember the <img src=”picture.gif”> attribute from HTML. The “src” attribute brings additional information about the <img> element.

In HTML, like in XML, the attributes are giving information about the elements that are not a part of data. In the next example, the type of the file is not important for data, but it is important for the application that will process the respective element:

<file type=”gif”>picture.gif</file>


The XML attributes need the quotation signs

The values of the attributes must always be quoted, but you can use simple or double quotes. If the value of the attribute has quotations, it must be put between simple quotation signs, but you can also use the quote signs for the elements contained by the afferent entities.


Elements vs. Attributes in the XML language

Pay attention to the next example:

<pupil sex=”feminine”>











it can be easily observed that the sex is an attribute in the first example. For the second example, it is only an element. Both examples would have the same result. There is no rule about using attributes or elements. A common practice would be to use attributes for HTML and the attributes for XML.


Is it recommended to avoid the attributes in XML?

A few problems that would be raised by the usage of attributes:

  • The attributes can’t contain more values, but the elements can.
  • The attributes can’t have a tree structure, while the elements can.
  • The attributes can’t be easily extended (for the next modifications)
  • The attributes are hard to read and maintain. It is recommended to use the elements for data storage. Use the attributes only for information that is not relevant for the data.


What is an XML element?

An XML element begins with a tag and ends with a tag. An element can contain other elements, simple texts, and also text combinations. The elements can also contain attributes.



<book category=”Programming”>

<title>The basis of PHP</title>





<book category=”Design”>

<title>Web template</title>






In this example, <library> and <book> have elements as content, <author> has a text content. In the same example, only the element <book> has an attribute (category=”Programming”)

Naming rules in XML

The name of the elements in XML must follow the next rules:

  • they can contain letters, numbers or other characters
  • they can’t begin with numbers or orthographic signs
  • the name can begin with the letters xml (XML, Xml, and so)
  • the names can’t contain spaces


Any name can be used, as none of the words is reserved. Try to use descriptive names. The elements containing underscores are great: <name_pupil>, <teacher_name>, etc.

The names must be short and simple like in the next example <name_book> instead of <name_of_the_borrowed_book>

Try to avoid the character “-“ like in the next example <name-pupil>. Some programs would think that you are trying to drop the “pupil” from the “name”.

Leave a Reply

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