2014-10-19 17:29:07 +00:00
|
|
|
README - 2014-10-19
|
2003-06-03 19:46:29 +00:00
|
|
|
-------------------
|
|
|
|
|
|
|
|
|
|
|
|
INTRODUCTION
|
|
|
|
|
2014-10-19 17:29:07 +00:00
|
|
|
This README file describes the Mini-XML library version 2.9.
|
2003-06-03 20:40:01 +00:00
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
Mini-XML is a small XML parsing library that you can use to read XML and
|
|
|
|
XML-like data files in your application without requiring large non-standard
|
|
|
|
libraries. Mini-XML only requires an ANSI C compatible compiler (GCC works,
|
|
|
|
as do most vendors' ANSI C compilers) and a "make" program.
|
2003-06-03 19:46:29 +00:00
|
|
|
|
2003-06-04 17:37:23 +00:00
|
|
|
Mini-XML provides the following functionality:
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
- Reading of UTF-8 and UTF-16 and writing of UTF-8 encoded XML files and
|
|
|
|
strings.
|
|
|
|
- Data is stored in a linked-list tree structure, preserving the XML
|
|
|
|
data hierarchy.
|
|
|
|
- Supports arbitrary element names, attributes, and attribute values
|
|
|
|
with no preset limits, just available memory.
|
|
|
|
- Supports integer, real, opaque ("cdata"), and text data types in
|
|
|
|
"leaf" nodes.
|
2003-06-04 17:37:23 +00:00
|
|
|
- Functions for creating and managing trees of data.
|
2009-05-17 17:17:46 +00:00
|
|
|
- "Find" and "walk" functions for easily locating and navigating trees
|
|
|
|
of data.
|
2003-06-04 17:37:23 +00:00
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
Mini-XML doesn't do validation or other types of processing on the data
|
|
|
|
based upon schema files or other sources of definition information.
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
BUILDING Mini-XML
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
Mini-XML comes with an autoconf-based configure script; just type the
|
|
|
|
following command to get things going:
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
./configure
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
The default install prefix is /usr/local, which can be overridden using the
|
|
|
|
--prefix option:
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
./configure --prefix=/foo
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
Other configure options can be found using the --help option:
|
2003-09-29 01:14:51 +00:00
|
|
|
|
|
|
|
./configure --help
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
Once you have configured the software, type "make" to do the build and run
|
|
|
|
the test program to verify that things are working, as follows:
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
make
|
|
|
|
|
2014-01-04 21:50:06 +00:00
|
|
|
If you are using Mini-XML under Microsoft Windows with Visual C++, use the
|
|
|
|
included project files in the "vcnet" subdirectory to build the library
|
2009-05-17 17:17:46 +00:00
|
|
|
instead.
|
2004-06-21 10:58:27 +00:00
|
|
|
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
INSTALLING Mini-XML
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
The "install" target will install Mini-XML in the lib and include
|
|
|
|
directories:
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
make install
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
Once you have installed it, use the "-lmxml" option to link your application
|
|
|
|
against it.
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
The documentation is available in the "doc" subdirectory in the files
|
|
|
|
"mxml.html" (HTML) and "mxml.pdf" (PDF). You can also look at the
|
|
|
|
"testmxml.c" and "mxmldoc.c" source files for examples of using Mini-XML.
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
Mini-XML provides a single header file which you include:
|
|
|
|
|
|
|
|
#include <mxml.h>
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
Nodes are defined by the "mxml_node_t" structure; the "type" member defines
|
|
|
|
the node type (element, integer, opaque, real, or text) which determines
|
|
|
|
which value you want to look at in the "value" union. New nodes can be
|
|
|
|
created using the "mxmlNewElement()", "mxmlNewInteger()", "mxmlNewOpaque()",
|
|
|
|
"mxmlNewReal()", and "mxmlNewText()" functions. Only elements can have
|
|
|
|
child nodes, and the top node must be an element, usually "?xml".
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
You load an XML file using the "mxmlLoadFile()" function:
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
mxml_node_t *tree;
|
|
|
|
|
|
|
|
fp = fopen("filename.xml", "r");
|
|
|
|
tree = mxmlLoadFile(NULL, fp, MXML_NO_CALLBACK);
|
|
|
|
fclose(fp);
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
Similarly, you save an XML file using the "mxmlSaveFile()" function:
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
mxml_node_t *tree;
|
|
|
|
|
|
|
|
fp = fopen("filename.xml", "w");
|
2003-06-04 17:37:23 +00:00
|
|
|
mxmlSaveFile(tree, fp, MXML_NO_CALLBACK);
|
2003-06-03 19:46:29 +00:00
|
|
|
fclose(fp);
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
The "mxmlLoadString()", "mxmlSaveAllocString()", and "mxmlSaveString()"
|
|
|
|
functions load XML node trees from and save XML node trees to strings:
|
2003-07-22 10:29:19 +00:00
|
|
|
|
|
|
|
char buffer[8192];
|
|
|
|
char *ptr;
|
|
|
|
mxml_node_t *tree;
|
|
|
|
|
|
|
|
...
|
|
|
|
tree = mxmlLoadString(NULL, buffer, MXML_NO_CALLBACK);
|
|
|
|
|
|
|
|
...
|
|
|
|
mxmlSaveString(tree, buffer, sizeof(buffer), MXML_NO_CALLBACK);
|
|
|
|
|
|
|
|
...
|
|
|
|
ptr = mxmlSaveAllocString(tree, MXML_NO_CALLBACK);
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
You can find a named element/node using the "mxmlFindElement()" function:
|
2003-06-03 19:46:29 +00:00
|
|
|
|
2003-06-04 16:30:40 +00:00
|
|
|
mxml_node_t *node = mxmlFindElement(tree, tree, "name", "attr",
|
|
|
|
"value", MXML_DESCEND);
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
The "name", "attr", and "value" arguments can be passed as NULL to act as
|
|
|
|
wildcards, e.g.:
|
2003-06-04 16:30:40 +00:00
|
|
|
|
|
|
|
/* Find the first "a" element */
|
|
|
|
node = mxmlFindElement(tree, tree, "a", NULL, NULL, MXML_DESCEND);
|
|
|
|
|
|
|
|
/* Find the first "a" element with "href" attribute */
|
|
|
|
node = mxmlFindElement(tree, tree, "a", "href", NULL, MXML_DESCEND);
|
|
|
|
|
|
|
|
/* Find the first "a" element with "href" to a URL */
|
|
|
|
node = mxmlFindElement(tree, tree, "a", "href",
|
2011-01-03 02:03:29 +00:00
|
|
|
"http://www.minixml.org/",
|
2003-06-04 16:30:40 +00:00
|
|
|
MXML_DESCEND);
|
|
|
|
|
|
|
|
/* Find the first element with a "src" attribute*/
|
|
|
|
node = mxmlFindElement(tree, tree, NULL, "src", NULL, MXML_DESCEND);
|
|
|
|
|
|
|
|
/* Find the first element with a "src" = "foo.jpg" */
|
|
|
|
node = mxmlFindElement(tree, tree, NULL, "src", "foo.jpg",
|
|
|
|
MXML_DESCEND);
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
You can also iterate with the same function:
|
|
|
|
|
|
|
|
mxml_node_t *node;
|
|
|
|
|
2003-06-04 16:30:40 +00:00
|
|
|
for (node = mxmlFindElement(tree, tree, "name", NULL, NULL,
|
|
|
|
MXML_DESCEND);
|
2003-06-03 19:46:29 +00:00
|
|
|
node != NULL;
|
2003-06-04 16:30:40 +00:00
|
|
|
node = mxmlFindElement(node, tree, "name", NULL, NULL,
|
|
|
|
MXML_DESCEND))
|
2003-06-03 19:46:29 +00:00
|
|
|
{
|
|
|
|
... do something ...
|
|
|
|
}
|
|
|
|
|
2011-01-03 02:03:29 +00:00
|
|
|
The "mxmlFindPath()" function finds the (first) value node under a specific
|
2010-11-08 16:07:05 +00:00
|
|
|
element using a "path":
|
|
|
|
|
2011-01-03 02:03:29 +00:00
|
|
|
mxml_node_t *value = mxmlFindPath(tree, "path/to/*/foo/bar");
|
|
|
|
|
|
|
|
The "mxmlGetInteger()", "mxmlGetOpaque()", "mxmlGetReal()", and
|
|
|
|
"mxmlGetText()" functions retrieve the value from a node:
|
|
|
|
|
|
|
|
mxml_node_t *node;
|
|
|
|
|
|
|
|
int intvalue = mxmlGetInteger(node);
|
|
|
|
|
|
|
|
const char *opaquevalue = mxmlGetOpaque(node);
|
|
|
|
|
|
|
|
double realvalue = mxmlGetReal(node);
|
|
|
|
|
|
|
|
int whitespacevalue;
|
|
|
|
const char *textvalue = mxmlGetText(node, &whitespacevalue);
|
|
|
|
|
2009-05-17 17:17:46 +00:00
|
|
|
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:
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
mxmlDelete(tree);
|
|
|
|
|
|
|
|
|
|
|
|
GETTING HELP AND REPORTING PROBLEMS
|
|
|
|
|
2014-01-04 21:50:06 +00:00
|
|
|
The Mini-XML project page provides access to a discussion forum and bug
|
2009-05-17 17:17:46 +00:00
|
|
|
reporting page:
|
2008-01-29 05:28:31 +00:00
|
|
|
|
2014-01-04 21:50:06 +00:00
|
|
|
http://www.msweet.org/projects.php/Mini-XML
|
2003-06-03 19:46:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
LEGAL STUFF
|
|
|
|
|
2014-01-04 21:50:06 +00:00
|
|
|
The Mini-XML library is Copyright 2003-2014 by Michael Sweet. License terms
|
2009-05-17 17:17:46 +00:00
|
|
|
are described in the file "COPYING".
|