diff --git a/documentation.html b/documentation.html index 9f30908..083302d 100644 --- a/documentation.html +++ b/documentation.html @@ -70,18 +70,12 @@ MXML_ADD_TO_PARENT can be used to specify a NULL child pointer.
void mxmlAdd( - mxml_node_t * parent, - int where, - mxml_node_t * child, - mxml_node_t * node); + mxml_node_t *parent, int where, mxml_node_t *child, mxml_node_t * node);
Name | Description |
---|---|
parent | Parent node |
where | Where to add, MXML_ADD_BEFORE or MXML_ADD_AFTER |
child | Child node for where or MXML_ADD_TO_PARENT |
node | Node to add |
const char * mxmlElementGetAttr( - mxml_node_t * node, - const char * name); + mxml_node_t *node, const char * name);
Name | Description |
---|---|
node | Element node |
name | Name of attribute |
void mxmlElementSetAttr( - mxml_node_t * node, - const char * name, - const char * value); + mxml_node_t *node, const char *name, const char * value);
Name | Description |
---|---|
node | Element node |
name | Name of attribute |
value | Attribute value |
mxml_node_t * mxmlFindElement( - mxml_node_t * node, - mxml_node_t * top, - const char * name, - const char * attr, - const char * value, - int descend); + mxml_node_t *node, mxml_node_t *top, const char *name, const char *attr, const char *value, int descend);
Name | Description |
---|---|
node | Current node |
top | Top node |
name | Element name or NULL for any |
attr | Attribute name, or NULL for none |
value | Attribute value, or NULL for any |
descend | Descend into tree - MXML_DESCEND, MXML_NO_DESCEND, or MXML_DESCEND_FIRST |
mxml_node_t * mxmlLoadFile( - mxml_node_t * top, - FILE * fp, - mxml_type_t (*cb)(mxml_node_t *)); + mxml_node_t *top, FILE *fp, mxml_type_t (*cb)(mxml_node_t *node));
Name | Description |
---|---|
top | Top node |
fp | File to read from |
(*cb)(mxml_node_t *) | Callback function or MXML_NO_CALLBACK |
(*cb)(mxml_node_t *node) | Callback function or MXML_NO_CALLBACK |
First node or NULL if the file could not be read.
@@ -232,17 +206,13 @@ MXML_ELEMENT or MXML_TEXT nodes.mxml_node_t * mxmlLoadString( - mxml_node_t * top, - const char * s, - mxml_type_t (*cb)(mxml_node_t *)); + mxml_node_t *top, const char *s, mxml_type_t (*cb)(mxml_node_t *node));
Name | Description |
---|---|
top | Top node |
s | String to load |
(*cb)(mxml_node_t *) | Callback function or MXML_NO_CALLBACK |
(*cb)(mxml_node_t *node) | Callback function or MXML_NO_CALLBACK |
First node or NULL if the string has errors.
@@ -257,14 +227,12 @@ element node has no parent.mxml_node_t * mxmlNewElement( - mxml_node_t * parent, - const char * name); + mxml_node_t *parent, const char * name);
Name | Description |
---|---|
parent | Parent node or MXML_NO_PARENT |
name | Name of element |
mxml_node_t * mxmlNewInteger( - mxml_node_t * parent, - int integer); + mxml_node_t *parent, int integer);
Name | Description |
---|---|
parent | Parent node or MXML_NO_PARENT |
integer | Integer value |
mxml_node_t * mxmlNewOpaque( - mxml_node_t * parent, - const char * opaque); + mxml_node_t *parent, const char * opaque);
Name | Description |
---|---|
parent | Parent node or MXML_NO_PARENT |
opaque | Opaque string |
mxml_node_t * mxmlNewReal( - mxml_node_t * parent, - double real); + mxml_node_t *parent, double real);
Name | Description |
---|---|
parent | Parent node or MXML_NO_PARENT |
real | Real number value |
mxml_node_t * mxmlNewText( - mxml_node_t * parent, - int whitespace, - const char * string); + mxml_node_t *parent, int whitespace, const char * string);
Name | Description |
---|---|
parent | Parent node or MXML_NO_PARENT |
whitespace | 1 = leading whitespace, 0 = no whitespace |
string | String |
char * mxmlSaveAllocString( - mxml_node_t * node, - int (*cb)(mxml_node_t *int)); + mxml_node_t *node, int (*cb)(mxml_node_t *node, int ws));
Name | Description |
---|---|
node | Node to write |
(*cb)(mxml_node_t *int) | Whitespace callback or MXML_NO_CALLBACK |
(*cb)(mxml_node_t *node, int ws) | Whitespace callback or MXML_NO_CALLBACK |
Allocated string or NULL
@@ -424,17 +380,13 @@ element tags.int mxmlSaveFile( - mxml_node_t * node, - FILE * fp, - int (*cb)(mxml_node_t *int)); + mxml_node_t *node, FILE *fp, int (*cb)(mxml_node_t *node, int ws));
Name | Description |
---|---|
node | Node to write |
fp | File to write to |
(*cb)(mxml_node_t *int) | Whitespace callback or MXML_NO_CALLBACK |
(*cb)(mxml_node_t *node, int ws) | Whitespace callback or MXML_NO_CALLBACK |
0 on success, -1 on error.
@@ -449,19 +401,13 @@ into the specified buffer.int mxmlSaveString( - mxml_node_t * node, - char * buffer, - int bufsize, - int (*cb)(mxml_node_t *int)); + mxml_node_t *node, char *buffer, int bufsize, int (*cb)(mxml_node_t *node, int ws));
Name | Description |
---|---|
node | Node to write |
buffer | String buffer |
bufsize | Size of string buffer |
(*cb)(mxml_node_t *int) | Whitespace callback or MXML_NO_CALLBACK |
(*cb)(mxml_node_t *node, int ws) | Whitespace callback or MXML_NO_CALLBACK |
Size of string
@@ -476,16 +422,12 @@ the node's children.mxml_node_t * mxmlWalkNext( - mxml_node_t * node, - mxml_node_t * top, - int descend); + mxml_node_t *node, mxml_node_t *top, int descend);
Name | Description |
---|---|
node | Current node |
top | Top node |
descend | Descend into tree - MXML_DESCEND, MXML_NO_DESCEND, or MXML_DESCEND_FIRST |
mxml_node_t * mxmlWalkPrev( - mxml_node_t * node, - mxml_node_t * top, - int descend); + mxml_node_t *node, mxml_node_t *top, int descend);
Name | Description |
---|---|
node | Current node |
top | Top node |
descend | Descend into tree - MXML_DESCEND, MXML_NO_DESCEND, or MXML_DESCEND_FIRST |
Mini-XML provides a single header file which you include:
@@ -129,6 +131,54 @@ href="documentation.html#mxmlNewText">mxmlNewText() functions. Only elements can have child nodes, and the top node must be an element, usually "?xml". ++Each node has pointers for the node above (parent), below (child), +to the left (prev), and to the right (next) of the current +node. If you have an XML file like the following:
+ ++ <?xml version="1.0"?> + <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> ++ +the node tree returned by mxmlLoadFile() would look +like the following in memory:
+ ++ ?xml + | + node - node - node - group - node - node - node + | | | | | | | + val1 val2 val3 | val7 val8 val9 + | + node - node - node + | | | + val4 val5 val6 ++ +where "-" is a pointer to the next node and "|" is a pointer +to the first child node.
+ +Once you are done with the XML data, use the mxmlDelete() +function to recursively free the memory that is used for a +particular node or the entire tree:
+ ++mxmlDelete(tree); ++ +Loading and Saving XML Files
+You load an XML file using the mxmlLoadFile() function:
@@ -142,6 +192,15 @@ tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK); fclose(fp);
The third argument specifies a callback function which +returns the value type of the immediate children for a new +element node: MXML_INTEGER, MXML_OPAQUE, +MXML_REAL, or MXML_TEXT. This function is +called after the element and its attributes have been +read, so you can look at the element name, attributes, and +attribute values to determine the proper value type to return. +The default value type is MXML_TEXT if no callback is used.
+Similarly, you save an XML file using the mxmlSaveFile() function:
@@ -155,6 +214,16 @@ mxmlSaveFile(tree, fp, MXML_NO_CALLBACK); fclose(fp); +Callback functions for saving are used to optionally insert +whitespace before and after elements in the node tree. Your +function will be called up to four times for each element node +with a pointer to the node and a "where" value of +MXML_WS_BEFORE_OPEN, MXML_WS_AFTER_OPEN, +MXML_WS_BEFORE_CLOSE, or MXML_WS_AFTER_CLOSE. +The callback function should return 0 if no whitespace should be +added and the character to insert (space, tab, newline) +otherwise.
+The mxmlLoadString(),
- You can find a named element/node using the Finding and Iterating Nodes
+
+ The mxmlWalkPrev()
+and mxmlWalkNext()functions
+can be used to iterate through the XML node tree: In addition, you can find a named element/node using the mxmlFindElement()
function: Finally, once you are done with the XML data, use the mxmlDelete()
-function to recursively free the memory that is used for a
-particular node or the entire tree: The MXML_DESCEND argument can actually be one of three constants: If you started at "val9" and walked using
+ mxmlWalkPrev(), the order would be reversed,
+ ending at "?xml". You can email me at "mxml at easysw dot com" to
diff --git a/mxml-file.c b/mxml-file.c
index 216e9d2..b6e2688 100644
--- a/mxml-file.c
+++ b/mxml-file.c
@@ -1,5 +1,5 @@
/*
- * "$Id: mxml-file.c,v 1.18 2003/07/23 14:47:17 mike Exp $"
+ * "$Id: mxml-file.c,v 1.19 2003/07/26 17:24:14 mike Exp $"
*
* File loading code for mini-XML, a small XML-like file parsing library.
*
@@ -80,7 +80,7 @@ static int mxml_write_ws(mxml_node_t *node, void *p,
mxml_node_t * /* O - First node or NULL if the file could not be read. */
mxmlLoadFile(mxml_node_t *top, /* I - Top node */
FILE *fp, /* I - File to read from */
- mxml_type_t (*cb)(mxml_node_t *))
+ mxml_type_t (*cb)(mxml_node_t *node))
/* I - Callback function or MXML_NO_CALLBACK */
{
return (mxml_load_data(top, fp, cb, mxml_file_getc));
@@ -101,7 +101,7 @@ mxmlLoadFile(mxml_node_t *top, /* I - Top node */
mxml_node_t * /* O - First node or NULL if the string has errors. */
mxmlLoadString(mxml_node_t *top, /* I - Top node */
const char *s, /* I - String to load */
- mxml_type_t (*cb)(mxml_node_t *))
+ mxml_type_t (*cb)(mxml_node_t *node))
/* I - Callback function or MXML_NO_CALLBACK */
{
return (mxml_load_data(top, &s, cb, mxml_string_getc));
@@ -120,7 +120,7 @@ mxmlLoadString(mxml_node_t *top, /* I - Top node */
char * /* O - Allocated string or NULL */
mxmlSaveAllocString(mxml_node_t *node, /* I - Node to write */
- int (*cb)(mxml_node_t *, int))
+ int (*cb)(mxml_node_t *node, int ws))
/* I - Whitespace callback or MXML_NO_CALLBACK */
{
int bytes; /* Required bytes */
@@ -178,7 +178,7 @@ mxmlSaveAllocString(mxml_node_t *node, /* I - Node to write */
int /* O - 0 on success, -1 on error. */
mxmlSaveFile(mxml_node_t *node, /* I - Node to write */
FILE *fp, /* I - File to write to */
- int (*cb)(mxml_node_t *, int))
+ int (*cb)(mxml_node_t *node, int ws))
/* I - Whitespace callback or MXML_NO_CALLBACK */
{
int col; /* Final column */
@@ -215,7 +215,7 @@ int /* O - Size of string */
mxmlSaveString(mxml_node_t *node, /* I - Node to write */
char *buffer, /* I - String buffer */
int bufsize, /* I - Size of string buffer */
- int (*cb)(mxml_node_t *, int))
+ int (*cb)(mxml_node_t *node, int ws))
/* I - Whitespace callback or MXML_NO_CALLBACK */
{
int col; /* Final column */
@@ -1432,5 +1432,5 @@ mxml_write_ws(mxml_node_t *node, /* I - Current node */
/*
- * End of "$Id: mxml-file.c,v 1.18 2003/07/23 14:47:17 mike Exp $".
+ * End of "$Id: mxml-file.c,v 1.19 2003/07/26 17:24:14 mike Exp $".
*/
diff --git a/mxml.xml b/mxml.xml
index b109e8a..aef9fa0 100644
--- a/mxml.xml
+++ b/mxml.xml
@@ -7,10 +7,8 @@ on the value of the where argument. If the child argument is NULL,
puts the new node at the beginning of the child list (MXML_ADD_BEFORE)
or at the end of the child list (MXML_ADD_AFTER). The constant
MXML_ADD_TO_PARENT can be used to specify a NULL child pointer.
+mxml_node_t *node = mxmlWalkPrev(current, tree, MXML_DESCEND);
+
+mxml_node_t *node = mxmlWalkNext(current, tree, MXML_DESCEND);
+
+
+
+
+
+
-mxmlDelete(tree);
+ ?xml
+ node
+ val1
+ node
+ val2
+ node
+ val3
+ group
+ node
+ val4
+ node
+ val5
+ node
+ val6
+ node
+ val7
+ node
+ val8
+ node
+ val9
+ Getting Help and Reporting Problems