mxml/www/docfiles/Nodes.html
2004-06-21 11:00:28 +00:00

92 lines
3.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>Mini-XML Programmers Manual, Version 2.0</TITLE>
<META NAME="author" CONTENT="Michael Sweet">
<META NAME="copyright" CONTENT="Copyright 2003-2004">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1">
<LINK REL="Start" HREF="index.html">
<LINK REL="Contents" HREF="toc.html">
<LINK REL="Prev" HREF="TheBasics.html">
<LINK REL="Next" HREF="LoadingXML.html">
<STYLE TYPE="text/css"><!--
BODY { font-family: serif }
H1 { font-family: sans-serif }
H2 { font-family: sans-serif }
H3 { font-family: sans-serif }
H4 { font-family: sans-serif }
H5 { font-family: sans-serif }
H6 { font-family: sans-serif }
SUB { font-size: smaller }
SUP { font-size: smaller }
PRE { font-family: monospace }
--></STYLE>
</HEAD>
<BODY>
<A HREF="toc.html">Contents</A>
<A HREF="TheBasics.html">Previous</A>
<A HREF="LoadingXML.html">Next</A>
<HR NOSHADE>
<H2><A NAME="3_2">Nodes</A></H2>
<P>Every piece of information in an XML file (elements, text, numbers)
is stored in memory in &quot;nodes&quot;. Nodes are defined by the <A href="mxmlnodet.html#mxml_node_t">
<TT>mxml_node_t</TT></A> structure. The <A href="mxmltypet.html#mxml_type_t">
<TT>type</TT></A> member defines the node type (element, integer,
opaque, real, or text) which determines which value you want to look at
in the <A href="mxmlvaluet.html#mxml_value_t"><TT>value</TT></A> union.</P>
<P>New nodes can be created using the <A href="mxmlNewElement.html#mxmlNewElement">
<TT>mxmlNewElement()</TT></A>, <A href="mxmlNewInteger.html#mxmlNewInteger">
<TT>mxmlNewInteger()</TT></A>, <A href="mxmlNewOpaque.html#mxmlNewOpaque">
<TT>mxmlNewOpaque()</TT></A>, <A href="mxmlNewReal.html#mxmlNewReal"><TT>
mxmlNewReal()</TT></A>, and <A href="mxmlNewText.html#mxmlNewText"><TT>
mxmlNewText()</TT></A> functions. Only elements can have child nodes,
and the top node must be an element, usually &quot;?xml&quot;.</P>
<P>Each node has pointers for the node above (<TT>parent</TT>), below (<TT>
child</TT>), to the left (<TT>prev</TT>), and to the right (<TT>next</TT>
) of the current node. If you have an XML file like the following:</P>
<PRE>
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;data&gt;
&lt;node&gt;val1&lt;/node&gt;
&lt;node&gt;val2&lt;/node&gt;
&lt;node&gt;val3&lt;/node&gt;
&lt;group&gt;
&lt;node&gt;val4&lt;/node&gt;
&lt;node&gt;val5&lt;/node&gt;
&lt;node&gt;val6&lt;/node&gt;
&lt;/group&gt;
&lt;node&gt;val7&lt;/node&gt;
&lt;node&gt;val8&lt;/node&gt;
&lt;node&gt;val9&lt;/node&gt;
&lt;/data&gt;
</PRE>
<P>the node tree returned by <TT>mxmlLoadFile()</TT> would look like the
following in memory:</P>
<PRE>
?xml
|
data
|
node - node - node - group - node - node - node
| | | | | | |
val1 val2 val3 | val7 val8 val9
|
node - node - node
| | |
val4 val5 val6
</PRE>
<P>where &quot;-&quot; is a pointer to the next node and &quot;|&quot; is a pointer to the
first child node.</P>
<P>Once you are done with the XML data, use the <A href="mxmlDelete.html#mxmlDelete">
<TT>mxmlDelete()</TT></A> function to recursively free the memory that
is used for a particular node or the entire tree:</P>
<PRE>
mxmlDelete(tree);
</PRE>
<HR NOSHADE>
<A HREF="toc.html">Contents</A>
<A HREF="TheBasics.html">Previous</A>
<A HREF="LoadingXML.html">Next</A>
</BODY>
</HTML>