Extensible Markup Language, commonly known as XML, is a specification allowing custom markup to be used to store information. XML is very useful, in that it allows data to be stored or transferred in an efficient, organised way.
Characters such as &, <, >, ' or " can only be included within an element's content if their entity placeholder is used, similarly to valid HTML.
The example below shows how a recipe could be held in an XML format, allowing the recipes name, preparation time and cooking time to be held with the recipe. In this example, the sample of XML code could be repeated many times within the same XML file, allowing multiple recipes to be held together. Depending on the system being used, it may be more appropriate to hold all data in the same file, or keep each item separately in a separate file.
<recipe name="bread" prep_time="5 mins" cook_time="3 hours">
<title>Basic bread</title>
<ingredient amount="8" unit="dL">Flour</ingredient>
<ingredient amount="10" unit="grams">Yeast</ingredient>
<ingredient amount="4" unit="dL" state="warm">Water</ingredient>
<ingredient amount="1" unit="teaspoon">Salt</ingredient>
<instructions>
<step>Mix all ingredients together.</step>
<step>Knead thoroughly.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Knead again.</step>
<step>Place in a bread baking tin.</step>
<step>Cover with a cloth, and leave for one hour in warm room.</step>
<step>Bake in the oven at 180(degrees)C for 30 minutes.</step>
</instructions>
</recipe>
In this example, the root level element is 'recipe'. This root element's start tag can be preceeded by an XML declaration similar to the example given below.
<?xml version="1.0" encoding="UTF-8"?>
In order to create a well-formed document, the capitalisation of each entities start and end tags should be the same.
Last updated on 28 October 2008, at 20:32.