Saturday, December 24, 2005

XML: All You Need to Know in One Easy Lesson

This will be simple. I promise. It won't be "all you need to know" if you are a professional programmer working with XML files, but it will be "all you need to know" to understand the basics of how REALbasic's own XML format works. And you'll have all the foundation you'll need to understand many of the TraverToys. But it will be simple.

After you've mastered this lesson, if you want further details on the "REALbasic XML Project Format" you will find it here:

http://www.realsoftware.com/support/whitepapers/xml/

First, what is XML? XML stands for "eXtensible Markup Language." The "eXtensible" part merely means that the language can be extended, but that's another topic for another time. The important thing to note now is that it is a "markup language."

Second, what does "markup language" mean? Well, suppose you have data that can be expressed as text. That data may be information about a Web page (in which case we might use "XHTML," i.e., eXtensible HyperText Markup Language) or an RB Project (which also has its own XML format, which we'll call "XRBML" for the purposes of this lesson).

So that the textual data is not just a jumble, it must be organized and "marked up" to show what each piece means and/or how the pieces fit together. You need to "mark up" the original textual data with comments or descriptions (also in textual format) to the textual data to fit it into categories and make it understandable.

Third, how can you distinguish the added comments and descriptions from the original textual data? The answer is simple: enclose it within "less than" ("<") and "greater than" (">") symbols.

Example from XHTML:

Suppose your text is "This is really simple!" and you want to show that the word "really" is to be put in bold type. Here's how it is done:

This is <b>really</b> simple!

And it is really simple to separate the original text from the added "mark-ups."

Fourth, XML does have two important rules to know. The first is that the comments always come in matching pairs (note the "<b>" and the "</b>" in the preceding example. The presence of "/" normally means "ends here"; its absence meana "starts here." The matching pairs requirement meants that this is NOT valid XHTML:

This is one paragraph.<p>This is another paragraph.

This IS valid XHTML:

<p>This is one paragraph</p><p>This is another paragraph</p>

That is, valid markup-language "tags" are like bookends. They come in matching pairs, and you need both for it to be valid XML.

Fifth, the other important rule is that the matching pairs need to be "nested" properly. "LIFO" ("Last In, First Out" and FILO ("First In, Last Out") apply here. You have to close the innermost pair before you close any other pair, and so on.

Example from XHTML:

The following is valid XHTML:

This is <i><b>really</b></i> simple!

But the following is invalid XHTML:

This is <i><b>really</i></b> simple!

These two rules followed by XHTML also apply to XRBML, i.e., the XML format for RB Projects. The difference is with the "tags" used (for example, RB uses "<SourceLine>" and "</SourceLine>" as tags to indicate the start and the end of a line of source code.)

Easy, eh? And that's all you need to know about XML to follow the source code and explanations for the TraverToys that work with the XML versions of RB Projects.

Barry Traver



Blog Home Page: http://traverrb.blogspot.com/

Programs and Files Discussed in the Blog: http://traver.org/traverrb/

0 Comments:

Post a Comment

<< Home