Commit dd903644 authored by Michael R Sweet's avatar Michael R Sweet

Add prototype and definitions for string functions and array types.

parent 243f7076
README - 06/15/2003
README - 06/18/2003
-------------------
CHANGES IN Mini-XML 1.0.1
......@@ -7,6 +7,8 @@ CHANGES IN Mini-XML 1.0.1
allocated string buffers for element names, attribute
names, and attribute values. Previously they were
capped at 16383, 255, and 255 bytes, respectively.
- Added a new mxmlLoadString() function for loading an
XML node tree from a string.
CHANGES IN Mini-XML 1.0
......
TODO - 06/15/2003
TODO - 06/18/2003
-----------------
- Dynamically allocate memory for attribute values.
- Add C++ class.
......@@ -30,8 +30,10 @@
<tbody>
<tr><td><tt>MXML_ELEMENT</tt></td><td>XML element with attributes</td></tr>
<tr><td><tt>MXML_INTEGER</tt></td><td>Integer value</td></tr>
<tr><td><tt>MXML_INTEGER_ARRAY</tt></td><td>Integer array value</td></tr>
<tr><td><tt>MXML_OPAQUE</tt></td><td>Opaque string</td></tr>
<tr><td><tt>MXML_REAL</tt></td><td>Real value</td></tr>
<tr><td><tt>MXML_REAL_ARRAY</tt></td><td>Real array value</td></tr>
<tr><td><tt>MXML_TEXT</tt></td><td>Text fragment</td></tr>
</tbody></table></p>
<h1><a name="_functions">Functions</a></h1>
......@@ -42,6 +44,7 @@
<li><a href="#mxmlElementSetAttr"><tt>mxmlElementSetAttr()</tt></a></li>
<li><a href="#mxmlFindElement"><tt>mxmlFindElement()</tt></a></li>
<li><a href="#mxmlLoadFile"><tt>mxmlLoadFile()</tt></a></li>
<li><a href="#mxmlLoadString"><tt>mxmlLoadString()</tt></a></li>
<li><a href="#mxmlNewElement"><tt>mxmlNewElement()</tt></a></li>
<li><a href="#mxmlNewInteger"><tt>mxmlNewInteger()</tt></a></li>
<li><a href="#mxmlNewOpaque"><tt>mxmlNewOpaque()</tt></a></li>
......@@ -49,6 +52,7 @@
<li><a href="#mxmlNewText"><tt>mxmlNewText()</tt></a></li>
<li><a href="#mxmlRemove"><tt>mxmlRemove()</tt></a></li>
<li><a href="#mxmlSaveFile"><tt>mxmlSaveFile()</tt></a></li>
<li><a href="#mxmlSaveString"><tt>mxmlSaveString()</tt></a></li>
<li><a href="#mxmlWalkNext"><tt>mxmlWalkNext()</tt></a></li>
<li><a href="#mxmlWalkPrev"><tt>mxmlWalkPrev()</tt></a></li>
</ul>
......@@ -215,6 +219,34 @@ mxmlLoadFile(
<h3>Returns</h3>
<p>First node or NULL if the file could not be read.</p>
<hr noshade/>
<h2><a name="mxmlLoadString">mxmlLoadString()</a></h2>
<p>Load a string into an XML node tree.
The nodes in the specified string are added to the specified top node.
If no top node is provided, the XML string MUST be well-formed with a
single parent node like &lt;?xml&gt; for the entire string. The callback
function returns the value type that should be used for child nodes.
If MXML_NO_CALLBACK is specified then all child nodes will be either
MXML_ELEMENT or MXML_TEXT nodes.</p>
<h3>Syntax</h3>
<pre>
<a href="#mxml_node_t">mxml_node_t</a> *
mxmlLoadString(
<a href="#mxml_node_t">mxml_node_t</a> * top,
const char * s,
<a href="#mxml_type_t">mxml_type_t</a> (*cb)(mxml_node_t *));
</pre>
<h3>Arguments</h3>
<p class="table"><table align="center" border="1" width="80%">
<thead><tr><th>Name</th><th>Description</th></tr></thead>
<tbody>
<tr><td><tt>top</tt></td><td>Top node</td></tr>
<tr><td><tt>s</tt></td><td>String to load</td></tr>
<tr><td><tt>(*cb)(mxml_node_t *)</tt></td><td>Callback function or MXML_NO_CALLBACK</td></tr>
</tbody></table></p>
<h3>Returns</h3>
<p>First node or NULL if the string has errors.</p>
<hr noshade/>
<h2><a name="mxmlNewElement">mxmlNewElement()</a></h2>
<p>Create a new element node.
......@@ -382,6 +414,33 @@ mxmlSaveFile(
<h3>Returns</h3>
<p>0 on success, -1 on error.</p>
<hr noshade/>
<h2><a name="mxmlSaveString">mxmlSaveString()</a></h2>
<p>Save an XML node tree to a string.
This function returns the total number of bytes that would be
required for the string but only copies (bufsize - 1) characters
into the specified buffer.</p>
<h3>Syntax</h3>
<pre>
int
mxmlSaveString(
<a href="#mxml_node_t">mxml_node_t</a> * node,
char * buffer,
int bufsize,
int (*cb)(mxml_node_t *int));
</pre>
<h3>Arguments</h3>
<p class="table"><table align="center" border="1" width="80%">
<thead><tr><th>Name</th><th>Description</th></tr></thead>
<tbody>
<tr><td><tt>node</tt></td><td>Node to write</td></tr>
<tr><td><tt>buffer</tt></td><td>String buffer</td></tr>
<tr><td><tt>bufsize</tt></td><td>Size of string buffer</td></tr>
<tr><td><tt>(*cb)(mxml_node_t *int)</tt></td><td>Whitespace callback or MXML_NO_CALLBACK</td></tr>
</tbody></table></p>
<h3>Returns</h3>
<p>Size of string</p>
<hr noshade/>
<h2><a name="mxmlWalkNext">mxmlWalkNext()</a></h2>
<p>Walk to the next logical node in the tree.
......@@ -434,7 +493,9 @@ mxmlWalkPrev(
<h1><a name="_structures">Structures</a></h1>
<ul>
<li><a href="#mxml_attr_s"><tt>mxml_attr_s</tt></a></li>
<li><a href="#mxml_intarray_s"><tt>mxml_intarray_s</tt></a></li>
<li><a href="#mxml_node_s"><tt>mxml_node_s</tt></a></li>
<li><a href="#mxml_realarray_s"><tt>mxml_realarray_s</tt></a></li>
<li><a href="#mxml_text_s"><tt>mxml_text_s</tt></a></li>
<li><a href="#mxml_value_s"><tt>mxml_value_s</tt></a></li>
</ul>
......@@ -457,6 +518,24 @@ struct mxml_attr_s
<tr><td><tt>value</tt></td><td>Attribute value</td></tr>
</tbody></table></p>
<hr noshade/>
<h2><a name="mxml_intarray_s">mxml_intarray_s</a></h2>
<p>An XML integer array value.</p>
<h3>Definition</h3>
<pre>
struct mxml_intarray_s
{
int num_values;
int * values;
};
</pre>
<h3>Members</h3>
<p class="table"><table align="center" border="1" width="80%">
<thead><tr><th>Name</th><th>Description</th></tr></thead>
<tbody>
<tr><td><tt>num_values</tt></td><td>Number of values</td></tr>
<tr><td><tt>values</tt></td><td>The array of values</td></tr>
</tbody></table></p>
<hr noshade/>
<h2><a name="mxml_node_s">mxml_node_s</a></h2>
<p>Data types...</p>
<h3>Definition</h3>
......@@ -485,6 +564,24 @@ struct mxml_node_s
<tr><td><tt>value</tt></td><td>Node value</td></tr>
</tbody></table></p>
<hr noshade/>
<h2><a name="mxml_realarray_s">mxml_realarray_s</a></h2>
<p>An XML real array value.</p>
<h3>Definition</h3>
<pre>
struct mxml_realarray_s
{
int num_values;
double * values;
};
</pre>
<h3>Members</h3>
<p class="table"><table align="center" border="1" width="80%">
<thead><tr><th>Name</th><th>Description</th></tr></thead>
<tbody>
<tr><td><tt>num_values</tt></td><td>Number of values</td></tr>
<tr><td><tt>values</tt></td><td>The array of values</td></tr>
</tbody></table></p>
<hr noshade/>
<h2><a name="mxml_text_s">mxml_text_s</a></h2>
<p>An XML text value.</p>
<h3>Definition</h3>
......@@ -526,7 +623,9 @@ struct mxml_value_s
<ul>
<li><a href="#mxml_attr_t"><tt>mxml_attr_t</tt></a></li>
<li><a href="#mxml_element_t"><tt>mxml_element_t</tt></a></li>
<li><a href="#mxml_intarray_t"><tt>mxml_intarray_t</tt></a></li>
<li><a href="#mxml_node_t"><tt>mxml_node_t</tt></a></li>
<li><a href="#mxml_realarray_t"><tt>mxml_realarray_t</tt></a></li>
<li><a href="#mxml_text_t"><tt>mxml_text_t</tt></a></li>
<li><a href="#mxml_type_t"><tt>mxml_type_t</tt></a></li>
<li><a href="#mxml_value_t"><tt>mxml_value_t</tt></a></li>
......@@ -546,6 +645,13 @@ typedef struct <a href="#mxml_attr_s">mxml_attr_s</a> mxml_attr_t;
typedef struct <a href="#mxml_value_s">mxml_value_s</a> mxml_element_t;
</pre>
<hr noshade/>
<h2><a name="mxml_intarray_t">mxml_intarray_t</a></h2>
<p>An XML integer array value.</p>
<h3>Definition</h3>
<pre>
typedef struct <a href="#mxml_intarray_s">mxml_intarray_s</a> mxml_intarray_t;
</pre>
<hr noshade/>
<h2><a name="mxml_node_t">mxml_node_t</a></h2>
<p>An XML node.</p>
<h3>Definition</h3>
......@@ -553,6 +659,13 @@ typedef struct <a href="#mxml_value_s">mxml_value_s</a> mxml_element_t;
typedef struct <a href="#mxml_node_s">mxml_node_s</a> mxml_node_t;
</pre>
<hr noshade/>
<h2><a name="mxml_realarray_t">mxml_realarray_t</a></h2>
<p>An XML real array value.</p>
<h3>Definition</h3>
<pre>
typedef struct <a href="#mxml_realarray_s">mxml_realarray_s</a> mxml_realarray_t;
</pre>
<hr noshade/>
<h2><a name="mxml_text_t">mxml_text_t</a></h2>
<p>An XML text value.</p>
<h3>Definition</h3>
......@@ -585,9 +698,11 @@ typedef union <a href="#mxml_value_u">mxml_value_u</a> mxml_value_t;
struct mxml_value_u
{
<a href="#mxml_element_t">mxml_element_t</a> element;
<a href="#mxml_intarray_t">mxml_intarray_t</a> intarray;
int integer;
char * opaque;
double real;
<a href="#mxml_realarray_t">mxml_realarray_t</a> realarray;
<a href="#mxml_text_t">mxml_text_t</a> text;
};
</pre>
......@@ -596,9 +711,11 @@ struct mxml_value_u
<thead><tr><th>Name</th><th>Description</th></tr></thead>
<tbody>
<tr><td><tt>element</tt></td><td>Element</td></tr>
<tr><td><tt>intarray</tt></td><td>Integer array</td></tr>
<tr><td><tt>integer</tt></td><td>Integer number</td></tr>
<tr><td><tt>opaque</tt></td><td>Opaque string</td></tr>
<tr><td><tt>real</tt></td><td>Real number</td></tr>
<tr><td><tt>realarray</tt></td><td>Real array</td></tr>
<tr><td><tt>text</tt></td><td>Text fragment</td></tr>
</tbody></table></p>
</body>
......
This diff is collapsed.
/*
* "$Id: mxml.h,v 1.9 2003/06/14 23:56:47 mike Exp $"
* "$Id: mxml.h,v 1.10 2003/06/19 03:20:41 mike Exp $"
*
* Header file for mini-XML, a small XML-like file parsing library.
*
......@@ -68,28 +68,42 @@ typedef enum mxml_type_e /**** The XML node type. ****/
MXML_INTEGER, /* Integer value */
MXML_OPAQUE, /* Opaque string */
MXML_REAL, /* Real value */
MXML_TEXT /* Text fragment */
MXML_TEXT, /* Text fragment */
MXML_INTEGER_ARRAY, /* Integer array value */
MXML_REAL_ARRAY /* Real array value */
} mxml_type_t;
typedef struct mxml_attr_s /**** An XML element attribute value. ****/
{
char *name; /* Attribute name */
char *value; /* Attribute value */
char *name; /* Attribute name */
char *value; /* Attribute value */
} mxml_attr_t;
typedef struct mxml_value_s /**** An XML element value. ****/
{
char *name; /* Name of element */
int num_attrs; /* Number of attributes */
mxml_attr_t *attrs; /* Attributes */
char *name; /* Name of element */
int num_attrs; /* Number of attributes */
mxml_attr_t *attrs; /* Attributes */
} mxml_element_t;
typedef struct mxml_text_s /**** An XML text value. ****/
{
int whitespace; /* Leading whitespace? */
char *string; /* Fragment string */
int whitespace; /* Leading whitespace? */
char *string; /* Fragment string */
} mxml_text_t;
typedef struct mxml_intarray_s /**** An XML integer array value. ****/
{
int num_values; /* Number of values */
int *values; /* The array of values */
} mxml_intarray_t;
typedef struct mxml_realarray_s /**** An XML real array value. ****/
{
int num_values; /* Number of values */
double *values; /* The array of values */
} mxml_realarray_t;
typedef union mxml_value_u /**** An XML node value. ****/
{
mxml_element_t element; /* Element */
......@@ -97,19 +111,21 @@ typedef union mxml_value_u /**** An XML node value. ****/
char *opaque; /* Opaque string */
double real; /* Real number */
mxml_text_t text; /* Text fragment */
mxml_intarray_t intarray; /* Integer array */
mxml_realarray_t realarray; /* Real array */
} mxml_value_t;
typedef struct mxml_node_s mxml_node_t; /**** An XML node. ****/
struct mxml_node_s /**** An XML node. ****/
{
mxml_type_t type; /* Node type */
mxml_node_t *next; /* Next node under same parent */
mxml_node_t *prev; /* Previous node under same parent */
mxml_node_t *parent; /* Parent node */
mxml_node_t *child; /* First child node */
mxml_node_t *last_child; /* Last child node */
mxml_value_t value; /* Node value */
mxml_type_t type; /* Node type */
mxml_node_t *next; /* Next node under same parent */
mxml_node_t *prev; /* Previous node under same parent */
mxml_node_t *parent; /* Parent node */
mxml_node_t *child; /* First child node */
mxml_node_t *last_child; /* Last child node */
mxml_value_t value; /* Node value */
};
......@@ -136,6 +152,8 @@ extern mxml_node_t *mxmlFindElement(mxml_node_t *node, mxml_node_t *top,
const char *value, int descend);
extern mxml_node_t *mxmlLoadFile(mxml_node_t *top, FILE *fp,
mxml_type_t (*cb)(mxml_node_t *));
extern mxml_node_t *mxmlLoadString(mxml_node_t *top, const char *s,
mxml_type_t (*cb)(mxml_node_t *));
extern mxml_node_t *mxmlNewElement(mxml_node_t *parent, const char *name);
extern mxml_node_t *mxmlNewInteger(mxml_node_t *parent, int integer);
extern mxml_node_t *mxmlNewOpaque(mxml_node_t *parent, const char *opaque);
......@@ -145,6 +163,9 @@ extern mxml_node_t *mxmlNewText(mxml_node_t *parent, int whitespace,
extern void mxmlRemove(mxml_node_t *node);
extern int mxmlSaveFile(mxml_node_t *node, FILE *fp,
int (*cb)(mxml_node_t *, int));
extern int mxmlSaveString(mxml_node_t *node, char *buffer,
int bufsize,
int (*cb)(mxml_node_t *, int));
extern mxml_node_t *mxmlWalkNext(mxml_node_t *node, mxml_node_t *top,
int descend);
extern mxml_node_t *mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top,
......@@ -162,5 +183,5 @@ extern mxml_node_t *mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top,
/*
* End of "$Id: mxml.h,v 1.9 2003/06/14 23:56:47 mike Exp $".
* End of "$Id: mxml.h,v 1.10 2003/06/19 03:20:41 mike Exp $".
*/
......@@ -70,6 +70,20 @@ name="top" direction="I"><type>mxml_node_t *</type><description>Top node</descri
<argument name="fp" direction="I"><type>FILE *</type><description>File to read from</description></argument>
<argument name="(*cb)(mxml_node_t *)" direction="I"><type>mxml_type_t</type><description>Callback function or MXML_NO_CALLBACK</description></argument>
</function>
<function name="mxmlLoadString"><returnvalue><description>First node or NULL if the string has errors.</description><type>mxml_node_t
*</type></returnvalue>
<description>Load a string into an XML node tree.
The nodes in the specified string are added to the specified top node.
If no top node is provided, the XML string MUST be well-formed with a
single parent node like &lt;?xml&gt; for the entire string. The callback
function returns the value type that should be used for child nodes.
If MXML_NO_CALLBACK is specified then all child nodes will be either
MXML_ELEMENT or MXML_TEXT nodes.</description><argument
name="top" direction="I"><type>mxml_node_t *</type><description>Top node</description></argument>
<argument name="s" direction="I"><type>const char *</type><description>String to load</description></argument>
<argument name="(*cb)(mxml_node_t *)" direction="I"><type>mxml_type_t</type><description>Callback function or MXML_NO_CALLBACK</description></argument>
</function>
<function name="mxmlNewElement"><returnvalue><description>New node</description><type>mxml_node_t
*</type></returnvalue>
<description>Create a new element node.
......@@ -142,6 +156,17 @@ name="node" direction="I"><type>mxml_node_t *</type><description>Node to write</
<argument name="fp" direction="I"><type>FILE *</type><description>File to write to</description></argument>
<argument name="(*cb)(mxml_node_t *int)" direction="I"><type>int</type><description>Whitespace callback or MXML_NO_CALLBACK</description></argument>
</function>
<function name="mxmlSaveString"><returnvalue><description>Size of string</description><type>int</type></returnvalue>
<description>Save an XML node tree to a string.
This function returns the total number of bytes that would be
required for the string but only copies (bufsize - 1) characters
into the specified buffer.</description><argument
name="node" direction="I"><type>mxml_node_t *</type><description>Node to write</description></argument>
<argument name="buffer" direction="I"><type>char *</type><description>String buffer</description></argument>
<argument name="bufsize" direction="I"><type>int</type><description>Size of string buffer</description></argument>
<argument name="(*cb)(mxml_node_t *int)" direction="I"><type>int</type><description>Whitespace callback or MXML_NO_CALLBACK</description></argument>
</function>
<function name="mxmlWalkNext"><returnvalue><description>Next node or NULL</description><type>mxml_node_t
*</type></returnvalue>
<description>Walk to the next logical node in the tree.
......@@ -172,6 +197,12 @@ name="name"><type>char *</type><description>Attribute name</description></variab
mxml_attr_s</type></typedef>
<typedef name="mxml_element_t"><description>An XML element value.</description><type>struct
mxml_value_s</type></typedef>
<struct name="mxml_intarray_s"><description>An XML integer array value.</description><variable
name="num_values"><type>int</type><description>Number of values</description></variable>
<variable name="values"><type>int *</type><description>The array of values</description></variable>
</struct>
<typedef name="mxml_intarray_t"><description>An XML integer array value.</description><type>struct
mxml_intarray_s</type></typedef>
<struct name="mxml_node_s"><description>Data types...</description><variable
name="child"><type>mxml_node_t *</type><description>First child node</description></variable>
<variable name="last_child"><type>mxml_node_t *</type><description>Last child node</description></variable>
......@@ -182,6 +213,12 @@ name="child"><type>mxml_node_t *</type><description>First child node</descriptio
<variable name="value"><type>mxml_value_t</type><description>Node value</description></variable>
</struct>
<typedef name="mxml_node_t"><type>struct mxml_node_s</type><description>An XML node.</description><description>An XML node.</description></typedef>
<struct name="mxml_realarray_s"><description>An XML real array value.</description><variable
name="num_values"><type>int</type><description>Number of values</description></variable>
<variable name="values"><type>double *</type><description>The array of values</description></variable>
</struct>
<typedef name="mxml_realarray_t"><description>An XML real array value.</description><type>struct
mxml_realarray_s</type></typedef>
<struct name="mxml_text_s"><description>An XML text value.</description><variable
name="string"><type>char *</type><description>Fragment string</description></variable>
<variable name="whitespace"><type>int</type><description>Leading whitespace?</description></variable>
......@@ -191,8 +228,10 @@ mxml_text_s</type></typedef>
<enumeration name="mxml_type_e"><description>The XML node type.</description><constant
name="MXML_ELEMENT"><description>XML element with attributes</description></constant>
<constant name="MXML_INTEGER"><description>Integer value</description></constant>
<constant name="MXML_INTEGER_ARRAY"><description>Integer array value</description></constant>
<constant name="MXML_OPAQUE"><description>Opaque string</description></constant>
<constant name="MXML_REAL"><description>Real value</description></constant>
<constant name="MXML_REAL_ARRAY"><description>Real array value</description></constant>
<constant name="MXML_TEXT"><description>Text fragment</description></constant>
</enumeration>
<typedef name="mxml_type_t"><description>The XML node type.</description><type>enum
......@@ -206,8 +245,10 @@ name="attrs"><type>mxml_attr_t *</type><description>Attributes</description></va
mxml_value_u</type></typedef>
<union name="mxml_value_u"><description>An XML node value.</description><variable
name="element"><type>mxml_element_t</type><description>Element</description></variable>
<variable name="intarray"><type>mxml_intarray_t</type><description>Integer array</description></variable>
<variable name="integer"><type>int</type><description>Integer number</description></variable>
<variable name="opaque"><type>char *</type><description>Opaque string</description></variable>
<variable name="real"><type>double</type><description>Real number</description></variable>
<variable name="realarray"><type>mxml_realarray_t</type><description>Real array</description></variable>
<variable name="text"><type>mxml_text_t</type><description>Text fragment</description></variable>
</union>
/*
* "$Id: testmxml.c,v 1.8 2003/06/14 22:14:17 mike Exp $"
* "$Id: testmxml.c,v 1.9 2003/06/19 03:20:41 mike Exp $"
*
* Test program for mini-XML, a small XML-like file parsing library.
*
......@@ -232,19 +232,23 @@ main(int argc, /* I - Number of command-line args */
* Open the file...
*/
if ((fp = fopen(argv[1], "r")) == NULL)
if (argv[1][0] == '<')
tree = mxmlLoadString(NULL, argv[1], type_cb);
else if ((fp = fopen(argv[1], "r")) == NULL)
{
perror(argv[1]);
return (1);
}
else
{
/*
* Read the file...
*/
/*
* Read the file...
*/
tree = mxmlLoadFile(NULL, fp, type_cb);
tree = mxmlLoadFile(NULL, fp, type_cb);
fclose(fp);
fclose(fp);
}
if (!tree)
{
......@@ -379,5 +383,5 @@ whitespace_cb(mxml_node_t *node, /* I - Element node */
/*
* End of "$Id: testmxml.c,v 1.8 2003/06/14 22:14:17 mike Exp $".
* End of "$Id: testmxml.c,v 1.9 2003/06/19 03:20:41 mike Exp $".
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment