diff --git a/doc/mxml-cover.opacity b/doc/mxml-cover.opacity index c635102..f6a21e3 100644 Binary files a/doc/mxml-cover.opacity and b/doc/mxml-cover.opacity differ diff --git a/doc/mxml-cover.png b/doc/mxml-cover.png index 7260385..d3ca99d 100644 Binary files a/doc/mxml-cover.png and b/doc/mxml-cover.png differ diff --git a/doc/mxml.3 b/doc/mxml.3 index 2872a60..b082af8 100644 --- a/doc/mxml.3 +++ b/doc/mxml.3 @@ -1,4 +1,4 @@ -.TH mxml 3 "Mini-XML API" "2020-10-09" "Mini-XML API" +.TH mxml 3 "Mini-XML API" "2021-05-30" "Mini-XML API" .SH NAME mxml \- Mini-XML API .SH INCLUDE FILE diff --git a/doc/mxml.epub b/doc/mxml.epub index 8846608..6cfed3f 100644 Binary files a/doc/mxml.epub and b/doc/mxml.epub differ diff --git a/doc/mxml.html b/doc/mxml.html index 0abf8f2..515df0f 100644 --- a/doc/mxml.html +++ b/doc/mxml.html @@ -1,14 +1,14 @@ -
-Michael R Sweet
-Copyright © 2003-2020, All Rights Reserved.
-Mini-XML is a small XML parsing library that you can use to read XML data files or strings in your application without requiring large non-standard libraries. Mini-XML provides the following functionality:
-Reading of UTF-8 and UTF-16 and writing of UTF-8 encoded XML files and strings.
+ + +Michael R Sweet
+Copyright © 2003-2020, All Rights Reserved.
+Mini-XML is a small XML parsing library that you can use to read XML data files or strings in your application without requiring large non-standard libraries. Mini-XML provides the following functionality:
+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.
+Data is stored in a linked-list tree structure, preserving the XML data hierarchy.
SAX (streamed) reading of XML files and strings to minimize memory usage.
+SAX (streamed) reading of XML files and strings to minimize memory usage.
Supports arbitrary element names, attributes, and attribute values with no preset limits, just available memory.
+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.
+Supports integer, real, opaque ("cdata"), and text data types in "leaf" nodes.
Functions for creating and managing trees of data.
+Functions for creating and managing trees of data.
"Find" and "walk" functions for easily locating and navigating trees of data.
+"Find" and "walk" functions for easily locating and navigating trees of data.
Mini-XML doesn't do validation or other types of processing on the data based upon schema files or other sources of definition information.
-Mini-XML was initially developed for the Gutenprint project to replace the rather large and unwieldy libxml2
library with something substantially smaller and easier-to-use. It all began one morning in June of 2003 when Robert posted the following sentence to the developer's list:
-It's bad enough that we require libxml2, but rolling our own XML parser is a bit more than we can handle.
+Mini-XML doesn't do validation or other types of processing on the data based upon schema files or other sources of definition information.
+History
+Mini-XML was initially developed for the Gutenprint project to replace the rather large and unwieldy
+libxml2
library with something substantially smaller and easier-to-use. It all began one morning in June of 2003 when Robert posted the following sentence to the developer's list:+-It's bad enough that we require libxml2, but rolling our own XML parser is a bit more than we can handle.
I then replied with:
--Given the limited scope of what you use in XML, it should be trivial to code a mini-XML API in a few hundred lines of code.
+I then replied with:
++-Given the limited scope of what you use in XML, it should be trivial to code a mini-XML API in a few hundred lines of code.
I took my own challenge and coded furiously for two days to produced the initial public release of Mini-XML, total lines of code: 696. Robert promptly integrated Mini-XML into Gutenprint and removed libxml2.
-Thanks to lots of feedback and support from various developers, Mini-XML has evolved since then to provide a more complete XML implementation and now stands at a whopping 4,186 lines of code, compared to 196,141 lines of code for libxml2 version 2.9.9.
-Resources
-The Mini-XML home page can be found at https://www.msweet.org/mxml. From there you can download the current version of Mini-XML, access the issue tracker, and find other resources.
-Legal Stuff
-The Mini-XML library is copyright © 2003-2019 by Michael R Sweet and is provided under the Apache License Version 2.0 with an exception to allow linking against GPL2/LGPL2-only software. See the files "LICENSE" and "NOTICE" for more information.
-Using Mini-XML
-Mini-XML provides a single header file which you include:
--#include <mxml.h> -
The Mini-XML library is included with your program using the
--lmxml
option:-gcc -o myprogram myprogram.c -lmxml -
If you have the
-pkg-config
software installed, you can use it to determine the proper compiler and linker options for your installation:-gcc `pkg-config --cflags mxml` -o myprogram myprogram.c `pkg-config --libs mxml` -
Loading an XML File
-You load an XML file using the
-mxmlLoadFile
function:mxml_node_t * +
I took my own challenge and coded furiously for two days to produced the initial public release of Mini-XML, total lines of code: 696. Robert promptly integrated Mini-XML into Gutenprint and removed libxml2.
+Thanks to lots of feedback and support from various developers, Mini-XML has evolved since then to provide a more complete XML implementation and now stands at a whopping 4,186 lines of code, compared to 196,141 lines of code for libxml2 version 2.9.9.
+Resources
+The Mini-XML home page can be found at https://www.msweet.org/mxml. From there you can download the current version of Mini-XML, access the issue tracker, and find other resources.
+Legal Stuff
+The Mini-XML library is copyright © 2003-2019 by Michael R Sweet and is provided under the Apache License Version 2.0 with an exception to allow linking against GPL2/LGPL2-only software. See the files "LICENSE" and "NOTICE" for more information.
+Using Mini-XML
+Mini-XML provides a single header file which you include:
++#include <mxml.h> +
The Mini-XML library is included with your program using the
+-lmxml
option:+gcc -o myprogram myprogram.c -lmxml +
If you have the
+pkg-config
software installed, you can use it to determine the proper compiler and linker options for your installation:+gcc `pkg-config --cflags mxml` -o myprogram myprogram.c `pkg-config --libs mxml` +
Loading an XML File
+You load an XML file using the
+mxmlLoadFile
function:-mxml_node_t * mxmlLoadFile(mxml_node_t *top, FILE *fp, mxml_type_t (*cb)(mxml_node_t *));
The
-cb
argument specifies a function that assigns child (value) node types for each element in the document. The callback can be a function you provide or one of the standard functions provided with Mini-XML. For example, to load the XML file "filename.xml" containing text strings you can use theMXML_OPAQUE_CALLBACK
function:FILE *fp; +
The
+cb
argument specifies a function that assigns child (value) node types for each element in the document. The callback can be a function you provide or one of the standard functions provided with Mini-XML. For example, to load the XML file "filename.xml" containing text strings you can use theMXML_OPAQUE_CALLBACK
function:-FILE *fp; mxml_node_t *tree; fp = fopen("filename.xml", "r"); tree = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK); fclose(fp);
Mini-XML also provides functions to load from a file descriptor or string:
-mxml_node_t * +
Mini-XML also provides functions to load from a file descriptor or string:
+-mxml_node_t * mxmlLoadFd(mxml_node_t *top, int fd, mxml_type_t (*cb)(mxml_node_t *)); @@ -424,21 +444,21 @@ mxml_node_t * mxmlLoadString(mxml_node_t *top, const char *s, mxml_type_t (*cb)(mxml_node_t *));
Load Callbacks
-The last argument to the
-mxmlLoad
functions is a callback function which is used to determine the value type of each data node in an XML document. Mini-XML defines several standard callbacks for simple XML data files:-
+
MXML_INTEGER_CALLBACK
: All data nodes contain whitespace-separated integers.Load Callbacks
+The last argument to the
+mxmlLoad
functions is a callback function which is used to determine the value type of each data node in an XML document. Mini-XML defines several standard callbacks for simple XML data files:+
-- -
MXML_INTEGER_CALLBACK
: All data nodes contain whitespace-separated integers.+
MXML_OPAQUE_CALLBACK
: All data nodes contain opaque strings with whitespace preserved.- -
MXML_OPAQUE_CALLBACK
: All data nodes contain opaque strings with whitespace preserved.+
MXML_REAL_CALLBACK
- All data nodes contain whitespace-separated floating-point numbers.- -
MXML_REAL_CALLBACK
- All data nodes contain whitespace-separated floating-point numbers.+
MXML_TEXT_CALLBACK
- All data nodes contain whitespace-separated strings.
MXML_TEXT_CALLBACK
- All data nodes contain whitespace-separated strings.You can provide your own callback functions for more complex XML documents. Your callback function will receive a pointer to the current element node and must return the value type of the immediate children for that element node:
-MXML_CUSTOM
,MXML_INTEGER
,MXML_OPAQUE
,MXML_REAL
, orMXML_TEXT
. The 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 following callback function looks for an attribute named "type" or the element name to determine the value type for its child nodes:
-mxml_type_t +
You can provide your own callback functions for more complex XML documents. Your callback function will receive a pointer to the current element node and must return the value type of the immediate children for that element node:
+MXML_CUSTOM
,MXML_INTEGER
,MXML_OPAQUE
,MXML_REAL
, orMXML_TEXT
. The 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 following callback function looks for an attribute named "type" or the element name to determine the value type for its child nodes:
+-mxml_type_t type_cb(mxml_node_t *node) { const char *type; @@ -462,18 +482,18 @@ type_cb(mxml_node_t *node) return (MXML_TEXT); }
To use this callback function, simply use the name when you call any of the load functions:
-FILE *fp; +
To use this callback function, simply use the name when you call any of the load functions:
+-FILE *fp; mxml_node_t *tree; fp = fopen("filename.xml", "r"); tree = mxmlLoadFile(NULL, fp, type_cb); fclose(fp);
Nodes
-Every piece of information in an XML file is stored in memory in "nodes". Nodes are defined by the
-mxml_node_t
structure. Each node has a typed value, optional user data, a parent node, sibling nodes (previous and next), and potentially child nodes.For example, if you have an XML file like the following:
-<?xml version="1.0" encoding="utf-8"?> +
Nodes
+Every piece of information in an XML file is stored in memory in "nodes". Nodes are defined by the
+mxml_node_t
structure. Each node has a typed value, optional user data, a parent node, sibling nodes (previous and next), and potentially child nodes.For example, if you have an XML file like the following:
+-<?xml version="1.0" encoding="utf-8"?> <data> <node>val1</node> <node>val2</node> @@ -487,8 +507,8 @@ fclose(fp); <node>val8</node> </data>
the node tree for the file would look like the following in memory:
-?xml version="1.0" encoding="utf-8"? +
the node tree for the file would look like the following in memory:
+-?xml version="1.0" encoding="utf-8"? | data | @@ -500,30 +520,30 @@ val1 val2 val3 | val7 val8 | | | val4 val5 val6
where "-" is a pointer to the sibling node and "|" is a pointer to the first child or parent node.
-The
-mxmlGetType
function gets the type of a node:mxml_type_t +
where "-" is a pointer to the sibling node and "|" is a pointer to the first child or parent node.
+The
+mxmlGetType
function gets the type of a node:-mxml_type_t mxmlGetType(mxml_node_t *node);
-
+
MXML_CUSTOM
: A custom value defined by your application,+
-- -
MXML_CUSTOM
: A custom value defined by your application,+
MXML_ELEMENT
: An XML element, CDATA, comment, or processing instruction,- -
MXML_ELEMENT
: An XML element, CDATA, comment, or processing instruction,+
MXML_INTEGER
: A whitespace-delimited integer value,- -
MXML_INTEGER
: A whitespace-delimited integer value,+
MXML_OPAQUE
: An opaque string value that preserves all whitespace,- -
MXML_OPAQUE
: An opaque string value that preserves all whitespace,+
MXML_REAL
: A whitespace-delimited floating point value, or- -
MXML_REAL
: A whitespace-delimited floating point value, or+
MXML_TEXT
: A whitespace-delimited text (fragment) value.
MXML_TEXT
: A whitespace-delimited text (fragment) value.-Note: CDATA, comment, and processing directive nodes are currently stored in memory as special elements. This will be changed in a future major release of Mini-XML.
++-Note: CDATA, comment, and processing directive nodes are currently stored in memory as special elements. This will be changed in a future major release of Mini-XML.
The parent and sibling nodes are accessed using the
-mxmlGetParent
,mxmlGetNextSibling
, andmxmlGetPreviousSibling
functions, while the children of an element node are accessed using themxmlGetFirstChild
ormxmlGetLastChild
functions:mxml_node_t * +
The parent and sibling nodes are accessed using the
+mxmlGetParent
,mxmlGetNextSibling
, andmxmlGetPreviousSibling
functions, while the children of an element node are accessed using themxmlGetFirstChild
ormxmlGetLastChild
functions:-mxml_node_t * mxmlGetFirstChild(mxml_node_t *node); mxml_node_t * @@ -538,13 +558,13 @@ mxmlGetParent(mxml_node_t *node); mxml_node_t * mxmlGetPrevSibling(mxml_node_t *node);
The
-mxmlGetUserData
function gets any user (application) data associated with the node:void * +
The
+mxmlGetUserData
function gets any user (application) data associated with the node:-void * mxmlGetUserData(mxml_node_t *node);
Creating XML Documents
-You can create and update XML documents in memory using the various
-mxmlNew
functions. The following code will create the XML document described in the previous section:mxml_node_t *xml; /* <?xml ... ?> */ +
Creating XML Documents
+You can create and update XML documents in memory using the various
+mxmlNew
functions. The following code will create the XML document described in the previous section:-mxml_node_t *xml; /* <?xml ... ?> */ mxml_node_t *data; /* <data> */ mxml_node_t *node; /* <node> */ mxml_node_t *group; /* <group> */ @@ -574,32 +594,32 @@ data = mxmlNewElement(xml, "data"); node = mxmlNewElement(data, "node"); mxmlNewText(node, 0, "val8");
We start by creating the declaration node common to all XML files using the
-mxmlNewXML
function:xml = mxmlNewXML("1.0"); +
We start by creating the declaration node common to all XML files using the
+mxmlNewXML
function:-xml = mxmlNewXML("1.0");
We then create the
-<data>
node used for this document using themxmlNewElement
function. The first argument specifies the parent node (xml
) while the second specifies the element name (data
):data = mxmlNewElement(xml, "data"); +
We then create the
+<data>
node used for this document using themxmlNewElement
function. The first argument specifies the parent node (xml
) while the second specifies the element name (data
):-data = mxmlNewElement(xml, "data");
Each
-<node>...</node>
in the file is created using themxmlNewElement
andmxmlNewText
functions. The first argument ofmxmlNewText
specifies the parent node (node
). The second argument specifies whether whitespace appears before the text - 0 or false in this case. The last argument specifies the actual text to add:node = mxmlNewElement(data, "node"); +
Each
+<node>...</node>
in the file is created using themxmlNewElement
andmxmlNewText
functions. The first argument ofmxmlNewText
specifies the parent node (node
). The second argument specifies whether whitespace appears before the text - 0 or false in this case. The last argument specifies the actual text to add:-node = mxmlNewElement(data, "node"); mxmlNewText(node, 0, "val1");
The resulting in-memory XML document can then be saved or processed just like one loaded from disk or a string.
-Saving an XML File
-You save an XML file using the
-mxmlSaveFile
function:int +
The resulting in-memory XML document can then be saved or processed just like one loaded from disk or a string.
+Saving an XML File
+You save an XML file using the
+mxmlSaveFile
function:-int mxmlSaveFile(mxml_node_t *node, FILE *fp, mxml_save_cb_t cb);
The
-cb
argument specifies a function that returns the whitespace (if any) that is inserted before and after each element node. TheMXML_NO_CALLBACK
constant tells Mini-XML to not include any extra whitespace. For example, so save an XML file to the file "filename.xml" with no extra whitespace:FILE *fp; +
The
+cb
argument specifies a function that returns the whitespace (if any) that is inserted before and after each element node. TheMXML_NO_CALLBACK
constant tells Mini-XML to not include any extra whitespace. For example, so save an XML file to the file "filename.xml" with no extra whitespace:-FILE *fp; fp = fopen("filename.xml", "w"); mxmlSaveFile(xml, fp, MXML_NO_CALLBACK); fclose(fp);
Mini-XML also provides functions to save to a file descriptor or strings:
-char * +
Mini-XML also provides functions to save to a file descriptor or strings:
+-char * mxmlSaveAllocString(mxml_node_t *node, mxml_save_cb_t cb); int @@ -609,20 +629,20 @@ int mxmlSaveString(mxml_node_t *node, char *buffer, int bufsize, mxml_save_cb_t cb);
Controlling Line Wrapping
-When saving XML documents, Mini-XML normally wraps output lines at column 75 so that the text is readable in terminal windows. The
-mxmlSetWrapMargin
function overrides the default wrap margin for the current thread:void mxmlSetWrapMargin(int column); +
Controlling Line Wrapping
+When saving XML documents, Mini-XML normally wraps output lines at column 75 so that the text is readable in terminal windows. The
+mxmlSetWrapMargin
function overrides the default wrap margin for the current thread:-void mxmlSetWrapMargin(int column);
For example, the following code sets the margin to 132 columns:
-mxmlSetWrapMargin(132); +
For example, the following code sets the margin to 132 columns:
+-mxmlSetWrapMargin(132);
while the following code disables wrapping by setting the margin to 0:
-mxmlSetWrapMargin(0); +
while the following code disables wrapping by setting the margin to 0:
+-mxmlSetWrapMargin(0);
Save Callbacks
-The last argument to the
-mxmlSave
functions is a callback function which is used to automatically insert whitespace in an XML document. Your callback function will be called up to four times for each element node with a pointer to the node and a "where" value ofMXML_WS_BEFORE_OPEN
,MXML_WS_AFTER_OPEN
,MXML_WS_BEFORE_CLOSE
, orMXML_WS_AFTER_CLOSE
. The callback function should returnNULL
if no whitespace should be added or the string to insert (spaces, tabs, carriage returns, and newlines) otherwise.The following whitespace callback can be used to add whitespace to XHTML output to make it more readable in a standard text editor:
-const char * +
Save Callbacks
+The last argument to the
+mxmlSave
functions is a callback function which is used to automatically insert whitespace in an XML document. Your callback function will be called up to four times for each element node with a pointer to the node and a "where" value ofMXML_WS_BEFORE_OPEN
,MXML_WS_AFTER_OPEN
,MXML_WS_BEFORE_CLOSE
, orMXML_WS_AFTER_CLOSE
. The callback function should returnNULL
if no whitespace should be added or the string to insert (spaces, tabs, carriage returns, and newlines) otherwise.The following whitespace callback can be used to add whitespace to XHTML output to make it more readable in a standard text editor:
+-const char * whitespace_cb(mxml_node_t *node, int where) { const char *element; @@ -686,24 +706,24 @@ whitespace_cb(mxml_node_t *node, int where) return (NULL); }
To use this callback function, simply use the name when you call any of the save functions:
-FILE *fp; +
To use this callback function, simply use the name when you call any of the save functions:
+-FILE *fp; mxml_node_t *tree; fp = fopen("filename.xml", "w"); mxmlSaveFile(tree, fp, whitespace_cb); fclose(fp);
Memory Management
-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:void +
Memory Management
+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:-void mxmlDelete(mxml_node_t *tree);
You can also use reference counting to manage memory usage. The
-mxmlRetain
andmxmlRelease
functions increment and decrement a node's use count, respectively. When the use count goes to zero,mxmlRelease
automatically callsmxmlDelete
to actually free the memory used by the node tree. New nodes start with a use count of 1.More About Nodes
-Element Nodes
-Element (
-MXML_ELEMENT
) nodes are created using themxmlNewElement
function. Element attributes are set using themxmlElementSetAttr
andmxmlElementSetAttrf
functions and cleared using themxmlElementDeleteAttr
function:mxml_node_t * +
You can also use reference counting to manage memory usage. The
+mxmlRetain
andmxmlRelease
functions increment and decrement a node's use count, respectively. When the use count goes to zero,mxmlRelease
automatically callsmxmlDelete
to actually free the memory used by the node tree. New nodes start with a use count of 1.More About Nodes
+Element Nodes
+Element (
+MXML_ELEMENT
) nodes are created using themxmlNewElement
function. Element attributes are set using themxmlElementSetAttr
andmxmlElementSetAttrf
functions and cleared using themxmlElementDeleteAttr
function:-mxml_node_t * mxmlNewElement(mxml_node_t *parent, const char *name); void @@ -717,12 +737,12 @@ void mxmlElementSetAttrf(mxml_node_t *node, const char *name, const char *format, ...);
Child nodes are added using the various
-mxmlNew
functions. The top (root) node must be an element, usually created by themxmlNewXML
function:mxml_node_t * +
Child nodes are added using the various
+mxmlNew
functions. The top (root) node must be an element, usually created by themxmlNewXML
function:-mxml_node_t * mxmlNewXML(const char *version);
The
-mxmlGetElement
function retrieves the element name, themxmlElementGetAttr
function retrieves the value string for a named attribute associated with the element. ThemxmlElementGetAttrByIndex
andmxmlElementGetAttrCount
functions retrieve attributes by index:const char * +
The
+mxmlGetElement
function retrieves the element name, themxmlElementGetAttr
function retrieves the value string for a named attribute associated with the element. ThemxmlElementGetAttrByIndex
andmxmlElementGetAttrCount
functions retrieve attributes by index:-const char * mxmlGetElement(mxml_node_t *node); const char * @@ -735,50 +755,50 @@ mxmlElementGetAttrByIndex(mxml_node_t *node, int idx, int mxmlElementGetAttrCount(mxml_node_t *node);
CDATA Nodes
-CDATA (
-MXML_ELEMENT
) nodes are created using themxmlNewCDATA
function:mxml_node_t *mxmlNewCDATA(mxml_node_t *parent, const char *string); +
CDATA Nodes
+CDATA (
+MXML_ELEMENT
) nodes are created using themxmlNewCDATA
function:-mxml_node_t *mxmlNewCDATA(mxml_node_t *parent, const char *string);
The
-mxmlGetCDATA
function retrieves the CDATA string pointer for a node:const char *mxmlGetCDATA(mxml_node_t *node); +
The
+mxmlGetCDATA
function retrieves the CDATA string pointer for a node:-const char *mxmlGetCDATA(mxml_node_t *node);
Comment Nodes
-Because comments are currently stored as element nodes, comment (
-MXML_ELEMENT
) nodes are created using themxmlNewElement
function by including the surrounding "!--" and "--" characters in the element name, for example:mxml_node_t *node = mxmlNewElement("!-- This is a comment --"); +
Comment Nodes
+Because comments are currently stored as element nodes, comment (
+MXML_ELEMENT
) nodes are created using themxmlNewElement
function by including the surrounding "!--" and "--" characters in the element name, for example:-mxml_node_t *node = mxmlNewElement("!-- This is a comment --");
Similarly, the
-mxmlGetElement
function retrieves the comment string pointer for a node, which includes the surrounding "!--" and "--" characters.const char *comment = mxmlGetElement(node); +
Similarly, the
+mxmlGetElement
function retrieves the comment string pointer for a node, which includes the surrounding "!--" and "--" characters.-const char *comment = mxmlGetElement(node); /* returns "!-- This is a comment --" */
Processing Instruction Nodes
-Because processing instructions are currently stored as element nodes, processing instruction (
-MXML_ELEMENT
) nodes are created using themxmlNewElement
function including the surrounding "?" characters:mxml_node_t *node = mxmlNewElement("?xml-stylesheet type=\"text/css\" href=\"style.css\"?"); +
Processing Instruction Nodes
+Because processing instructions are currently stored as element nodes, processing instruction (
+MXML_ELEMENT
) nodes are created using themxmlNewElement
function including the surrounding "?" characters:-mxml_node_t *node = mxmlNewElement("?xml-stylesheet type=\"text/css\" href=\"style.css\"?");
The
-mxmlGetElement
function retrieves the processing instruction string for a node, including the surrounding "?" characters:const char *instr = mxmlGetElement(node); +
The
+mxmlGetElement
function retrieves the processing instruction string for a node, including the surrounding "?" characters:-const char *instr = mxmlGetElement(node); /* returned "?xml-stylesheet type=\"text/css\" href=\"style.css\"?" */
Integer Nodes
-Integer (
-MXML_INTEGER
) nodes are created using themxmlNewInteger
function:mxml_node_t * +
Integer Nodes
+Integer (
+MXML_INTEGER
) nodes are created using themxmlNewInteger
function:-mxml_node_t * mxmlNewInteger(mxml_node_t *parent, int integer);
The
-mxmlGetInteger
function retrieves the integer value for a node:int +
The
+mxmlGetInteger
function retrieves the integer value for a node:-int mxmlGetInteger(mxml_node_t *node);
Opaque String Nodes
-Opaque string (
-MXML_OPAQUE
) nodes are created using themxmlNewOpaque
function:mxml_node_t * +
Opaque String Nodes
+Opaque string (
+MXML_OPAQUE
) nodes are created using themxmlNewOpaque
function:-mxml_node_t * mxmlNewOpaque(mxml_node_t *parent, const char *opaque);
The
-mxmlGetOpaque
function retrieves the opaque string pointer for a node:const char * +
The
+mxmlGetOpaque
function retrieves the opaque string pointer for a node:-const char * mxmlGetOpaque(mxml_node_t *node);
Text Nodes
-Whitespace-delimited text string (
-MXML_TEXT
) nodes are created using themxmlNewText
andmxmlNewTextf
functions. Each text node consists of a text string and (leading) whitespace flag value.mxml_node_t * +
Text Nodes
+Whitespace-delimited text string (
+MXML_TEXT
) nodes are created using themxmlNewText
andmxmlNewTextf
functions. Each text node consists of a text string and (leading) whitespace flag value.-mxml_node_t * mxmlNewText(mxml_node_t *parent, int whitespace, const char *string); @@ -786,39 +806,39 @@ mxml_node_t * mxmlNewTextf(mxml_node_t *parent, int whitespace, const char *format, ...);
The
-mxmlGetText
function retrieves the text string pointer and whitespace flag value for a node:const char * +
The
+mxmlGetText
function retrieves the text string pointer and whitespace flag value for a node:-const char * mxmlGetText(mxml_node_t *node, int *whitespace);
Real Number Nodes
-Real number (
-MXML_REAL
) nodes are created using themxmlNewReal
function:mxml_node_t * +
Real Number Nodes
+Real number (
+MXML_REAL
) nodes are created using themxmlNewReal
function:-mxml_node_t * mxmlNewReal(mxml_node_t *parent, double real);
The
-mxmlGetReal
function retrieves the real number for a node:double +
The
+mxmlGetReal
function retrieves the real number for a node:-double mxmlGetReal(mxml_node_t *node);
Locating Data in an XML Document
-Mini-XML provides many functions for enumerating, searching, and indexing XML documents.
-Finding Nodes
-The
-mxmlFindPath
function finds the (first) value node under a specific element using a "path":mxml_node_t * +
Locating Data in an XML Document
+Mini-XML provides many functions for enumerating, searching, and indexing XML documents.
+Finding Nodes
+The
+mxmlFindPath
function finds the (first) value node under a specific element using a "path":-mxml_node_t * mxmlFindPath(mxml_node_t *node, const char *path);
The
-path
string can contain the "*" wildcard to match a single element node in the hierarchy. For example, the following code will find the first "node" element under the "group" element, first using an explicit path and then using a wildcard:mxml_node_t *value = mxmlFindPath(xml, "data/group/node"); +
The
+path
string can contain the "*" wildcard to match a single element node in the hierarchy. For example, the following code will find the first "node" element under the "group" element, first using an explicit path and then using a wildcard:-mxml_node_t *value = mxmlFindPath(xml, "data/group/node"); mxml_node_t *value = mxmlFindPath(xml, "data/*/node");
The
-mxmlFindElement
function can be used to find a named element, optionally matching an attribute and value:mxml_node_t * +
The
+mxmlFindElement
function can be used to find a named element, optionally matching an attribute and value:-mxml_node_t * mxmlFindElement(mxml_node_t *node, mxml_node_t *top, const char *element, const char *attr, const char *value, int descend);
The "element", "attr", and "value" arguments can be passed as
-NULL
to act as wildcards, e.g.:/* Find the first "a" element */ +
The "element", "attr", and "value" arguments can be passed as
+NULL
to act as wildcards, e.g.:-/* Find the first "a" element */ node = mxmlFindElement(tree, tree, "a", NULL, NULL, MXML_DESCEND); @@ -839,8 +859,8 @@ node = mxmlFindElement(tree, tree, NULL, "src", NULL, node = mxmlFindElement(tree, tree, NULL, "src", "foo.jpg", MXML_DESCEND);
You can also iterate with the same function:
-mxml_node_t *node; +
You can also iterate with the same function:
+-mxml_node_t *node; for (node = mxmlFindElement(tree, tree, "element", NULL, NULL, MXML_DESCEND); @@ -851,18 +871,18 @@ for (node = mxmlFindElement(tree, tree, "element", NULL, ... do something ... }
The
-descend
argument (MXML_DESCEND
in the examples above) can be one of three constants:-
+
MXML_NO_DESCEND
: ignore child nodes in the element hierarchy, instead using siblings (same level) or parent nodes (above) until the top (root) node is reached.The
+descend
argument (MXML_DESCEND
in the examples above) can be one of three constants:+
-- -
MXML_NO_DESCEND
: ignore child nodes in the element hierarchy, instead using siblings (same level) or parent nodes (above) until the top (root) node is reached.+
MXML_DESCEND_FIRST
: start the search with the first child of the node, and then search siblings. You'll normally use this when iterating through direct children of a parent node, e.g. all of the "node" and "group" elements under the "?xml" parent node in the previous example.- -
MXML_DESCEND_FIRST
: start the search with the first child of the node, and then search siblings. You'll normally use this when iterating through direct children of a parent node, e.g. all of the "node" and "group" elements under the "?xml" parent node in the previous example.+
MXML_DESCEND
: search child nodes first, then sibling nodes, and then parent nodes.
MXML_DESCEND
: search child nodes first, then sibling nodes, and then parent nodes.Iterating Nodes
-While the
-mxmlFindNode
andmxmlFindPath
functions will find a particular element node, sometimes you need to iterate over all nodes. ThemxmlWalkNext
andmxmlWalkPrev
functions can be used to iterate through the XML node tree:mxml_node_t * +
Iterating Nodes
+While the
+mxmlFindNode
andmxmlFindPath
functions will find a particular element node, sometimes you need to iterate over all nodes. ThemxmlWalkNext
andmxmlWalkPrev
functions can be used to iterate through the XML node tree:-mxml_node_t * mxmlWalkNext(mxml_node_t *node, mxml_node_t *top, int descend); @@ -870,8 +890,8 @@ mxml_node_t * mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top, int descend);
Depending on the value of the
-descend
argument, these functions will automatically traverse child, sibling, and parent nodes until thetop
node is reached. For example, the following code will iterate over all of the nodes in the sample XML document in the previous section:mxml_node_t *node; +
Depending on the value of the
+descend
argument, these functions will automatically traverse child, sibling, and parent nodes until thetop
node is reached. For example, the following code will iterate over all of the nodes in the sample XML document in the previous section:-mxml_node_t *node; for (node = xml; node != NULL; @@ -880,8 +900,8 @@ for (node = xml; ... do something ... }
The nodes will be returned in the following order:
-<?xml version="1.0" encoding="utf-8"?> +
The nodes will be returned in the following order:
+-<?xml version="1.0" encoding="utf-8"?> <data> <node> val1 @@ -901,33 +921,33 @@ val7 <node> val8
Indexing
-The
-mxmlIndexNew
function allows you to create an index of nodes for faster searching and enumeration:mxml_index_t * +
Indexing
+The
+mxmlIndexNew
function allows you to create an index of nodes for faster searching and enumeration:-mxml_index_t * mxmlIndexNew(mxml_node_t *node, const char *element, const char *attr);
The
-element
andattr
arguments control which elements are included in the index. Ifelement
is notNULL
then only elements with the specified name are added to the index. Similarly, ifattr
is notNULL
then only elements containing the specified attribute are added to the index. The nodes are sorted in the index.For example, the following code creates an index of all "id" values in an XML document:
-mxml_index_t *ind = mxmlIndexNew(xml, NULL, "id"); +
The
+element
andattr
arguments control which elements are included in the index. Ifelement
is notNULL
then only elements with the specified name are added to the index. Similarly, ifattr
is notNULL
then only elements containing the specified attribute are added to the index. The nodes are sorted in the index.For example, the following code creates an index of all "id" values in an XML document:
+-mxml_index_t *ind = mxmlIndexNew(xml, NULL, "id");
Once the index is created, the
-mxmlIndexFind
function can be used to find a matching node:mxml_node_t * +
Once the index is created, the
+mxmlIndexFind
function can be used to find a matching node:-mxml_node_t * mxmlIndexFind(mxml_index_t *ind, const char *element, const char *value);
For example, the following code will find the element whose "id" string is "42":
-mxml_node_t *node = mxmlIndexFind(ind, NULL, "42"); +
For example, the following code will find the element whose "id" string is "42":
+-mxml_node_t *node = mxmlIndexFind(ind, NULL, "42");
Alternately, the
-mxmlIndexReset
andmxmlIndexEnum
functions can be used to enumerate the nodes in the index:mxml_node_t * +
Alternately, the
+mxmlIndexReset
andmxmlIndexEnum
functions can be used to enumerate the nodes in the index:-mxml_node_t * mxmlIndexReset(mxml_index_t *ind); mxml_node_t * mxmlIndexEnum(mxml_index_t *ind);
Typically these functions will be used in a
-for
loop:mxml_node_t *node; +
Typically these functions will be used in a
+for
loop:-mxml_node_t *node; for (node = mxmlIndexReset(ind); node != NULL; @@ -936,22 +956,22 @@ for (node = mxmlIndexReset(ind); ... do something ... }
The
-mxmlIndexCount
function returns the number of nodes in the index:int +
The
+mxmlIndexCount
function returns the number of nodes in the index:-int mxmlIndexGetCount(mxml_index_t *ind);
Finally, the
-mxmlIndexDelete
function frees all memory associated with the index:void +
Finally, the
+mxmlIndexDelete
function frees all memory associated with the index:-void mxmlIndexDelete(mxml_index_t *ind);
Custom Data Types
-Mini-XML supports custom data types via per-thread load and save callbacks. Only a single set of callbacks can be active at any time for the current thread, however your callbacks can store additional information in order to support multiple custom data types as needed. The
-MXML_CUSTOM
node type identifies custom data nodes.The
-mxmlGetCustom
function retrieves the custom value pointer for a node.const void * +
Custom Data Types
+Mini-XML supports custom data types via per-thread load and save callbacks. Only a single set of callbacks can be active at any time for the current thread, however your callbacks can store additional information in order to support multiple custom data types as needed. The
+MXML_CUSTOM
node type identifies custom data nodes.The
+mxmlGetCustom
function retrieves the custom value pointer for a node.-const void * mxmlGetCustom(mxml_node_t *node);
Custom (
-MXML_CUSTOM
) nodes are created using themxmlNewCustom
function or using a custom per-thread load callbacks specified using themxmlSetCustomHandlers
function:typedef void (*mxml_custom_destroy_cb_t)(void *); +
Custom (
+MXML_CUSTOM
) nodes are created using themxmlNewCustom
function or using a custom per-thread load callbacks specified using themxmlSetCustomHandlers
function:-typedef void (*mxml_custom_destroy_cb_t)(void *); typedef int (*mxml_custom_load_cb_t)(mxml_node_t *, const char *); typedef char *(*mxml_custom_save_cb_t)(mxml_node_t *); @@ -967,8 +987,8 @@ void mxmlSetCustomHandlers(mxml_custom_load_cb_t load, mxml_custom_save_cb_t save);
The load callback receives a pointer to the current data node and a string of opaque character data from the XML source with character entities converted to the corresponding UTF-8 characters. For example, if we wanted to support a custom date/time type whose value is encoded as "yyyy-mm-ddThh:mm:ssZ" (ISO format), the load callback would look like the following:
-typedef struct +
The load callback receives a pointer to the current data node and a string of opaque character data from the XML source with character entities converted to the corresponding UTF-8 characters. For example, if we wanted to support a custom date/time type whose value is encoded as "yyyy-mm-ddThh:mm:ssZ" (ISO format), the load callback would look like the following:
+-typedef struct { unsigned year, /* Year */ month, /* Month */ @@ -1055,9 +1075,9 @@ load_custom(mxml_node_t *node, const char *data) return (0); }
The function itself can return 0 on success or -1 if it is unable to decode the custom data or the data contains an error. Custom data nodes contain a
-void
pointer to the allocated custom data for the node and a pointer to a destructor function which will free the custom data when the node is deleted. In this example, we use the standardfree
function since everything is contained in a single calloc'd block.The save callback receives the node pointer and returns an allocated string containing the custom data value. The following save callback could be used for our ISO date/time type:
-char * +
The function itself can return 0 on success or -1 if it is unable to decode the custom data or the data contains an error. Custom data nodes contain a
+void
pointer to the allocated custom data for the node and a pointer to a destructor function which will free the custom data when the node is deleted. In this example, we use the standardfree
function since everything is contained in a single calloc'd block.The save callback receives the node pointer and returns an allocated string containing the custom data value. The following save callback could be used for our ISO date/time type:
+-char * save_custom(mxml_node_t *node) { char data[255]; @@ -1074,13 +1094,13 @@ save_custom(mxml_node_t *node) return (strdup(data)); }
You register the callback functions using the
-mxmlSetCustomHandlers
function:mxmlSetCustomHandlers(load_custom, save_custom); +
You register the callback functions using the
+mxmlSetCustomHandlers
function:-mxmlSetCustomHandlers(load_custom, save_custom);
SAX (Stream) Loading of Documents
-Mini-XML supports an implementation of the Simple API for XML (SAX) which allows you to load and process an XML document as a stream of nodes. Aside from allowing you to process XML documents of any size, the Mini-XML implementation also allows you to retain portions of the document in memory for later processing.
-The
-mxmlSAXLoadFd
,mxmlSAXLoadFile
, andmxmlSAXLoadString
functions provide the SAX loading APIs:mxml_node_t * +
SAX (Stream) Loading of Documents
+Mini-XML supports an implementation of the Simple API for XML (SAX) which allows you to load and process an XML document as a stream of nodes. Aside from allowing you to process XML documents of any size, the Mini-XML implementation also allows you to retain portions of the document in memory for later processing.
+The
+mxmlSAXLoadFd
,mxmlSAXLoadFile
, andmxmlSAXLoadString
functions provide the SAX loading APIs:-mxml_node_t * mxmlSAXLoadFd(mxml_node_t *top, int fd, mxml_type_t (*cb)(mxml_node_t *), mxml_sax_cb_t sax, void *sax_data); @@ -1095,31 +1115,31 @@ mxmlSAXLoadString(mxml_node_t *top, const char *s, mxml_type_t (*cb)(mxml_node_t *), mxml_sax_cb_t sax, void *sax_data);
Each function works like the corresponding
-mxmlLoad
function but uses a callback to process each node as it is read. The callback function receives the node, an event code, and a user data pointer you supply:void +
Each function works like the corresponding
+mxmlLoad
function but uses a callback to process each node as it is read. The callback function receives the node, an event code, and a user data pointer you supply:-void sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *data) { ... do something ... }
The event will be one of the following:
--
+
MXML_SAX_CDATA
: CDATA was just read.The event will be one of the following:
++
-- -
MXML_SAX_CDATA
: CDATA was just read.+
MXML_SAX_COMMENT
: A comment was just read.- -
MXML_SAX_COMMENT
: A comment was just read.+
MXML_SAX_DATA
: Data (custom, integer, opaque, real, or text) was just read.- -
MXML_SAX_DATA
: Data (custom, integer, opaque, real, or text) was just read.+
MXML_SAX_DIRECTIVE
: A processing directive/instruction was just read.- -
MXML_SAX_DIRECTIVE
: A processing directive/instruction was just read.+
MXML_SAX_ELEMENT_CLOSE
- A close element was just read (</element>
)- -
MXML_SAX_ELEMENT_CLOSE
- A close element was just read (</element>
)+
MXML_SAX_ELEMENT_OPEN
- An open element was just read (<element>
)
MXML_SAX_ELEMENT_OPEN
- An open element was just read (<element>
)Elements are released after the close element is processed. All other nodes are released after they are processed. The SAX callback can retain the node using the
-mxmlRetain
function. For example, the following SAX callback will retain all nodes, effectively simulating a normal in-memory load:void +
Elements are released after the close element is processed. All other nodes are released after they are processed. The SAX callback can retain the node using the
+mxmlRetain
function. For example, the following SAX callback will retain all nodes, effectively simulating a normal in-memory load:-void sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *data) { @@ -1127,8 +1147,8 @@ sax_cb(mxml_node_t *node, mxml_sax_event_t event, mxmlRetain(node); }
More typically the SAX callback will only retain a small portion of the document that is needed for post-processing. For example, the following SAX callback will retain the title and headings in an XHTML file. It also retains the (parent) elements like
-<html>
,<head>
, and<body>
, and processing directives like<?xml ... ?>
and<!DOCTYPE ... >
:void +
More typically the SAX callback will only retain a small portion of the document that is needed for post-processing. For example, the following SAX callback will retain the title and headings in an XHTML file. It also retains the (parent) elements like
+<html>
,<head>
, and<body>
, and processing directives like<?xml ... ?>
and<!DOCTYPE ... >
:-void sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *data) { @@ -1168,8 +1188,8 @@ sax_cb(mxml_node_t *node, mxml_sax_event_t event, } }
The resulting skeleton document tree can then be searched just like one loaded using the
-mxmlLoad
functions. For example, a filter that reads an XHTML document from stdin and then shows the title and headings in the document would look like:mxml_node_t *doc, *title, *body, *heading; +
The resulting skeleton document tree can then be searched just like one loaded using the
+mxmlLoad
functions. For example, a filter that reads an XHTML document from stdin and then shows the title and headings in the document would look like:-mxml_node_t *doc, *title, *body, *heading; doc = mxmlSAXLoadFd(NULL, 0, MXML_TEXT_CALLBACK, sax_cb, NULL); @@ -1191,8 +1211,8 @@ if (body) print_children(heading); }
The
-print_children
function is:void +
The
+print_children
function is:-void print_children(mxml_node_t *parent) { mxml_node_t *node; @@ -1214,209 +1234,209 @@ print_children(mxml_node_t *parent) putchar('\n'); }
Functions
+Functions
mxmlAdd
-Add a node to a tree.
+Add a node to a tree.
void mxmlAdd(mxml_node_t *parent, int where, mxml_node_t *child, mxml_node_t *node);
Parameters
+ parent -Parent node Parent node + where -Where to add, MXML_ADD_BEFORE
orMXML_ADD_AFTER
Where to add, MXML_ADD_BEFORE
orMXML_ADD_AFTER
+ child -Child node for where or MXML_ADD_TO_PARENT
Child node for where or MXML_ADD_TO_PARENT
+ node -Node to add Node to add Discussion
-Adds the specified node to the parent. If the child argument is not +
Adds the specified node to the parent. If the child argument is not
NULL
, puts the new node before or after the specified child depending on the value of the where argument. If the child argument isNULL
, 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 constantMXML_ADD_TO_PARENT
can be used to specify aNULL
child pointer.mxmlDelete
-Delete a node and all of its children.
+Delete a node and all of its children.
void mxmlDelete(mxml_node_t *node);
Parameters
+ node -Node to delete Node to delete Discussion
-If the specified node has a parent, this function first removes the +
If the specified node has a parent, this function first removes the node from its parent using the
mxmlRemove
function.Mini-XML 2.4 mxmlElementDeleteAttr
-Delete an attribute.
+Delete an attribute.
void mxmlElementDeleteAttr(mxml_node_t *node, const char *name);
Parameters
+ node -Element Element + name -Attribute name Attribute name mxmlElementGetAttr
-Get an attribute.
+Get an attribute.
const char *mxmlElementGetAttr(mxml_node_t *node, const char *name);
Parameters
+ node -Element node Element node + name -Name of attribute Name of attribute Return Value
-Attribute value or
+NULL
Attribute value or
NULL
Discussion
-This function returns
NULL
if the node is not an element or the +This function returns
NULL
if the node is not an element or the named attribute does not exist.Mini-XML 2.11 mxmlElementGetAttrByIndex
-Get an element attribute by index.
+Get an element attribute by index.
const char *mxmlElementGetAttrByIndex(mxml_node_t *node, int idx, const char **name);
Parameters
+ node -Node Node + idx -Attribute index, starting at 0 Attribute index, starting at 0 + name -Attribute name Attribute name Return Value
-Attribute value
+Attribute value
Discussion
-The index ("idx") is 0-based.
NULL
is returned if the specified index +The index ("idx") is 0-based.
NULL
is returned if the specified index is out of range.Mini-XML 2.11 mxmlElementGetAttrCount
-Get the number of element attributes.
+Get the number of element attributes.
int mxmlElementGetAttrCount(mxml_node_t *node);
Parameters
+ node -Node Node Return Value
-Number of attributes
+Number of attributes
mxmlElementSetAttr
-Set an attribute.
+Set an attribute.
void mxmlElementSetAttr(mxml_node_t *node, const char *name, const char *value);
Parameters
+ node -Element node Element node + name -Name of attribute Name of attribute + value -Attribute value Attribute value Discussion
-If the named attribute already exists, the value of the attribute +
If the named attribute already exists, the value of the attribute is replaced by the new string value. The string value is copied into the element node. This function does nothing if the node is not an element.
Mini-XML 2.3 mxmlElementSetAttrf
-Set an attribute with a formatted value.
+Set an attribute with a formatted value.
void mxmlElementSetAttrf(mxml_node_t *node, const char *name, const char *format, ...);
Parameters
+ node -Element node Element node + name -Name of attribute Name of attribute + format -Printf-style attribute value Printf-style attribute value + ... -Additional arguments as needed Additional arguments as needed Discussion
-If the named attribute already exists, the value of the attribute +
If the named attribute already exists, the value of the attribute is replaced by the new formatted string. The formatted string value is copied into the element node. This function does nothing if the node is not an element.
mxmlEntityAddCallback
-Add a callback to convert entities to Unicode.
+Add a callback to convert entities to Unicode.
int mxmlEntityAddCallback(mxml_entity_cb_t cb);
Parameters
+ cb -Callback function to add Callback function to add Return Value
-0 on success, -1 on failure
+0 on success, -1 on failure
mxmlEntityGetName
-Get the name that corresponds to the character value.
+Get the name that corresponds to the character value.
const char *mxmlEntityGetName(int val);
Parameters
+ val -Character value Character value Return Value
-Entity name or
+NULL
Entity name or
NULL
Discussion
-If val does not need to be represented by a named entity,
+NULL
is returned.If val does not need to be represented by a named entity,
NULL
is returned.mxmlEntityGetValue
-Get the character corresponding to a named entity.
+Get the character corresponding to a named entity.
int mxmlEntityGetValue(const char *name);
Parameters
+ name -Entity name Entity name Return Value
-Character value or -1 on error
+Character value or -1 on error
Discussion
-The entity name can also be a numeric constant. -1 is returned if the +
The entity name can also be a numeric constant. -1 is returned if the name is not known.
mxmlEntityRemoveCallback
-Remove a callback.
+Remove a callback.
void mxmlEntityRemoveCallback(mxml_entity_cb_t cb);
Parameters
+ cb -Callback function to remove Callback function to remove mxmlFindElement
-Find the named element.
+Find the named element.
mxml_node_t *mxmlFindElement(mxml_node_t *node, mxml_node_t *top, const char *element, const char *attr, const char *value, int descend);
Parameters
+ node -Current node Current node + top -Top node Top node + element -Element name or NULL
for anyElement name or NULL
for any+ attr -Attribute name, or NULL
for noneAttribute name, or NULL
for none+ value -Attribute value, or NULL
for anyAttribute value, or NULL
for any+ descend -Descend into tree - MXML_DESCEND
,MXML_NO_DESCEND
, orMXML_DESCEND_FIRST
Descend into tree - MXML_DESCEND
,MXML_NO_DESCEND
, orMXML_DESCEND_FIRST
Return Value
-Element node or
+NULL
Element node or
NULL
Discussion
-The search is constrained by the name, attribute name, and value; any +
The search is constrained by the name, attribute name, and value; any
NULL
names or values are treated as wildcards, so different kinds of searches can be implemented by looking for all elements of a given name or all elements with a specific attribute. The descend argument determines @@ -1425,20 +1445,20 @@ whether the search descends into child nodes; normally you will use to find additional direct descendents of the node. The top node argument constrains the search to a particular node's children.Mini-XML 2.7 mxmlFindPath
-Find a node with the given path.
+Find a node with the given path.
mxml_node_t *mxmlFindPath(mxml_node_t *top, const char *path);
Parameters
+ top -Top node Top node + path -Path to element Path to element Return Value
-Found node or
+NULL
Found node or
NULL
Discussion
-The "path" is a slash-separated list of element names. The name "" is +
The "path" is a slash-separated list of element names. The name "" is considered a wildcard for one or more levels of elements. For example, "foo/one/two", "bar/two/one", "/one", and so forth.
@@ -1447,206 +1467,206 @@ children and the first child is a value node.Mini-XML 2.7 mxmlGetCDATA
-Get the value for a CDATA node.
+Get the value for a CDATA node.
const char *mxmlGetCDATA(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-CDATA value or
+NULL
CDATA value or
NULL
Discussion
-
NULL
is returned if the node is not a CDATA element. +
NULL
is returned if the node is not a CDATA element.Mini-XML 2.7 mxmlGetCustom
-Get the value for a custom node.
+Get the value for a custom node.
const void *mxmlGetCustom(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-Custom value or
+NULL
Custom value or
NULL
Discussion
-
NULL
is returned if the node (or its first child) is not a custom +
NULL
is returned if the node (or its first child) is not a custom value node.Mini-XML 2.7 mxmlGetElement
-Get the name for an element node.
+Get the name for an element node.
const char *mxmlGetElement(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-Element name or
+NULL
Element name or
NULL
Discussion
-
NULL
is returned if the node is not an element node. +
NULL
is returned if the node is not an element node.Mini-XML 2.7 mxmlGetFirstChild
-Get the first child of an element node.
+Get the first child of an element node.
mxml_node_t *mxmlGetFirstChild(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-First child or
+NULL
First child or
NULL
Discussion
-
NULL
is returned if the node is not an element node or if the node +
NULL
is returned if the node is not an element node or if the node has no children.Mini-XML 2.7 mxmlGetInteger
-Get the integer value from the specified node or its +
Get the integer value from the specified node or its first child.
int mxmlGetInteger(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-Integer value or 0
+Integer value or 0
Discussion
-0 is returned if the node (or its first child) is not an integer value node. +
0 is returned if the node (or its first child) is not an integer value node.
Mini-XML 2.7 mxmlGetLastChild
-Get the last child of an element node.
+Get the last child of an element node.
mxml_node_t *mxmlGetLastChild(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-Last child or
+NULL
Last child or
NULL
Discussion
-
NULL
is returned if the node is not an element node or if the node +
NULL
is returned if the node is not an element node or if the node has no children.mxmlGetNextSibling
- +mxml_node_t *mxmlGetNextSibling(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-Get the next node for the current parent.
-
NULL
is returned if this is the last child for the current parent. +Get the next node for the current parent.
+
NULL
is returned if this is the last child for the current parent.Mini-XML 2.7 mxmlGetOpaque
-Get an opaque string value for a node or its first child.
+Get an opaque string value for a node or its first child.
const char *mxmlGetOpaque(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-Opaque string or
+NULL
Opaque string or
NULL
Discussion
-
NULL
is returned if the node (or its first child) is not an opaque +
NULL
is returned if the node (or its first child) is not an opaque value node.Mini-XML 2.7 mxmlGetParent
-Get the parent node.
+Get the parent node.
mxml_node_t *mxmlGetParent(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-Parent node or
+NULL
Parent node or
NULL
Discussion
-
NULL
is returned for a root node. +
NULL
is returned for a root node.Mini-XML 2.7 mxmlGetPrevSibling
-Get the previous node for the current parent.
+Get the previous node for the current parent.
mxml_node_t *mxmlGetPrevSibling(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-Previous node or
+NULL
Previous node or
NULL
Discussion
-
NULL
is returned if this is the first child for the current parent. +
NULL
is returned if this is the first child for the current parent.Mini-XML 2.7 mxmlGetReal
-Get the real value for a node or its first child.
+Get the real value for a node or its first child.
double mxmlGetReal(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-Real value or 0.0
+Real value or 0.0
Discussion
-0.0 is returned if the node (or its first child) is not a real value node. +
0.0 is returned if the node (or its first child) is not a real value node.
Mini-XML 2.7 mxmlGetRefCount
-Get the current reference (use) count for a node.
+Get the current reference (use) count for a node.
int mxmlGetRefCount(mxml_node_t *node);
Parameters
+ node -Node Node Return Value
-Reference count
+Reference count
Discussion
-The initial reference count of new nodes is 1. Use the
mxmlRetain
+The initial reference count of new nodes is 1. Use the
mxmlRetain
andmxmlRelease
functions to increment and decrement a node's reference count. .Mini-XML 2.7 mxmlGetText
-Get the text value for a node or its first child.
+Get the text value for a node or its first child.
const char *mxmlGetText(mxml_node_t *node, int *whitespace);
Parameters
+ node -Node to get Node to get + whitespace -1 if string is preceded by whitespace, 0 otherwise 1 if string is preceded by whitespace, 0 otherwise Return Value
-Text string or
+NULL
Text string or
NULL
Discussion
-
NULL
is returned if the node (or its first child) is not a text node. +
NULL
is returned if the node (or its first child) is not a text node. The "whitespace" argument can beNULL
.
Note: Text nodes consist of whitespace-delimited words. You will only get @@ -1657,139 +1677,139 @@ using themxmlGetOpaque
function insteMini-XML 2.7 mxmlGetType
-Get the node type.
+Get the node type.
mxml_type_t mxmlGetType(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-Type of node
+Type of node
Discussion
-
MXML_IGNORE
is returned if "node" isNULL
. +
MXML_IGNORE
is returned if "node" isNULL
.Mini-XML 2.7 mxmlGetUserData
-Get the user data pointer for a node.
+Get the user data pointer for a node.
void *mxmlGetUserData(mxml_node_t *node);
Parameters
+ node -Node to get Node to get Return Value
-User data pointer
+User data pointer
mxmlIndexDelete
-Delete an index.
+Delete an index.
void mxmlIndexDelete(mxml_index_t *ind);
Parameters
+ ind -Index to delete Index to delete mxmlIndexEnum
-Return the next node in the index.
+Return the next node in the index.
mxml_node_t *mxmlIndexEnum(mxml_index_t *ind);
Parameters
+ ind -Index to enumerate Index to enumerate Return Value
-Next node or
+NULL
if there is noneNext node or
NULL
if there is noneDiscussion
-You should call
mxmlIndexReset
prior to using this function to get +You should call
mxmlIndexReset
prior to using this function to get the first node in the index. Nodes are returned in the sorted order of the index.mxmlIndexFind
-Find the next matching node.
+Find the next matching node.
mxml_node_t *mxmlIndexFind(mxml_index_t *ind, const char *element, const char *value);
Parameters
+ ind -Index to search Index to search + element -Element name to find, if any Element name to find, if any + value -Attribute value, if any Attribute value, if any Return Value
-Node or
+NULL
if none foundNode or
NULL
if none foundDiscussion
-You should call
mxmlIndexReset
prior to using this function for +You should call
mxmlIndexReset
prior to using this function for the first time with a particular set of "element" and "value" strings. PassingNULL
for both "element" and "value" is equivalent to callingmxmlIndexEnum
.Mini-XML 2.7 mxmlIndexGetCount
-Get the number of nodes in an index.
+Get the number of nodes in an index.
int mxmlIndexGetCount(mxml_index_t *ind);
Parameters
+ ind -Index of nodes Index of nodes Return Value
-Number of nodes in index
+Number of nodes in index
mxmlIndexNew
-Create a new index.
+Create a new index.
mxml_index_t *mxmlIndexNew(mxml_node_t *node, const char *element, const char *attr);
Parameters
+ node -XML node tree XML node tree + element -Element to index or NULL
for allElement to index or NULL
for all+ attr -Attribute to index or NULL
for noneAttribute to index or NULL
for noneReturn Value
-New index
+New index
Discussion
-The index will contain all nodes that contain the named element and/or +
The index will contain all nodes that contain the named element and/or attribute. If both "element" and "attr" are
NULL
, then the index will contain a sorted list of the elements in the node tree. Nodes are sorted by element name and optionally by attribute value if the "attr" argument is not NULL.mxmlIndexReset
-Reset the enumeration/find pointer in the index and +
Reset the enumeration/find pointer in the index and return the first node in the index.
mxml_node_t *mxmlIndexReset(mxml_index_t *ind);
Parameters
+ ind -Index to reset Index to reset Return Value
-First node or
+NULL
if there is noneFirst node or
NULL
if there is noneDiscussion
-This function should be called prior to using
mxmlIndexEnum
or +This function should be called prior to using
mxmlIndexEnum
ormxmlIndexFind
for the first time.mxmlLoadFd
-Load a file descriptor into an XML node tree.
+Load a file descriptor into an XML node tree.
mxml_node_t *mxmlLoadFd(mxml_node_t *top, int fd, mxml_load_cb_t cb);
Parameters
+ top -Top node Top node + fd -File descriptor to read from File descriptor to read from + cb -Callback function or constant Callback function or constant Return Value
-First node or
+NULL
if the file could not be read.First node or
NULL
if the file could not be read.Discussion
-The nodes in the specified file are added to the specified top node. +
The nodes in the specified file are added to the specified top node. If no top node is provided, the XML file MUST be well-formed with a single parent node like ?xml for the entire file. The callback function returns the value type that should be used for child nodes. @@ -1803,22 +1823,22 @@ text as a series of whitespace-delimited words, instead of using the
MXML_OPAQUE_CALLBACK
which returns the inline text as a single string (including whitespace).mxmlLoadFile
-Load a file into an XML node tree.
+Load a file into an XML node tree.
mxml_node_t *mxmlLoadFile(mxml_node_t *top, FILE *fp, mxml_load_cb_t cb);
Parameters
+ top -Top node Top node + fp -File to read from File to read from + cb -Callback function or constant Callback function or constant Return Value
-First node or
+NULL
if the file could not be read.First node or
NULL
if the file could not be read.Discussion
-The nodes in the specified file are added to the specified top node. +
The nodes in the specified file are added to the specified top node. If no top node is provided, the XML file MUST be well-formed with a single parent node like ?xml for the entire file. The callback function returns the value type that should be used for child nodes. @@ -1832,22 +1852,22 @@ text as a series of whitespace-delimited words, instead of using the
MXML_OPAQUE_CALLBACK
which returns the inline text as a single string (including whitespace).mxmlLoadString
-Load a string into an XML node tree.
+Load a string into an XML node tree.
mxml_node_t *mxmlLoadString(mxml_node_t *top, const char *s, mxml_load_cb_t cb);
Parameters
+ top -Top node Top node + s -String to load String to load + cb -Callback function or constant Callback function or constant Return Value
-First node or
+NULL
if the string has errors.First node or
NULL
if the string has errors.Discussion
-The nodes in the specified string are added to the specified top node. +
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 ?xml for the entire string. The callback function returns the value type that should be used for child nodes. @@ -1861,20 +1881,20 @@ text as a series of whitespace-delimited words, instead of using the
MXML_OPAQUE_CALLBACK
which returns the inline text as a single string (including whitespace).Mini-XML 2.3 mxmlNewCDATA
-Create a new CDATA node.
+Create a new CDATA node.
mxml_node_t *mxmlNewCDATA(mxml_node_t *parent, const char *data);
Parameters
+ parent -Parent node or MXML_NO_PARENT
Parent node or MXML_NO_PARENT
+ data -Data string Data string Return Value
-New node
+New node
Discussion
-The new CDATA node is added to the end of the specified parent's child +
The new CDATA node is added to the end of the specified parent's child list. The constant
MXML_NO_PARENT
can be used to specify that the new CDATA node has no parent. The data string must be nul-terminated and is copied into the new node. CDATA nodes currently use the @@ -1882,237 +1902,237 @@ is copied into the new node. CDATA nodes currently use theMini-XML 2.1 mxmlNewCustom
-Create a new custom data node.
+Create a new custom data node.
mxml_node_t *mxmlNewCustom(mxml_node_t *parent, void *data, mxml_custom_destroy_cb_t destroy);
Parameters
+ parent -Parent node or MXML_NO_PARENT
Parent node or MXML_NO_PARENT
+ data -Pointer to data Pointer to data + destroy -Function to destroy data Function to destroy data Return Value
-New node
+New node
Discussion
-The new custom node is added to the end of the specified parent's child +
The new custom node is added to the end of the specified parent's child list. The constant
MXML_NO_PARENT
can be used to specify that the new element node has no parent.NULL
can be passed when the data in the node is not dynamically allocated or is separately managed.mxmlNewElement
-Create a new element node.
+Create a new element node.
mxml_node_t *mxmlNewElement(mxml_node_t *parent, const char *name);
Parameters
+ parent -Parent node or MXML_NO_PARENT
Parent node or MXML_NO_PARENT
+ name -Name of element Name of element Return Value
-New node
+New node
Discussion
-The new element node is added to the end of the specified parent's child +
The new element node is added to the end of the specified parent's child list. The constant
MXML_NO_PARENT
can be used to specify that the new element node has no parent.mxmlNewInteger
-Create a new integer node.
+Create a new integer node.
mxml_node_t *mxmlNewInteger(mxml_node_t *parent, int integer);
Parameters
+ parent -Parent node or MXML_NO_PARENT
Parent node or MXML_NO_PARENT
+ integer -Integer value Integer value Return Value
-New node
+New node
Discussion
-The new integer node is added to the end of the specified parent's child +
The new integer node is added to the end of the specified parent's child list. The constant
MXML_NO_PARENT
can be used to specify that the new integer node has no parent.mxmlNewOpaque
-Create a new opaque string.
+Create a new opaque string.
mxml_node_t *mxmlNewOpaque(mxml_node_t *parent, const char *opaque);
Parameters
+ parent -Parent node or MXML_NO_PARENT
Parent node or MXML_NO_PARENT
+ opaque -Opaque string Opaque string Return Value
-New node
+New node
Discussion
-The new opaque string node is added to the end of the specified parent's +
The new opaque string node is added to the end of the specified parent's child list. The constant
MXML_NO_PARENT
can be used to specify that the new opaque string node has no parent. The opaque string must be nul- terminated and is copied into the new node.mxmlNewOpaquef
-Create a new formatted opaque string node.
+Create a new formatted opaque string node.
mxml_node_t *mxmlNewOpaquef(mxml_node_t *parent, const char *format, ...);
Parameters
+ parent -Parent node or MXML_NO_PARENT
Parent node or MXML_NO_PARENT
+ format -Printf-style format string Printf-style format string + ... -Additional args as needed Additional args as needed Return Value
-New node
+New node
Discussion
-The new opaque string node is added to the end of the specified parent's +
The new opaque string node is added to the end of the specified parent's child list. The constant
MXML_NO_PARENT
can be used to specify that the new opaque string node has no parent. The format string must be nul-terminated and is formatted into the new node.mxmlNewReal
-Create a new real number node.
+Create a new real number node.
mxml_node_t *mxmlNewReal(mxml_node_t *parent, double real);
Parameters
+ parent -Parent node or MXML_NO_PARENT
Parent node or MXML_NO_PARENT
+ real -Real number value Real number value Return Value
-New node
+New node
Discussion
-The new real number node is added to the end of the specified parent's +
The new real number node is added to the end of the specified parent's child list. The constant
MXML_NO_PARENT
can be used to specify that the new real number node has no parent.mxmlNewText
-Create a new text fragment node.
+Create a new text fragment node.
mxml_node_t *mxmlNewText(mxml_node_t *parent, int whitespace, const char *string);
Parameters
+ parent -Parent node or MXML_NO_PARENT
Parent node or MXML_NO_PARENT
+ whitespace -1 = leading whitespace, 0 = no whitespace 1 = leading whitespace, 0 = no whitespace + string -String String Return Value
-New node
+New node
Discussion
-The new text node is added to the end of the specified parent's child +
The new text node is added to the end of the specified parent's child list. The constant
MXML_NO_PARENT
can be used to specify that the new text node has no parent. The whitespace parameter is used to specify whether leading whitespace is present before the node. The text string must be nul-terminated and is copied into the new node.mxmlNewTextf
-Create a new formatted text fragment node.
+Create a new formatted text fragment node.
mxml_node_t *mxmlNewTextf(mxml_node_t *parent, int whitespace, const char *format, ...);
Parameters
+ parent -Parent node or MXML_NO_PARENT
Parent node or MXML_NO_PARENT
+ whitespace -1 = leading whitespace, 0 = no whitespace 1 = leading whitespace, 0 = no whitespace + format -Printf-style format string Printf-style format string + ... -Additional args as needed Additional args as needed Return Value
-New node
+New node
Discussion
-The new text node is added to the end of the specified parent's child +
The new text node is added to the end of the specified parent's child list. The constant
MXML_NO_PARENT
can be used to specify that the new text node has no parent. The whitespace parameter is used to specify whether leading whitespace is present before the node. The format string must be nul-terminated and is formatted into the new node.Mini-XML 2.3 mxmlNewXML
-Create a new XML document tree.
+Create a new XML document tree.
mxml_node_t *mxmlNewXML(const char *version);
Parameters
+ version -Version number to use Version number to use Return Value
-New ?xml node
+New ?xml node
Discussion
-The "version" argument specifies the version number to put in the +
The "version" argument specifies the version number to put in the ?xml element node. If
NULL
, version "1.0" is assumed.Mini-XML 2.3 mxmlRelease
-Release a node.
+Release a node.
int mxmlRelease(mxml_node_t *node);
Parameters
+ node -Node Node Return Value
-New reference count
+New reference count
Discussion
-When the reference count reaches zero, the node (and any children) +
When the reference count reaches zero, the node (and any children) is deleted via
mxmlDelete
.mxmlRemove
-Remove a node from its parent.
+Remove a node from its parent.
void mxmlRemove(mxml_node_t *node);
Parameters
+ node -Node to remove Node to remove Discussion
-This function does not free memory used by the node - use
mxmlDelete
+This function does not free memory used by the node - use
mxmlDelete
for that. This function does nothing if the node has no parent.Mini-XML 2.3 mxmlRetain
-Retain a node.
+Retain a node.
int mxmlRetain(mxml_node_t *node);
Parameters
+ node -Node Node Return Value
-New reference count
+New reference count
Mini-XML 2.3 mxmlSAXLoadFd
-Load a file descriptor into an XML node tree +
Load a file descriptor into an XML node tree using a SAX callback.
mxml_node_t *mxmlSAXLoadFd(mxml_node_t *top, int fd, mxml_load_cb_t cb, mxml_sax_cb_t sax_cb, void *sax_data);
Parameters
+ top -Top node Top node + fd -File descriptor to read from File descriptor to read from + cb -Callback function or constant Callback function or constant + sax_cb -SAX callback or MXML_NO_CALLBACK
SAX callback or MXML_NO_CALLBACK
+ sax_data -SAX user data SAX user data Return Value
-First node or
+NULL
if the file could not be read.First node or
NULL
if the file could not be read.Discussion
-The nodes in the specified file are added to the specified top node. +
The nodes in the specified file are added to the specified top node. If no top node is provided, the XML file MUST be well-formed with a single parent node like ?xml for the entire file. The callback function returns the value type that should be used for child nodes. @@ -2126,27 +2146,27 @@ node is closed or after each data, comment, CDATA, or directive node.
Mini-XML 2.3 mxmlSAXLoadFile
-Load a file into an XML node tree +
Load a file into an XML node tree using a SAX callback.
mxml_node_t *mxmlSAXLoadFile(mxml_node_t *top, FILE *fp, mxml_load_cb_t cb, mxml_sax_cb_t sax_cb, void *sax_data);
Parameters
+ top -Top node Top node + fp -File to read from File to read from + cb -Callback function or constant Callback function or constant + sax_cb -SAX callback or MXML_NO_CALLBACK
SAX callback or MXML_NO_CALLBACK
+ sax_data -SAX user data SAX user data Return Value
-First node or
+NULL
if the file could not be read.First node or
NULL
if the file could not be read.Discussion
-The nodes in the specified file are added to the specified top node. +
The nodes in the specified file are added to the specified top node. If no top node is provided, the XML file MUST be well-formed with a single parent node like ?xml for the entire file. The callback function returns the value type that should be used for child nodes. @@ -2160,27 +2180,27 @@ node is closed or after each data, comment, CDATA, or directive node.
Mini-XML 2.3 mxmlSAXLoadString
-Load a string into an XML node tree +
Load a string into an XML node tree using a SAX callback.
mxml_node_t *mxmlSAXLoadString(mxml_node_t *top, const char *s, mxml_load_cb_t cb, mxml_sax_cb_t sax_cb, void *sax_data);
Parameters
+ top -Top node Top node + s -String to load String to load + cb -Callback function or constant Callback function or constant + sax_cb -SAX callback or MXML_NO_CALLBACK
SAX callback or MXML_NO_CALLBACK
+ sax_data -SAX user data SAX user data Return Value
-First node or
+NULL
if the string has errors.First node or
NULL
if the string has errors.Discussion
-The nodes in the specified string are added to the specified top node. +
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 ?xml for the entire string. The callback function returns the value type that should be used for child nodes. @@ -2194,20 +2214,20 @@ node is closed or after each data, comment, CDATA, or directive node.
mxmlSaveAllocString
-Save an XML tree to an allocated string.
+Save an XML tree to an allocated string.
char *mxmlSaveAllocString(mxml_node_t *node, mxml_save_cb_t cb);
Parameters
+ node -Node to write Node to write + cb -Whitespace callback or MXML_NO_CALLBACK
Whitespace callback or MXML_NO_CALLBACK
Return Value
-Allocated string or
+NULL
Allocated string or
NULL
Discussion
-This function returns a pointer to a string containing the textual +
This function returns a pointer to a string containing the textual representation of the XML node tree. The string should be freed using the free() function when you are done with it.
NULL
is returned if the node would produce an empty string or if the string cannot be @@ -2219,66 +2239,66 @@ is specified, whitespace will only be added beforeMXML_TEXT
nodes with leading whitespace and before attribute names inside opening element tags.mxmlSaveFd
-Save an XML tree to a file descriptor.
+Save an XML tree to a file descriptor.
int mxmlSaveFd(mxml_node_t *node, int fd, mxml_save_cb_t cb);
Parameters
+ node -Node to write Node to write + fd -File descriptor to write to File descriptor to write to + cb -Whitespace callback or MXML_NO_CALLBACK
Whitespace callback or MXML_NO_CALLBACK
Return Value
-0 on success, -1 on error.
+0 on success, -1 on error.
Discussion
-The callback argument specifies a function that returns a whitespace +
The callback argument specifies a function that returns a whitespace string or NULL before and after each element. If
MXML_NO_CALLBACK
is specified, whitespace will only be added beforeMXML_TEXT
nodes with leading whitespace and before attribute names inside opening element tags.mxmlSaveFile
-Save an XML tree to a file.
+Save an XML tree to a file.
int mxmlSaveFile(mxml_node_t *node, FILE *fp, mxml_save_cb_t cb);
Parameters
+ node -Node to write Node to write + fp -File to write to File to write to + cb -Whitespace callback or MXML_NO_CALLBACK
Whitespace callback or MXML_NO_CALLBACK
Return Value
-0 on success, -1 on error.
+0 on success, -1 on error.
Discussion
-The callback argument specifies a function that returns a whitespace +
The callback argument specifies a function that returns a whitespace string or NULL before and after each element. If
MXML_NO_CALLBACK
is specified, whitespace will only be added beforeMXML_TEXT
nodes with leading whitespace and before attribute names inside opening element tags.mxmlSaveString
-Save an XML node tree to a string.
+Save an XML node tree to a string.
int mxmlSaveString(mxml_node_t *node, char *buffer, int bufsize, mxml_save_cb_t cb);
Parameters
+ node -Node to write Node to write + buffer -String buffer String buffer + bufsize -Size of string buffer Size of string buffer + cb -Whitespace callback or MXML_NO_CALLBACK
Whitespace callback or MXML_NO_CALLBACK
Return Value
-Size of string
+Size of string
Discussion
-This function returns the total number of bytes that would be +
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.
@@ -2288,331 +2308,331 @@ is specified, whitespace will only be added beforeMXML_TEXT
nodes with leading whitespace and before attribute names inside opening element tags.Mini-XML 2.3 mxmlSetCDATA
-Set the element name of a CDATA node.
+Set the element name of a CDATA node.
int mxmlSetCDATA(mxml_node_t *node, const char *data);
Parameters
+ node -Node to set Node to set + data -New data string New data string Return Value
-0 on success, -1 on failure
+0 on success, -1 on failure
Discussion
-The node is not changed if it (or its first child) is not a CDATA element node. +
The node is not changed if it (or its first child) is not a CDATA element node.
Mini-XML 2.1 mxmlSetCustom
-Set the data and destructor of a custom data node.
+Set the data and destructor of a custom data node.
int mxmlSetCustom(mxml_node_t *node, void *data, mxml_custom_destroy_cb_t destroy);
Parameters
+ node -Node to set Node to set + data -New data pointer New data pointer + destroy -New destructor function New destructor function Return Value
-0 on success, -1 on failure
+0 on success, -1 on failure
Discussion
-The node is not changed if it (or its first child) is not a custom node. +
The node is not changed if it (or its first child) is not a custom node.
mxmlSetCustomHandlers
-Set the handling functions for custom data.
+Set the handling functions for custom data.
void mxmlSetCustomHandlers(mxml_custom_load_cb_t load, mxml_custom_save_cb_t save);
Parameters
+ load -Load function Load function + save -Save function Save function Discussion
-The load function accepts a node pointer and a data string and must +
The load function accepts a node pointer and a data string and must return 0 on success and non-zero on error.
The save function accepts a node pointer and must return a malloc'd string on success andNULL
on error.mxmlSetElement
-Set the name of an element node.
+Set the name of an element node.
int mxmlSetElement(mxml_node_t *node, const char *name);
Parameters
+ node -Node to set Node to set + name -New name string New name string Return Value
-0 on success, -1 on failure
+0 on success, -1 on failure
Discussion
-The node is not changed if it is not an element node.
+The node is not changed if it is not an element node.
mxmlSetErrorCallback
-Set the error message callback.
+Set the error message callback.
void mxmlSetErrorCallback(mxml_error_cb_t cb);
Parameters
+ cb -Error callback function Error callback function mxmlSetInteger
-Set the value of an integer node.
+Set the value of an integer node.
int mxmlSetInteger(mxml_node_t *node, int integer);
Parameters
+ node -Node to set Node to set + integer -Integer value Integer value Return Value
-0 on success, -1 on failure
+0 on success, -1 on failure
Discussion
-The node is not changed if it (or its first child) is not an integer node.
+The node is not changed if it (or its first child) is not an integer node.
mxmlSetOpaque
-Set the value of an opaque node.
+Set the value of an opaque node.
int mxmlSetOpaque(mxml_node_t *node, const char *opaque);
Parameters
+ node -Node to set Node to set + opaque -Opaque string Opaque string Return Value
-0 on success, -1 on failure
+0 on success, -1 on failure
Discussion
-The node is not changed if it (or its first child) is not an opaque node.
+The node is not changed if it (or its first child) is not an opaque node.
Mini-XML 2.11 mxmlSetOpaquef
-Set the value of an opaque string node to a formatted string.
+Set the value of an opaque string node to a formatted string.
int mxmlSetOpaquef(mxml_node_t *node, const char *format, ...);
Parameters
+ node -Node to set Node to set + format -Printf-style format string Printf-style format string + ... -Additional arguments as needed Additional arguments as needed Return Value
-0 on success, -1 on failure
+0 on success, -1 on failure
Discussion
-The node is not changed if it (or its first child) is not an opaque node. +
The node is not changed if it (or its first child) is not an opaque node.
mxmlSetReal
-Set the value of a real number node.
+Set the value of a real number node.
int mxmlSetReal(mxml_node_t *node, double real);
Parameters
+ node -Node to set Node to set + real -Real number value Real number value Return Value
-0 on success, -1 on failure
+0 on success, -1 on failure
Discussion
-The node is not changed if it (or its first child) is not a real number node.
+The node is not changed if it (or its first child) is not a real number node.
mxmlSetText
-Set the value of a text node.
+Set the value of a text node.
int mxmlSetText(mxml_node_t *node, int whitespace, const char *string);
Parameters
+ node -Node to set Node to set + whitespace -1 = leading whitespace, 0 = no whitespace 1 = leading whitespace, 0 = no whitespace + string -String String Return Value
-0 on success, -1 on failure
+0 on success, -1 on failure
Discussion
-The node is not changed if it (or its first child) is not a text node.
+The node is not changed if it (or its first child) is not a text node.
mxmlSetTextf
-Set the value of a text node to a formatted string.
+Set the value of a text node to a formatted string.
int mxmlSetTextf(mxml_node_t *node, int whitespace, const char *format, ...);
Parameters
+ node -Node to set Node to set + whitespace -1 = leading whitespace, 0 = no whitespace 1 = leading whitespace, 0 = no whitespace + format -Printf-style format string Printf-style format string + ... -Additional arguments as needed Additional arguments as needed Return Value
-0 on success, -1 on failure
+0 on success, -1 on failure
Discussion
-The node is not changed if it (or its first child) is not a text node.
+The node is not changed if it (or its first child) is not a text node.
Mini-XML 2.7 mxmlSetUserData
-Set the user data pointer for a node.
+Set the user data pointer for a node.
int mxmlSetUserData(mxml_node_t *node, void *data);
Parameters
+ node -Node to set Node to set + data -User data pointer User data pointer Return Value
-0 on success, -1 on failure
+0 on success, -1 on failure
Mini-XML 2.3 mxmlSetWrapMargin
-Set the wrap margin when saving XML data.
+Set the wrap margin when saving XML data.
void mxmlSetWrapMargin(int column);
Parameters
+ column -Column for wrapping, 0 to disable wrapping Column for wrapping, 0 to disable wrapping Discussion
-Wrapping is disabled when "column" is 0. +
Wrapping is disabled when "column" is 0.
mxmlWalkNext
-Walk to the next logical node in the tree.
+Walk to the next logical node in the tree.
mxml_node_t *mxmlWalkNext(mxml_node_t *node, mxml_node_t *top, int descend);
Parameters
+ node -Current node Current node + top -Top node Top node + descend -Descend into tree - MXML_DESCEND
,MXML_NO_DESCEND
, orMXML_DESCEND_FIRST
Descend into tree - MXML_DESCEND
,MXML_NO_DESCEND
, orMXML_DESCEND_FIRST
Return Value
-Next node or
+NULL
Next node or
NULL
Discussion
-The descend argument controls whether the first child is considered +
The descend argument controls whether the first child is considered to be the next node. The top node argument constrains the walk to the node's children.
mxmlWalkPrev
-Walk to the previous logical node in the tree.
+Walk to the previous logical node in the tree.
mxml_node_t *mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top, int descend);
Parameters
+ node -Current node Current node + top -Top node Top node + descend -Descend into tree - MXML_DESCEND
,MXML_NO_DESCEND
, orMXML_DESCEND_FIRST
Descend into tree - MXML_DESCEND
,MXML_NO_DESCEND
, orMXML_DESCEND_FIRST
Return Value
-Previous node or
+NULL
Previous node or
NULL
Discussion
-The descend argument controls whether the previous node's last child +
The descend argument controls whether the previous node's last child is considered to be the previous node. The top node argument constrains the walk to the node's children.
-Data Types
-mxml_custom_destroy_cb_t
-Custom data destructor
-+
Data Types
+mxml_custom_destroy_cb_t
+Custom data destructor
+typedef void (*mxml_custom_destroy_cb_t)(void *);
-mxml_custom_load_cb_t
-Custom data load callback function
-+
mxml_custom_load_cb_t
+Custom data load callback function
+typedef int (*mxml_custom_load_cb_t)(mxml_node_t *, const char *);
-mxml_custom_save_cb_t
-Custom data save callback function
-+
mxml_custom_save_cb_t
+Custom data save callback function
+typedef char *(*mxml_custom_save_cb_t)(mxml_node_t *);
-mxml_entity_cb_t
-Entity callback function
-+
mxml_entity_cb_t
+Entity callback function
+typedef int (*mxml_entity_cb_t)(const char *);
-mxml_error_cb_t
-Error callback function
-+
mxml_error_cb_t
+Error callback function
+typedef void (*mxml_error_cb_t)(const char *);
-mxml_index_t
-An XML node index.
-+
mxml_index_t
+An XML node index.
+typedef struct _mxml_index_s mxml_index_t;
-mxml_load_cb_t
-Load callback function
-+
mxml_load_cb_t
+Load callback function
+typedef mxml_type_t (*mxml_load_cb_t)(mxml_node_t *);
-mxml_node_t
-An XML node.
-+
mxml_node_t
+An XML node.
+typedef struct _mxml_node_s mxml_node_t;
-mxml_save_cb_t
-Save callback function
-+
mxml_save_cb_t
+Save callback function
+typedef const char *(*mxml_save_cb_t)(mxml_node_t *, int);
-mxml_sax_cb_t
-SAX callback function
-+
mxml_sax_cb_t
+SAX callback function
+typedef void (*mxml_sax_cb_t)(mxml_node_t *, mxml_sax_event_t, void *);
-mxml_sax_event_t
-SAX event type.
-+
mxml_sax_event_t
+SAX event type.
+typedef enum mxml_sax_event_e mxml_sax_event_t;
-mxml_type_t
-The XML node type.
-+
mxml_type_t
+The XML node type.
+typedef enum mxml_type_e mxml_type_t;
-Constants
-mxml_sax_event_e
-SAX event type.
-Constants
--
-- MXML_SAX_CDATA CDATA node - MXML_SAX_COMMENT Comment node - MXML_SAX_DATA Data node - MXML_SAX_DIRECTIVE Processing directive node - MXML_SAX_ELEMENT_CLOSE Element closed - MXML_SAX_ELEMENT_OPEN Element opened mxml_type_e
-The XML node type.
-Constants
--
-- MXML_CUSTOM Mini-XML 2.1 Custom data - MXML_ELEMENT XML element with attributes - MXML_IGNORE Mini-XML 2.3 Ignore/throw away node - MXML_INTEGER Integer value - MXML_OPAQUE Opaque string - MXML_REAL Real value - MXML_TEXT Text fragment
SAX event type.
+MXML_SAX_CDATA | CDATA node |
---|---|
MXML_SAX_COMMENT | Comment node |
MXML_SAX_DATA | Data node |
MXML_SAX_DIRECTIVE | Processing directive node |
MXML_SAX_ELEMENT_CLOSE | Element closed |
MXML_SAX_ELEMENT_OPEN | Element opened |
The XML node type.
+MXML_CUSTOM Mini-XML 2.1 | Custom data |
---|---|
MXML_ELEMENT | XML element with attributes |
MXML_IGNORE Mini-XML 2.3 | Ignore/throw away node |
MXML_INTEGER | Integer value |
MXML_OPAQUE | Opaque string |
MXML_REAL | Real value |
MXML_TEXT | Text fragment |