XML

 


COIN78 - XML Lesson 1: Introduction and Overview



Directions for Online Students

There are many ways to learn a new language, and XML is no different. I personally learn by reading, dissection, and then coding. Examples are -really- important. So I have set up a course with three ways to learn.

  1. For PC users, download and install XMLPad from WMHelp at http://www.wmhelp.com/xmlpad3.htm. This is a free XML Editor with amazing power, and will help you with basic document structure, writing DTDs and XSD for validating your XML model, and some help with XSL. For Mac users, download EditiX from Apple at http://www.apple.com/downloads/macosx/development_tools/editixxmleditor.html
  2. I learn by dissection. For months I scavenged the Web, looking for the ideal files, hoping that it would all be laid out for me. Nope. I -did- find over 100 files, most of them broken, and I fixed as much as I could. We used those for guidance, inspiration, but mostly as examples of what others had done. Remember that these are "buyer beware", but all will give you benefit of some kind. You can choose among dozens of "themes" for your model.
  3. My personal XML mentor, Salim Madjd, put together a wonderful step-by-step class, and the tutorial for this course. These have been significantly modified over the years. For online students, you will probably use these tutorials which use the address book model as a guide.

 

Outcomes

Either way, your goal in this course is to produce a set of files that include your base model, in a nested and empty data structure format, a pair of DTD, a CSS file, a pair of XML schema, and an XSL file. Be creative. The goal of this online course is to help you succeed in learning XML. So let's get started!

Buy an XML book, whatever you enjoy reading, and read about writing well formed and valid XML. That will get us through the first four weeks. After that it's CSS, schema, XSL and XPath, ending with an introduction to RSS, RDF, Google XML sitemaps, and XLink and XPointer.

 

Introduction to XML

  1. What is XML? Where did XML come from? What were the business problems that XML was designed to solve? XML follwed HTML, which in turn followed SGML. All three are markup languages, which have both a syntax and a grammar. Coverpages, an OASIS group, has an excellent website around markup languages.
  2. XML is used in RSS, RDF and Semantic Web technology, XML sitemaps, and Web services. In fact, XHTML is based on XML.
  3. XML is a metalanguage, which allows you to write your own custom markup languages, which you can describe in a DTD or XML schema.
  4. XML is human readable and 'created' but almost always written, and read, by a machine. Web services, SOAP and e-commerce are machine to machine applications of XML.
  5. XML is application agnostic, venfor neutral, and can be read by any 'XML aware application', which typically will employ an XML parser.

Dissection of an XML Example

XML is a way for you to define structured information of all kinds—content, object data, inter-application messages, or syndicated content summaries and represents data apart from visual markup. It separates data from content.

A site could be easily constructed by combining an XML document that holds the content data (your page text, perhaps pointers to specific image files and their dimensions, site navigation, headers/footers, and so on) and an XSL (eXtensible Style sheet Language) document in conjunction with a CSS style sheet that defines how the page is visually constructed.

Why is this important? By separating your content from your data, you have the ability to work on each without affecting the other. For example, content teams could be updating the XML content and image pointers in the XML file at the same time that visual designers are tweaking the CSS style sheet (visual layout) and an integration engineer is fine-tuning the XSL document that pulls it all together. No collisions by three parties trying to check out or open the same HTML file at the same time. Development harmony achieved.

The actual structure of an XML document is straightforward. The following XML document is the data representation of a message from Jane to John:

<?xml version="1.0" encoding="UTF-8"?>
<message>
<from>Jane Doe</from>
<to>John Doe</to>
<date>February 14, 2006</date>
<body>Are the annual report files finished yet?</body>
<priority>high</priority>
<attachments>
<attachment type="jpg">file_1.jpg</attachment>
<attachment type="pdf">file_2.pdf</attachment>
</attachments>
</message>

Note, first, that this (and each well-formed) XML document starts with an XML declaration that defines both the XML version and character encoding used within the document itself. The root node of this particular document is message—wholly appropriate given its content—and that message can contain several properties:

Syntax-wise, XML is both very strict in its interpretation, while reasonably easy to learn and use. Here are a few guiding principles:

In a nutshell, an XML file is simply a text file that wraps data into logical constructs. How those constructs are parsed is another matter.

Dissection of simple.xml

The simple.xml file contains information about a person, their contact information, what they do, their education, and any other general comments. There is only one root node and in this case it is named simple. Nested within it are the nodes, contact, general, and comments. Each of these nodes have nested nodes contained within them as well. Notice that the first line is the XML declaration. It defines the XML version (1.0) and the encoding UTF-8 (8-bit UCS/Unicode Transformation Format, a variable-length character encoding for Unicode). The following is an example of simple.xml with data.

  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <simple>
    <contact>
      <first_name>Jane</first_name>
      <last_name>Doe</last_name>
      <nick_name></nick_name>
      <email_address>janedoe@gmail.com</email_address>
    </contact>
    <general>
      <occupation>Web Designer</occupation>
      <education>BA Fine Arts</education>
      <goals>Start Web Design Company</goals>
    </general>
    <comments>
      <comment>Must take Dreamweaver</comment>
    </comments>
  </simple>

XML will not be displayed like HTML pages in the browser. The XML document will be displayed with color-coded root and child elements. A plus (+) or minus sign (-) to the left of the elements can be clicked to expand or collapse the element structure. To view the raw XML source (without the + and - signs), select "View Page Source" or "View Source" from the browser menu.

Note: In Chrome, Opera, and Safari, only the element text will be displayed. To view the raw XML, you must right click the page and select "View Source".

Homework

Tutorials and Primers

  1. W3 Schools Primer on XML http://www.w3schools.com/web/web_xml.asp
  2. W3 XML Tutorial on XML http://www.w3schools.com/xml/default.asp
  3. TellMe Networks primer on XML: https://studio.tellme.com/general/xmlprimer.html
  4. Overview of XML from Adobe: http://www.adobe.com/devnet/dreamweaver/articles/xml_overview_02.html
  5. Displaying XML data from Adobe: http://www.adobe.com/devnet/dreamweaver/articles/display_xml_data.html
  6. XML FAQ: http://xml.silmaril.ie/basics/whatfor/

 

Links to XML Related Sites

  1. XML.COM
  2. WDVL XML tutorial
  3. Sun Java XML Introduction
  4. IBM'S XML Website
  5. Google Directory on XML

 


Copyright © 2009 - 2010 Robert D. Cormia - June 26, 2010