mirror of
https://github.com/michaelrsweet/mxml.git
synced 2024-11-17 00:15:31 +00:00
92 lines
3.6 KiB
HTML
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.1</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 "nodes". 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 "?xml".</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>
|
|
<?xml version="1.0"?>
|
|
<data>
|
|
<node>val1</node>
|
|
<node>val2</node>
|
|
<node>val3</node>
|
|
<group>
|
|
<node>val4</node>
|
|
<node>val5</node>
|
|
<node>val6</node>
|
|
</group>
|
|
<node>val7</node>
|
|
<node>val8</node>
|
|
<node>val9</node>
|
|
</data>
|
|
</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 "-" is a pointer to the next node and "|" 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>
|