1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Using XML</TITLE>
</HEAD>
<BODY text="#000000" bgcolor="#ffffff">
<A HREF="tutorial.html"><EM> Entity Introduction </EM></A>
<b>:</b> <EM>Using XML</EM><BR>
<b>Previous:</b> <A HREF="tutorial2.html"><EM>Introduction</EM></A><BR>
<b>Next:</b> <A HREF="tutorial4.html"><EM>Data Structures</EM></A>
<HR NOSHADE>
<H2><A NAME="3"></A>3. Using XML</H2>
<p>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.</p>
<p>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.</p>
<p>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:</p>
<p>
<blockquote><code>
<pre>
<element attribute="value">
some data belonging to the outer node
<child-element attribute="value"/>
some more data belonging to the outer node
</element>
</pre>
</code></blockquote>
</p>
<p>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".</p>
<p>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.</p>
<p>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.</p>
<p>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:</p>
<p>
<blockquote><code>
<pre>
<sometag>
here is some data..
<someothertag> bananas and pineapples </someothertag>
here is more data
</sometag>
</pre>
</code></blockquote>
</p>
<p>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"</p>
<p>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:</p>
<p>
<blockquote><code>
<pre>
<javascript>
<![CDATA[
data goes here ...
<this won't confuse the parser>
]]>
</javascript>
</pre>
</code></blockquote>
</p>
<p>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.</p>
<p>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:</p>
<p>
<blockquote><code>
<pre>
<?javascript
data goes here
<this won't confuse the parser>
?>
</pre>
</code></blockquote>
</p>
<HR NOSHADE>
<A HREF="tutorial.html"><EM> Entity Introduction </EM></A>
<b>:</b> <EM>Using XML</EM><BR>
<b>Previous:</b> <A HREF="tutorial2.html"><EM>Introduction</EM></A><BR>
<b>Next:</b> <A HREF="tutorial4.html"><EM>Data Structures</EM></A>
</BODY>
</HTML>
|