Martha's COIN 74 Week 8 Exercises
Day Two - XML Documents
SOURCE: Robert D. Cormia's
online text
my comments in blue
My Simple Address
WELL-FORMED XML DOCUMENT
- Root Element For a document to be well-formed it must follow the XML recommendation. Basically a document must have a root element. As an example "<HTML>" is the root element in an HTML document."<address_book>", is our root element. The next guideline is the order in which to open and close. We only have <address_book> in this document, but it is 'well-formed'. Notice that the document displays <address_book/> as the root element is 'empty', i.e., no data.
- One and only one... root element is allowed. A document can not contain two or more root elements. In this example there are two instances of the "<address_book>"</address_book>". You can take a look at the source code of this document if you need to see the code itself. Your browser should return an error.
- FOLE First Open Last End. This is a play on the programming term FILO (First In Last Out). Another guideline which an XML document needs to meet is the order of the end elements, FOLE. Basically, you are required to preserve the symmetric of element nesting. The first opening element is the last closing element. Or close last what you opened first, and close first what you opened last. Whatever. The best example is the root element; it is the first element and it is last ending element.
- Do not try this at home In this simple example, the order of "</names>" and "</name>" were switched. This would cause any XML parser to choke. Actually, you will get a polite error statement about a mismatch, including the line and position number of the first "offense". For those of you using Dreamweaver to code your XML (never too early), the yellow tag error marker will also highlight the mismatch.
- alpha under case-no "xml" An XML tag must start with an alphabetic character (a-z), or underscore(_), and the tags are case-sensitive. An XML tag can not begin with the character combination of "xml"- it's a reserved name (we'll talk about reserved names later). By the way....
- Case matters! Unlike HTML, XML is fully case-sensitive. In this example the closing element for "<record>", "</record>" was replaced by "</Record>". To your computer, ASCII characters are all that matter. An upper case "A" is no more similar to a lower case "a" than it is to "z". Try to stay lower case as a good habit.
ANATOMY OF AN XML DOCUMENT
- Segmented Documents - an XML document may have a Prolog, Root Element, and Epilog. However, nothing can appear above the processing instruction. In order to build a three segmented document, you must omit the processing instruction. While this is 'legal' it is not wise. As such, we won;t spend anymore time on this subject.
- Processing Instruction The <? xxxxx ?> is a special syntax referred to as processing instruction. The most typical example is the XML declaration which indicates to the parser the version of XML this document would adhere to (<?xml version="1.0"?>). Processing instructions are information that the document would provide to the XML parser. What we have been following is the specification of XML version 1.0. In the future there might be additional changes to the XML specification that might grossly vary from the 1.0 recommendations. For upward compatibility it's a great idea to include the version of XML that your document adheres to. In the future we will see different uses for the processing instruction. Notice that the comment containing the "PROLOG" is no longer there. It's because the XML declaration needs to be the first information that the IE5 parser needs to see. The epilog can contain more comments and other processing instructions. Start out your XML documents like this.
Page Created 11/23/06 Assignment Submitted xx/xx/06
Document Last Modified:
© mjraup 2006
Webmaster