logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Painting
Heart Disease
Horror Literature
Dating
Hiking & Backpacking
SF/Fantasy Books
Healthy Foods


dailyclick
All times in EST

Full Schedule
g
g HTML Site

BellaOnline's HTML Editor

g

Building an XML File

Guest Author - Elizabeth Connick

If you’re not already familiar with the basic rules of XML, I suggest you start by reading the "XML Basics" article.

An XML file is laid out somewhat differently than an HTML file. With HTML, each page has a head section (with information for the browser on how to display the page) and a body section (the part that lays out code for what the visitor actually sees). XML pages, on the other hand, are made up of nesting elements. Each element consists of an opening and a closing tag, possibly with text or other elements in between.

The only part of an XML document that does not conform to this rule is the very first line, called the XML Prolog. It will look something like this:

<?xml version="1.0" encoding="ISO-8859-15"?>

You may notice that the prolog is similar in format to HTML’s Document Type Declaration, which appears at the beginning of every HTML page. The prolog serves a similar purpose; the first section announces what XML version you used to design your file, and the second section references the file’s character set – in the above example, we’re using the standard Latin alphabet.

Let’s say you are a realtor, and you've decided to build a website that shows your current inventory of houses available for sale. Your XML data file would look something like this:

<?xml version="1.0" encoding="ISO-8859-15"?>
<forsale>

<house id="301">
<address>123 Easy Street</address>
<city>Beverly Hills</city>
<bedrooms>3</bedrooms>
<baths>2</baths>
<price>200,000</price>
<comments>What a bargain!</comments>
</house>

<house id="302">
<address>84 Towering Lane</address>
<city>Malibu</city>
<bedrooms>4</bedrooms>
<baths>2</baths>
<price>400,000</price>
<comments>Ocean view</comments>
</house>

</forsale>

In the above example, the outside element <forsale></forsale> is the document's root element. Every XML document must have one and only one root element, which is the parent for all the other elements in the document. Naturally, an element inside another element is called a child element.

A child element must be nested inside its parent – and it cannot overlap a sibling element's tags. Here is an example of how NOT to build elements:

<house id="301">
<address>
<city>
</address>
</city>
</house>


As with HTML, XML elements can have attributes, which label or define the element. In the case of our house listing database, we used the attribute 'id' in the <house> element. Attributes are completely customizable.

Another helpful tool in XML is the entity. An entity is a piece of text that you can use as shorthand for something else. HTML has entities too, although unlike XML you can't define your own – you can only use the predefined ones. Some examples of entities in HTML are '–' (to insert an n-dash) or '©' (to insert the copyright symbol).

Entities in XML are defined at the beginning of the document and can then be used within any element in that document. To return to the realty database example, let's say we wanted to include the text 'This house is available for immediate viewing. Call us to schedule an appointment.' for some of our listed houses. Rather than type it out for every available house, we can create an entity called 'open' to simplify the process:

<?xml version="1.0" encoding="ISO-8859-15"?>
<!ENTITY open "This house is available for immediate viewing. Call us to schedule an appointment.">

We can then call on this entity within the document. Let's say we decide to put it in the <comments> text:

<house id="301">
<address>123 Easy Street</address>
<city>Beverly Hills</city>
<bedrooms>3</bedrooms>
<baths>2</baths>
<price>200,000</price>
<comments>What a bargain! &open;</comments>
</house>

Congratulations, you can now design and build your own XML files. Next time we'll discuss how to incorporate XML into your HTML pages.
This site needs an editor - click to learn more!

Add Building+an+XML+File to Twitter Add Building+an+XML+File to Facebook Add Building+an+XML+File to MySpace Add Building+an+XML+File to Del.icio.us Digg Building+an+XML+File Add Building+an+XML+File to Yahoo My Web Add Building+an+XML+File to Google Bookmarks Add Building+an+XML+File to Stumbleupon Add Building+an+XML+File to Reddit




RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the HTML Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2013 by Elizabeth Connick. All rights reserved.
This content was written by Elizabeth Connick. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
What's Coming in HTML 5

What is FTP?

HTML Fundamentals - Tables

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2013 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor