Layout files in Magento make use of XML. It can be baffling to see XML for the first time, especially if you're not familiar with XHTML. However, the markup is quite simple once you're used to it.
There is one simple rule in creating a well-formed XML document: Every element must close. An element in XML can close in two ways.
A self-closing element in XML is an element that closes itself. Let us take, as an example, the XML element <thing>
. If this element self-closed, it would look like this:
<thing />
The other way to close an XML element is with a closing tag of the opening tag's type. Therefore, with the <thing>
tag, a valid XML element would look like this:
<thing>Value (if any)</thing>
Just as in HTML and XHTML, XML requires some characters to escape, in order to prevent data in the XML file from being misinterpreted. The characters that you'll need to watch out for in your XML file are:
Character |
Description |
Escape |
---|---|---|
& |
Ampersand |
& |
< |
Less than |
< |
> |
Greater than |
> |
' |
Apostrophe |
' |
" |
Quotation mark |
" |
For example, if you wanted to display A & B > C < D 'E' "F" in our XML file, it would look like this:
A & B > C < D 'E ' "F "
Now that we have a better grasp of XML, we can look more closely at changing the layout using Magento's XML layout.