Empty elements in XML

Home » xml » Empty elements in XML
xml No Comments

Empty Elements in XML

Empty elements are elements that do not have any content of their own, this means that they do not keep data inside an opening and closing tags. Instead, they will
have attributes which they will use to store data about the element, to describe it. For example, you might have a main_image element with an attribute containing the file-name of an image, but it has no text content.

Empty elements can combine the opening and closing tags in one or can consist of an opening tag followed immediately by an independent closing tag as seen in the example below.

<main_image file="colossus.jpg"/>

And the second:

<main_image file="colossus.jpg"><main_image/>

Both ways are correct, doing the exact same thing, however I personally prefer the first, the shorter one, I advise you use it to.