|
XML Processing using the Whitebeam Environment
|
OverviewThe Whitebeam system contains a powerful and flexible XML parser. The features of the
parser - and the reprsentation of XML documents processed by the parser - are visible
within the Whitebeam project as a set of JavaScript classes: Class | Description |
---|
XmlParser | Provides access to the underlying parser. You can create different parsers for different activities
within your Presentation Page.
| XmlGeneric | Elements in the XML tree are represented by a number of separate classes, the most common of which
are XmlTag
and XmlText. The
Each of these specific classes share a lot of commonoality and this is documented as a 'virtual' class - XmlGeneric.
It is effectively the base - or super class of each of the specific element types.
| XmlTag | This is arguably the most important JavaScript class - it represents a single XML tag within a
tag tree. The class inherits the behaviour of
XmlGeneric
and adds additional tag specific behaviour.
| XmlText | Represents a text element in the XML tree. Inherits the behaviour of
XmlGeneric
along with behaviour specific to text items.
| XmlComment | Represents an XML comment. Not usually processed by JavaScript - and may actually be removed from the
tree as it is built by setting the parser.removeComments property to 'true'. Comment does however
still have the basic behaviour inherited from the
XmlGeneric
class.
| XmlCData | Represents an XML CDATA section - eg <[CDATA[...]]>. comment. In many cases this cane be treated as
a text element - but the parser represents it nonetheless as a separate class. XmlCData objects inherit
from the
XmlGeneric
class.
| XmlPi | Represents an XML processing instruction. In the Whitebeam environment at the moment support for
processing instructions is minimal - basically the text within the element is made available as the
text of the JavaScript model. Processing of that text must be done manually.comment. XmlPi does however
still have the basic behaviour inherited from the
XmlGeneric
class.
|
Together the classes allow an XML parser to be create - an XML tree to be constructed from a document,
that tree be represented by a collection of specialised JavaScript files. The simplest way to understand
the basics of the environment is to look at a simple example:
// Create a parser.
var aParser = new XmlParser;
// Load some XML from - in this case - a file.
var data = new Binary;
data.load("finename.xml");
// Build the XML tree. If there are no errors then the method
// returns the root of the tree. If there are errors then
// null is returned and the errors are available as
// 'aParser.errors[]'.
if (aParser.build(data)) {
// The tree has been built - we need to execute at least
// part of it to be useful. In this case execute the entire tree.
aParser.root.execute();
}
To understand what is happening now requires an overview of how Whitebeam processes XML data
to build - and make available an XML tree. This is the subject of this tutorial! |
|
(loadtime : 7ms) |