A brief guide to XML

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.

  1. The element can self-close.
  2. The element can be closed with a closing tag of its own type.

Self-closing elements in XML

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 />

Closing XML elements normally

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>

Entity escapes in XML

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

&amp;

<

Less than

&lt;

>

Greater than

&gt;

'

Apostrophe

&apos;

"

Quotation mark

&quot;

For example, if you wanted to display A & B > C < D 'E' "F" in our XML file, it would look like this:

A &amp; B &gt; C &lt; D &apos;E &apos; &quot;F &quot;

Now that we have a better grasp of XML, we can look more closely at changing the layout using Magento's XML layout.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset