Tags, Elements and Attributes
- Last UpdatedDec 08, 2025
- 1 minute read
The basic building blocks of a XML file are elements and attributes. Let us look at the sample file again:
<Ship>
<Defaults Surface="SPHULL" XMin="FR40" YMin="0" XMax="FR80"/>
<HullCurve ObjId="SPX951">
<ByPrincipalPlane X="FR30"/>
</HullCurve>
</Ship>
In this file "Ship", "Defaults", "HullCurve" and "ByPrincipalPlane" are elements. The data within the element tags are called attributes. The "Defaults" element for instance, has four attributes: "Surface", "XMin", "XMax" and "YMin". "Surface" is the attribute name and "SPHULL" is the attribute value.
Note: An attribute value must be enclosed within double quotes.
It is the attributes that actually carry the data. Elements organize the attributes into logical groups. If you compare an XML document to a file system, the elements are the directories and the attributes are the files.
An element in the XML file is represented by one or two tags. In this example there are two:
<Ship>
</Ship>
<Ship> is called a "start-tag" and "</Ship>" is the "end-tag". In XML, every start tag must have a corresponding end tag.
Important: XML is case sensitive: <Ship>, <SHIP> and <ship> will be regarded as three different tags.
There is an alternative way to write an element, with only one tag:
<Ship/>
This is called an empty element tag, because when an element written like this it may not have any child elements.