Entity Introduction : Using XML
Previous: Introduction
Next: Data Structures

3. Using XML

Entity uses XML as a textual representation of an application. XML is parsed by Entity into a tree in memory. Everything is marked up from XML, including the user interface, code, and data that an application may use.

Why XML ? While XML does have its share of problems, it is the natural fit for a tree-like markup, and is easily human readable and editable. It's also fairly fast and simple to parse.

Entity does not use all of the XML specification - only a small subset of all that "XML" can entail. All you need to know about XML is a few simple things. We'll use an example to illustrate:

<element attribute="value">
  some data belonging to the outer node
  <child-element attribute="value"/>
  some more data belonging to the outer node

The words used in the above example name the parts of the representation they occupy. An 'element' defines the type of the 'node'. A 'node' is a single entry in an XML document. An attribute is just that - an attribute of the node, and of course, every attribute must have a value. You will also find that we use the word "tag" as synonym for "element".

You will notice from the above example that XML must be 'balanced', and that every tag must be properly closed. You will notice that the second line is closed by using the '/>' - a special notation to allow you to close the node without an explicit closing tag.

In the above example, the 'child-element' node becomes a child of the parent 'element' node. This is because the 'child-element' is declared within the 'element' node - before the 'element' node was closed.

You can also bind 'data' to a node. This is done by having text placed after you start a node, and before you end it. The data will be concatenated and attached to its node. For example:

here is some data..
  <someothertag> bananas and pineapples </someothertag>
here is more data

The string "\nhere is some data..\n \nhere is more data", (\n is a way to say "enter" or "linebreak") will then be bound to the "sometag" node, and "bananas and pineapples" will be bound to the "someothertag"

Another useful XML-ism used in Entity is CDATA. CDATA is just a way to quote the data of a node, so you can use XML's special characters in your data. Here's what it looks like:


data goes here ...
<this won't confuse the parser>


This allows you to insert any kind of text in the CDATA section, without escaping it. This is often used for code sections within Entity.

Similar to CDATA are "processing command" nodes. The XML specification states that the data between <? and ?> markers should be passed straight to the program, without interpretation as XML. This is used to make a less ugly quoted tag. The example for CDATA would look like this with a processing command node instead:


data goes here
<this won't confuse the parser>

Entity Introduction : Using XML
Previous: Introduction
Next: Data Structures