Struggling with XML? Can't figure out the difference between an entity and a namespace? Fear not - our XML series has all the answers. This introductory article discusses the origins and design goals of XML, the basic rules of XML markup, and how to use elements and attributes in an XML document.
<?xml version="1.0"?>
<recipe>
<name>Chicken Tikka</name>
<author>Anonymous</author>
<date>1
June 1999</date>
<ingredients>
<item>
<desc>Boneless chicken
breasts</desc>
<quantity>2</quantity>
</item>
<item>
<desc>Chopped
onions</desc>
<quantity>2</quantity>
</item>
<item>
<desc>Ginger</desc>
<quantity>1
tsp</quantity>
</item>
<item>
<desc>Garlic</desc>
<quantity>1
tsp</quantity>
</item>
<item>
<desc>Red chili powder</desc>
<quantity>1
tsp</quantity>
</item>
<item>
<desc>Coriander seeds</desc>
<quantity>1
tsp</quantity>
</item>
<item>
<desc>Lime juice</desc>
<quantity>2
tbsp</quantity>
</item>
<item>
<desc>Butter</desc>
<quantity>1
tbsp</quantity>
</item>
</ingredients>
<servings>
3
</servings>
<process>
<step>Cut
chicken into cubes, wash and apply lime juice and salt</step>
<step>Add
ginger, garlic, chili, coriander and lime juice in a separate
bowl</step>
<step>Mix
well, and add chicken to marinate for 3-4 hours</step>
<step>Place chicken
pieces on skewers and barbeque</step>
<step>Remove, apply butter, and
barbeque again until meat is tender</step>
<step>Garnish with lemon and
chopped onions</step>
</process>
</recipe>
Since each markup tag has a name which describes the data contained within it,
it becomes possible to break up an unorganized document into structured, atomic parts. In the example above, the <author> tag identifies the data contained within it to be the name of the recipe author, while the <desc> and <quantity> tags are used to identify ingredients and their respective quantities.
The textual content which appears between the opening and closing tags is referred to as "character data"...or, as the XML specification puts it, "all text that is not markup constitutes the character data of the document." Although this character data may contain alphanumeric characters or symbols, care should be taken to escape special characters like angle brackets and ampersands by replacing them with the corresponding hexadecimal representation or the strings
<
>
&
respectively.
For example, while the following XML markup would generate an error,
to your left < is the yellow brick road
this would be absolutely fine.
to your left < is the yellow brick road
Similarly, while
Barnes & Noble
would produce an error,
Barnes & Noble
would have no trouble at all.
This article copyright Melonfire 2001. All rights reserved.