To read the article online, visit http://www.4GuysFromRolla.com/webtech/051000-1.shtml

Getting Started with XML


Chances are you've heard of XML sometime in the past. For about the past year Microsoft has been saying, "XML-this" and "XML-that." This article is intended for those who are brand-spankin' new to XML and are interested in learning what all the buzz is about!

Imagine that you ran an eCommerce site that sold widgets. Through your Web site, users could interact with the Widget Database, seeing real-time information on the widget stock, widget availability, and other relevant information. Being an industrious Widget-retailer, you'd like to be able to offer other Web sites to showcase your Widgets. For example, a Widget-information Web site might be interested in listing the widgets that your company currently had in stock.

Providing such a mechanism is not easy. Ideally, you would want to let this Widget Information site be able to access your Widget database directly, grabbing the needed information. However, perhaps you only want to provide a few tidbits of information and keep the rest secret? Offering database access would not be the best solution. Enter a better solution: XML.

XML, which stands for EXtensible Markup Language, is a means by which data can be stored in an easy to read, textual implementation. XML uses a tag-based implementation similar to HTML. However, unlike HTML, there are no predefined XML tags. The creator of an XML file must define his or her own tags, deciding how these tags describe the data they represent.

XML is a bit more stringent about closing tags than HTML. For example, in HTML, a single tag, like <BR> is acceptable. In XML, however, all tags must have an opening and closing tag, with the data they represent inbetween. XML tags are also case-sensitive.

In our Widget Web Site example, for those widget-information Web sites we might want to provide the following bits of information on all of our widgets:

  • Name
  • Product Number
  • Cost
  • Description

This information could be represented by the following XML document:

<?xml version="1.0"?>
<widgets>
  <widget>
    <name>Widget Name</name>
    <productNumber>Widget Product Number</productNumber>
    <cost>Widget Cost</cost>
    <description>Widget Description</description>
  </widget>
</widgets>

Note that for each widget in the database one of these entries would exist. The actual name, cost, product number, and description of each widget would go in the italicized text areas. Also note the first line, <?xml version="1.0"?>. This line identifies that the document is an XML document, specifically a version 1.0 XML document.

Think of XML as a verbose description of a database table. In our above example, the XML represents a table named widgets. Each row of the table is represented by a widget tag. Each widget row contains four columns: name, productNumber, cost, and description. So, if our Widget Database contained two widgets, our XML document might look like:

<?xml version="1.0"?>
<widgets>
  <widget>
    <name>Oblong Widget</name>
    <productNumber>3432341-12312</productNumber>
    <cost>45.50</cost>
    <description>This widget is useful for jobs requiring
                       oblong tools.</description>
  </widget>

  <widget>
    <name>Skinny Widget</name>
    <productNumber>34323341-1F11</productNumber>
    <cost>55.75</cost>
    <description>This widget is useful for jobs requiring
                       skinny tools.</description>
  </widget>
</widgets>

Save this XML file in your Web directory: /widget.xml.

In Part 2 we'll look at how to iterate through this XML document via an ASP page. Note that in our Widget Database Example, this XML file could be generated each day or on the fly from the Widget Database Web site.

  • Read Part 2


  • Article Information
    Article Title: Getting Started with XML
    Article Author: Scott Mitchell
    Published Date: Wednesday, May 10, 2000
    Article URL: http://www.4GuysFromRolla.com/webtech/051000-1.shtml


    Copyright 2014 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers