From 66a4800d57fe95a345ff8547033c2f2007f802ad Mon Sep 17 00:00:00 2001
From: Michael R Sweet This chapter shows additional ways to use the Mini-XML library in
your programs. Chapter 2 introduced the
-mxmlLoadFile() and
+ Chapter 2 introduced the
+mxmlLoadFile() and
mxmlLoadString() functions. The last argument to these
functions is a callback function which is used to determine the value
type of each data node in an XML document. Chapter 2 also introduced the
-mxmlSaveFile(),
-mxmlSaveString(), and
+ Chapter 2 also introduced the
+mxmlSaveFile(),
+mxmlSaveString(), and
mxmlSaveAllocString() functions. The last argument to these
functions is a callback function which is used to automatically insert
whitespace in an XML document. You register the callback functions using the
+ You register the callback functions using the
mxmlSetCustomHandlers() function: Existing nodes can be changed using the
-mxmlSetElement(),
-mxmlSetInteger(),
-mxmlSetOpaque(),
-mxmlSetReal(),
-mxmlSetText(), and
+ Existing nodes can be changed using the
+mxmlSetElement(),
+mxmlSetInteger(),
+mxmlSetOpaque(),
+mxmlSetReal(),
+mxmlSetText(), and
mxmlSetTextf() functions. For example, use the following
function call to change a text node to contain the text "new" with
leading whitespace: The mxmlNewTextf()
- and mxmlSetTextf()
+ The mxmlNewTextf()
+ and mxmlSetTextf()
functions create and change text nodes, respectively, using printf
-style format strings and arguments. For example, use the following
function call to create a new text node containing a constructed
@@ -369,7 +369,7 @@ mxmlSetTextf() Mini-XML provides functions for managing indices of nodes. The
- current implementation provides the same functionality as
+ current implementation provides the same functionality as
mxmlFindElement(). The advantage of using an index is that
searching and enumeration of elements is significantly faster. The only
disadvantage is that each index is a static snapshot of the XML
@@ -377,8 +377,8 @@ mxmlSetTextf() Indices are stored in
-mxml_index_t structures. The
+ Indices are stored in
+mxml_index_t structures. The
mxmlIndexNew() function creates a new index: The third argument contains the attribute to index; passing NULL
causes only the element name to be indexed. Once the index is created, the
-mxmlIndexEnum(),
-mxmlIndexFind(), and
+ Once the index is created, the
+mxmlIndexEnum(),
+mxmlIndexFind(), and
mxmlIndexReset() functions are used to access the nodes in the
- index. The mxmlIndexReset()
+ index. The mxmlIndexReset()
function resets the "current" node pointer in the index, allowing
you to do new searches and enumerations on the same index. Typically
- you will call this function prior to your calls to
-mxmlIndexEnum() and
+ you will call this function prior to your calls to
+mxmlIndexEnum() and
mxmlIndexFind(). The mxmlIndexEnum()
+ The mxmlIndexEnum()
function enumerates each of the nodes in the index and can be used in a
loop as follows: The mxmlIndexFind()
+ The mxmlIndexFind()
function locates the next occurrence of the named element and attribute
value in the index. It can be used to find all matching elements in an
index, as follows:Load Callbacks
-Save Callbacks
-
mxmlSetCustomHandlers(load_custom,
@@ -340,12 +340,12 @@ MXML_WS_BEFORE_CLOSE, or MXML_WS_AFTER_CLOSE. The callback
new XML data nodes. Many applications, however, need to manipulate or
change the nodes during their operation, so Mini-XML provides functions
to change node values safely and without leaking memory.
Formatted Text
-Indexing
mxml_node_t *tree;
@@ -393,17 +393,17 @@ mxml_index_t
structures. The
indexes all element nodes alphabetically.
@@ -416,7 +416,7 @@ mxmlIndexFind()
.
The mxmlSAXLoadFd,
-mxmlSAXLoadFile, and
+ The mxmlSAXLoadFd,
+mxmlSAXLoadFile, and
mxmlSAXLoadString functions provide the SAX loading APIs.
Each function works like the corresponding mxmlLoad function
but uses a callback to process each node as it is read.
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 + 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:
diff --git a/www/docfiles/basics.html b/www/docfiles/basics.html index f2dce93..1dd05bc 100644 --- a/www/docfiles/basics.html +++ b/www/docfiles/basics.html @@ -1,9 +1,9 @@ -Every piece of information in an XML file (elements, text, numbers) - is stored in memory in "nodes". Nodes are defined by the + is stored in memory in "nodes". 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 + text) which determines which value you want to look at in the value union.
@@ -95,15 +95,16 @@ node->value.opaqueEach node also has a user_data member which allows you to associate application-specific data with each node as needed.
-New nodes are created using the -mxmlNewElement, -mxmlNewInteger, -mxmlNewOpaque, -mxmlNewReal, mxmlNewText - mxmlNewTextf -mxmlNewXML functions. Only elements can have child nodes, - and the top node must be an element, usually the <?xml - version="1.0"?> node created by mxmlNewXML().
+New nodes are created using the +mxmlNewElement, +mxmlNewInteger, +mxmlNewOpaque, +mxmlNewReal, +mxmlNewText +mxmlNewTextf mxmlNewXML + functions. Only elements can have child nodes, and the top node + must be an element, usually the <?xml version="1.0"?> node + created by mxmlNewXML().
Nodes have pointers to the node above (parent), below ( child), left (prev), and right (next) of the current node. If you have an XML file like the following:
@@ -138,7 +139,7 @@ child), left (prev), and right (next) of thewhere "-" is a pointer to the next node and "|" is a pointer to the first child node.
-Once you are done with the XML data, use the
+ 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: We start by creating the <?xml version="1.0"?> node common
- to all XML files using the
+ to all XML files using the
mxmlNewXML function: We then create the <data> node used for this document using
- the mxmlNewElement
+ the mxmlNewElement
function. The first argument specifies the parent node (xml)
while the second specifies the element name (data): Each <node>...</node> in the file is created using the
-mxmlNewElement and
+mxmlNewElement and
mxmlNewText functions. The first argument of mxmlNewText
specifies the parent node (node). The second argument
specifies whether whitespace appears before the text - 0 or false in
@@ -209,7 +210,7 @@ mxmlNewText
@@ -182,20 +183,20 @@ mxmlNew functions. The following code will create the XML document
mxmlNewText(node, 0, "val8");
xml = mxmlNewXML("1.0");
data = mxmlNewElement(xml, "data");
You load an XML file using the
+ You load an XML file using the
mxmlLoadFile function:
FILE *fp;
@@ -238,7 +239,7 @@ Chapter 3
. The example code uses the MXML_TEXT_CALLBACK
whitespace-separated text values. Other standard callbacks include
MXML_IGNORE_CALLBACK, MXML_INTEGER_CALLBACK,
MXML_OPAQUE_CALLBACK, and MXML_REAL_CALLBACK.
The mxmlLoadString +
The mxmlLoadString function loads XML node trees from a string:
@@ -257,7 +258,7 @@ mxmlLoadFile(). The second argument specifies the string orYou save an XML file using the
+ You save an XML file using the
mxmlSaveFile function:
FILE *fp;
@@ -276,9 +277,9 @@ fopen() or popen(). You can also use stdout if
file. Whitespace callbacks are covered in detail in
Chapter 3. The previous example code uses the MXML_NO_CALLBACK
constant to specify that no special whitespace handling is required.
The mxmlSaveAllocString -, and mxmlSaveString - functions save XML node trees to strings:
+The +mxmlSaveAllocString, and +mxmlSaveString functions save XML node trees to strings:
char buffer[8192]; char *ptr; @@ -298,7 +299,7 @@ mxmlSaveFile(). The mxmlSaveString function takes pointer allocated using malloc().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 + column 75 so that the text is readable in terminal windows. The mxmlSetWrapMargin function overrides the default wrap margin:
@@ -311,9 +312,9 @@ mxmlSaveFile(). The mxmlSaveString function takes pointerFinding and Iterating Nodes
-The mxmlWalkPrev and mxmlWalkNextfunctions can - be used to iterate through the XML node tree:
+The mxmlWalkPrev + and mxmlWalkNext +functions can be used to iterate through the XML node tree:
mxml_node_t *node; @@ -323,7 +324,7 @@ href="refapp.html#mxmlWalkNext">mxmlWalkNextfunctions can node = mxmlWalkNext(current, tree, MXML_DESCEND);-In addition, you can find a named element/node using the +
In addition, you can find a named element/node using the mxmlFindElement function:
mxml_node_t *node; diff --git a/www/docfiles/index.html b/www/docfiles/index.html index 3d7d644..a605858 100644 --- a/www/docfiles/index.html +++ b/www/docfiles/index.html @@ -1,9 +1,9 @@ -Mini-XML Programmers Manual, Version 2.4 +Mini-XML Programmers Manual, Version 2.5 - + @@ -78,109 +78,109 @@ A { text-decoration: none }
Release Notes-Library Reference +Library Reference
-
diff --git a/www/docfiles/install.html b/www/docfiles/install.html index f7b3b39..615623f 100644 --- a/www/docfiles/install.html +++ b/www/docfiles/install.html @@ -1,9 +1,9 @@ -- Contents
-- Enumerations +
- Contents
+- Functions
--
- mxml_sax_event_e
-- mxml_type_e
+- mxmlAdd
+- mxmlDelete
+- mxmlElementDeleteAttr
+- mxmlElementGetAttr
+- mxmlElementSetAttr
+- mxmlElementSetAttrf
+- mxmlEntityAddCallback +
+- mxmlEntityGetName
+- mxmlEntityGetValue
+- +mxmlEntityRemoveCallback
+- mxmlFindElement
+- mxmlIndexDelete
+- mxmlIndexEnum
+- mxmlIndexFind
+- mxmlIndexNew
+- mxmlIndexReset
+- mxmlLoadFd
+- mxmlLoadFile
+- mxmlLoadString
+- mxmlNewCDATA
+- mxmlNewCustom
+- mxmlNewElement
+- mxmlNewInteger
+- mxmlNewOpaque
+- mxmlNewReal
+- mxmlNewText
+- mxmlNewTextf
+- mxmlNewXML
+- mxmlRelease
+- mxmlRemove
+- mxmlRetain
+- mxmlSAXLoadFd
+- mxmlSAXLoadFile
+- mxmlSAXLoadString
+- mxmlSaveAllocString
+- mxmlSaveFd
+- mxmlSaveFile
+- mxmlSaveString
+- mxmlSetCDATA
+- mxmlSetCustom
+- mxmlSetCustomHandlers +
+- mxmlSetElement
+- mxmlSetErrorCallback +
+- mxmlSetInteger
+- mxmlSetOpaque
+- mxmlSetReal
+- mxmlSetText
+- mxmlSetTextf
+- mxmlSetWrapMargin
+- mxmlWalkNext
+- mxmlWalkPrev
- Functions +
- Data Types
--
-- mxmlAdd()
-- mxmlDelete()
-- mxmlElementDeleteAttr()
-- mxmlElementGetAttr()
-- mxmlElementSetAttr()
-- mxmlElementSetAttrf()
-- mxmlEntityAddCallback() -
-- mxmlEntityGetName()
-- mxmlEntityGetValue()
-- -mxmlEntityRemoveCallback()
-- mxmlFindElement()
-- mxmlIndexDelete()
-- mxmlIndexEnum()
-- mxmlIndexFind()
-- mxmlIndexNew()
-- mxmlIndexReset()
-- mxmlLoadFd()
-- mxmlLoadFile()
-- mxmlLoadString()
-- mxmlNewCDATA()
-- mxmlNewCustom()
-- mxmlNewElement()
-- mxmlNewInteger()
-- mxmlNewOpaque()
-- mxmlNewReal()
-- mxmlNewText()
-- mxmlNewTextf()
-- mxmlNewXML()
-- mxmlRelease()
-- mxmlRemove()
-- mxmlRetain()
-- mxmlSAXLoadFd()
-- mxmlSAXLoadFile()
-- mxmlSAXLoadString()
-- mxmlSaveAllocString()
-- mxmlSaveFd()
-- mxmlSaveFile()
-- mxmlSaveString()
-- mxmlSetCDATA()
-- mxmlSetCustom()
-- mxmlSetCustomHandlers() -
-- mxmlSetElement()
-- mxmlSetErrorCallback() -
-- mxmlSetInteger()
-- mxmlSetOpaque()
-- mxmlSetReal()
-- mxmlSetText()
-- mxmlSetTextf()
-- mxmlSetWrapMargin()
-- mxmlWalkNext()
-- mxmlWalkPrev()
-- Structures - -
-- Types -
--
- mxml_attr_t
-- +
- mxml_attr_t
+- mxml_custom_destroy_cb_t
-- mxml_custom_load_cb_t +
- mxml_custom_load_cb_t
-- mxml_custom_save_cb_t +
- mxml_custom_save_cb_t
-- mxml_custom_t
-- mxml_element_t
-- mxml_error_cb_t
-- mxml_index_t
-- mxml_load_cb_t
-- mxml_node_t
-- mxml_save_cb_t
-- mxml_sax_cb_t
-- mxml_sax_event_t
-- mxml_text_t
-- mxml_value_t
+- mxml_custom_t
+- mxml_element_t
+- mxml_error_cb_t
+- mxml_index_t
+- mxml_load_cb_t
+- mxml_node_t
+- mxml_save_cb_t
+- mxml_sax_cb_t
+- mxml_sax_event_t
+- mxml_text_t
+- mxml_value_t
- Unions +
- Structures +
+- Unions +
++
+- mxml_value_u
+- Constants +
Mini-XML Programmers Manual, Version 2.4 +Mini-XML Programmers Manual, Version 2.5 - + diff --git a/www/docfiles/intro.html b/www/docfiles/intro.html index a129dbf..59b91a8 100644 --- a/www/docfiles/intro.html +++ b/www/docfiles/intro.html @@ -1,9 +1,9 @@ -Mini-XML Programmers Manual, Version 2.4 +Mini-XML Programmers Manual, Version 2.5 - + @@ -28,7 +28,7 @@ A { text-decoration: none }
Introduction
-This programmers manual describes Mini-XML version 2.4, a small XML +
This programmers manual describes Mini-XML version 2.5, a small XML parsing library that you can use to read and write XML data files in your C and C++ applications.
Mini-XML was initially developed for the @@ -55,7 +55,6 @@ libxml2 library with something substantially smaller and
Please email me (mxml @ easysw . com) if you would like your project @@ -79,8 +78,8 @@ libxml2 library with something substantially smaller and provides the terms and conditions for using and distributing Mini-XML.
Appendix B, "Release Notes", lists the changes in each release of Mini-XML. -Appendix C, "Library Reference", - contains a complete reference for Mini-XML, generated by mxmldoc + Appendix C, "Library Reference +", contains a complete reference for Mini-XML, generated by mxmldoc . Appendix D, "XML Schema", shows the XML schema used for the XML files produced by mxmldoc. @@ -165,7 +164,7 @@ libxml2 library with something substantially smaller andLegal Stuff
-The Mini-XML library is copyright 2003-2007 by Michael Sweet.
+The Mini-XML library is copyright 2003-2008 by Michael Sweet.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software diff --git a/www/docfiles/license.html b/www/docfiles/license.html index afb8733..27ef792 100644 --- a/www/docfiles/license.html +++ b/www/docfiles/license.html @@ -1,9 +1,9 @@
-Mini-XML Programmers Manual, Version 2.4 +Mini-XML Programmers Manual, Version 2.5 - + diff --git a/www/docfiles/mxmldoc.html b/www/docfiles/mxmldoc.html index 4445b39..a86ba75 100644 --- a/www/docfiles/mxmldoc.html +++ b/www/docfiles/mxmldoc.html @@ -1,9 +1,9 @@ -Mini-XML Programmers Manual, Version 2.4 +Mini-XML Programmers Manual, Version 2.5 - + diff --git a/www/docfiles/refapp.html b/www/docfiles/refapp.html deleted file mode 100644 index 0888df1..0000000 --- a/www/docfiles/refapp.html +++ /dev/null @@ -1,1821 +0,0 @@ - - - -Mini-XML Programmers Manual, Version 2.4 - - - - - - - - - - -Contents -Previous -Next -
-Library Reference
-Contents
--
- - -- Enumerations
-- Functions
-- Structures
-- Types
-- Unions
-Enumerations
- - - -mxml_sax_event_e
-Description
-SAX event type.
-Values
--- --
-- - Name Description - 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
-Description
-The XML node type.
-Values
--- --
-- - Name Description - 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 Functions
--
- - -- mxmlAdd()
-- mxmlDelete()
-- mxmlElementDeleteAttr() - - Mini-XML 2.4
-- mxmlElementGetAttr()
-- mxmlElementSetAttr()
-- mxmlElementSetAttrf() - - Mini-XML 2.3
-- mxmlEntityAddCallback() -
-- mxmlEntityGetName()
-- mxmlEntityGetValue()
-- mxmlEntityRemoveCallback() -
-- mxmlFindElement()
-- mxmlIndexDelete()
-- mxmlIndexEnum()
-- mxmlIndexFind()
-- mxmlIndexNew()
-- mxmlIndexReset()
-- mxmlLoadFd()
-- mxmlLoadFile()
-- mxmlLoadString()
-- mxmlNewCDATA() - - Mini-XML 2.3
-- mxmlNewCustom() - - Mini-XML 2.1
-- mxmlNewElement()
-- mxmlNewInteger()
-- mxmlNewOpaque()
-- mxmlNewReal()
-- mxmlNewText()
-- mxmlNewTextf()
-- mxmlNewXML() - - Mini-XML 2.3
-- mxmlRelease() - - Mini-XML 2.3
-- mxmlRemove()
-- mxmlRetain() - - Mini-XML 2.3
-- mxmlSAXLoadFd() - - Mini-XML 2.3
-- mxmlSAXLoadFile() - - Mini-XML 2.3
-- mxmlSAXLoadString() - - Mini-XML 2.3
-- mxmlSaveAllocString()
-- mxmlSaveFd()
-- mxmlSaveFile()
-- mxmlSaveString()
-- mxmlSetCDATA() - - Mini-XML 2.3
-- mxmlSetCustom() - - Mini-XML 2.1
-- mxmlSetCustomHandlers() -
-- mxmlSetElement()
-- mxmlSetErrorCallback()
-- mxmlSetInteger()
-- mxmlSetOpaque()
-- mxmlSetReal()
-- mxmlSetText()
-- mxmlSetTextf()
-- mxmlSetWrapMargin() - - Mini-XML 2.3
-- mxmlWalkNext()
-- mxmlWalkPrev()
-mxmlAdd()
-Description
-Add a node to a tree.
-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 is NULL, puts - the new node at the beginning of the child list (MXML_ADD_BEFORE) or at - the end of the child list (MXML_ADD_AFTER). The constant - MXML_ADD_TO_PARENT can be used to specify a NULL child pointer.
-Syntax
-void -
-
mxmlAdd( mxml_node_t * parent, int - where, mxml_node_t * child, -mxml_node_t * node);Arguments
----
-- - Name Description - parent Parent node - where Where to add, MXML_ADD_BEFORE or - MXML_ADD_AFTER - child Child node for where or - MXML_ADD_TO_PARENT - node Node to add Returns
-Nothing.
- - -mxmlDelete()
-Description
-Delete a node and all of its children.
-If the specified node has a parent, this function first removes the - node from its parent using the mxmlRemove() function.
-Syntax
-void -
-
mxmlDelete( mxml_node_t * node);Arguments
----
-- - Name Description - node Node to delete Returns
-Nothing.
- - -- - Mini-XML 2.4 mxmlElementDeleteAttr() -
-Description
-Delete an attribute.
-Syntax
-void -
-
mxmlElementDeleteAttr( mxml_node_t * - node, const char * name);Arguments
----
-- - Name Description - node Element - name Attribute name Returns
-Nothing.
- - -mxmlElementGetAttr()
-Description
-Get an attribute.
-This function returns NULL if the node is not an element or the named - attribute does not exist.
-Syntax
-const char * -
-
mxmlElementGetAttr( mxml_node_t * node, - const char * name);Arguments
----
-- - Name Description - node Element node - name Name of attribute Returns
-Attribute value or NULL
- - -mxmlElementSetAttr()
-Description
-Set an 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.
-Syntax
-void -
-
mxmlElementSetAttr( mxml_node_t * node, - const char * name, const char * value);Arguments
----
-- - Name Description - node Element node - name Name of attribute - value Attribute value Returns
-Nothing.
- - -- - Mini-XML 2.3 mxmlElementSetAttrf() -
-Description
-Set an attribute with a formatted value.
-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.
-Syntax
-void -
-
mxmlElementSetAttrf( mxml_node_t * node, - const char * name, const char * format, ...);Arguments
----
-- - Name Description - node Element node - name Name of attribute - format Printf-style attribute value - ... Additional arguments as needed Returns
-Nothing.
- - --mxmlEntityAddCallback()
-Description
-Add a callback to convert entities to Unicode.
-Syntax
-int -
-
mxmlEntityAddCallback(void);Arguments
-None.
-Returns
-0 on success, -1 on failure
- - -mxmlEntityGetName()
-Description
-Get the name that corresponds to the character value.
-If val does not need to be represented by a named entity, NULL is - returned.
-Syntax
-const char * -
-
mxmlEntityGetName( int val);Arguments
----
-- - Name Description - val Character value Returns
-Entity name or NULL
- - -mxmlEntityGetValue()
-Description
-Get the character corresponding to a named entity.
-The entity name can also be a numeric constant. -1 is returned if the - name is not known.
-Syntax
-int -
-
mxmlEntityGetValue( const char * name);Arguments
----
-- - Name Description - name Entity name Returns
-Character value or -1 on error
- - --mxmlEntityRemoveCallback()
-Description
-Remove a callback.
-Syntax
-void -
-
mxmlEntityRemoveCallback(void);Arguments
-None.
-Returns
-Nothing.
- - -mxmlFindElement()
-Description
-Find the named element.
-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 whether the search descends into child nodes; normally you - will use MXML_DESCEND_FIRST for the initial search and MXML_NO_DESCEND - to find additional direct descendents of the node. The top node - argument constrains the search to a particular node's children.
-Syntax
-mxml_node_t * -
-
mxmlFindElement( mxml_node_t * node, -mxml_node_t * top, const char * name, const char * attr, const char - * value, int descend);Arguments
----
-- - Name Description - node Current node - top Top node - name Element name or NULL for any - attr Attribute name, or NULL for none - value Attribute value, or NULL for any - descend Descend into tree - MXML_DESCEND, - MXML_NO_DESCEND, or MXML_DESCEND_FIRST Returns
-Element node or NULL
- - -mxmlIndexDelete()
-Description
-Delete an index.
-Syntax
-void -
-
mxmlIndexDelete( mxml_index_t * ind); -Arguments
----
-- - Name Description - ind Index to delete Returns
-Nothing.
- - -mxmlIndexEnum()
-Description
-Return the next node in the index.
-Nodes are returned in the sorted order of the index.
-Syntax
-mxml_node_t * -
-
mxmlIndexEnum( mxml_index_t * ind); -Arguments
----
-- - Name Description - ind Index to enumerate Returns
-Next node or NULL if there is none
- - -mxmlIndexFind()
-Description
-Find the next matching node.
-You should call mxmlIndexReset() prior to using this function for the - first time with a particular set of "element" and "value" strings. - Passing NULL for both "element" and "value" is equivalent to calling - mxmlIndexEnum().
-Syntax
-mxml_node_t * -
-
mxmlIndexFind( mxml_index_t * ind, - const char * element, const char * value);Arguments
----
-- - Name Description - ind Index to search - element Element name to find, if any - value Attribute value, if any Returns
-Node or NULL if none found
- - -mxmlIndexNew()
-Description
-Create a new index.
-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.
-Syntax
-mxml_index_t * -
-
mxmlIndexNew( mxml_node_t * node, const - char * element, const char * attr);Arguments
----
-- - Name Description - node XML node tree - element Element to index or NULL for all - attr Attribute to index or NULL for none Returns
-New index
- - -mxmlIndexReset()
-Description
-Reset the enumeration/find pointer in the index and return the first - node in the index.
-This function should be called prior to using mxmlIndexEnum() or - mxmlIndexFind() for the first time.
-Syntax
-mxml_node_t * -
-
mxmlIndexReset( mxml_index_t * ind); -Arguments
----
-- - Name Description - ind Index to reset Returns
-First node or NULL if there is none
- - -mxmlLoadFd()
-Description
-Load a file descriptor into an XML node tree.
-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. If - MXML_NO_CALLBACK is specified then all child nodes will be either - MXML_ELEMENT or MXML_TEXT nodes.
-The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK, - MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading - child nodes of the specified type.
-Syntax
-mxml_node_t * -
-
mxmlLoadFd( mxml_node_t * top, int fd, mxml_load_cb_t cb);Arguments
----
-- - Name Description - top Top node - fd File descriptor to read from - cb Callback function or MXML_NO_CALLBACK Returns
-First node or NULL if the file could not be read.
- - -mxmlLoadFile()
-Description
-Load a file into an XML node tree.
-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. If - MXML_NO_CALLBACK is specified then all child nodes will be either - MXML_ELEMENT or MXML_TEXT nodes.
-The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK, - MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading - child nodes of the specified type.
-Syntax
-mxml_node_t * -
-
mxmlLoadFile( mxml_node_t * top, FILE * - fp, mxml_load_cb_t cb);Arguments
----
-- - Name Description - top Top node - fp File to read from - cb Callback function or MXML_NO_CALLBACK Returns
-First node or NULL if the file could not be read.
- - -mxmlLoadString()
-Description
-Load a string into an XML node tree.
-The nodes in the specified string are added to the specified top - node. If no top node is provided, the XML string MUST be well-formed - with a single parent node like <?xml> for the entire string. The - callback function returns the value type that should be used for child - nodes. If MXML_NO_CALLBACK is specified then all child nodes will be - either MXML_ELEMENT or MXML_TEXT nodes.
-The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK, - MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading - child nodes of the specified type.
-Syntax
-mxml_node_t * -
-
mxmlLoadString( mxml_node_t * top, const - char * s, mxml_load_cb_t cb);Arguments
----
-- - Name Description - top Top node - s String to load - cb Callback function or MXML_NO_CALLBACK Returns
-First node or NULL if the string has errors.
- - -- - Mini-XML 2.3 mxmlNewCDATA()
-Description
-Create a new CDATA node.
-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 use the MXML_ELEMENT type.
-Syntax
-mxml_node_t * -
-
mxmlNewCDATA( mxml_node_t * parent, - const char * data);Arguments
----
-- - Name Description - parent Parent node or MXML_NO_PARENT - data Data string Returns
-New node
- - -- - Mini-XML 2.1 mxmlNewCustom()
-Description
-Create a new custom data node.
-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.
-Syntax
-mxml_node_t * -
-
mxmlNewCustom( mxml_node_t * parent, - void * data, -mxml_custom_destroy_cb_t destroy);Arguments
----
-- - Name Description - parent Parent node or MXML_NO_PARENT - data Pointer to data - destroy Function to destroy data Returns
-New node
- - -mxmlNewElement()
-Description
-Create a new element node.
-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.
-Syntax
-mxml_node_t * -
-
mxmlNewElement( mxml_node_t * parent, - const char * name);Arguments
----
-- - Name Description - parent Parent node or MXML_NO_PARENT - name Name of element Returns
-New node
- - -mxmlNewInteger()
-Description
-Create a new integer node.
-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.
-Syntax
-mxml_node_t * -
-
mxmlNewInteger( mxml_node_t * parent, - int integer);Arguments
----
-- - Name Description - parent Parent node or MXML_NO_PARENT - integer Integer value Returns
-New node
- - -mxmlNewOpaque()
-Description
-Create a new opaque string.
-The new opaque 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 node has no parent. The opaque string must be nul-terminated - and is copied into the new node.
-Syntax
-mxml_node_t * -
-
mxmlNewOpaque( mxml_node_t * parent, - const char * opaque);Arguments
----
-- - Name Description - parent Parent node or MXML_NO_PARENT - opaque Opaque string Returns
-New node
- - -mxmlNewReal()
-Description
-Create a new real number node.
-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.
-Syntax
-mxml_node_t * -
-
mxmlNewReal( mxml_node_t * parent, - double real);Arguments
----
-- - Name Description - parent Parent node or MXML_NO_PARENT - real Real number value Returns
-New node
- - -mxmlNewText()
-Description
-Create a new text fragment node.
-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.
-Syntax
-mxml_node_t * -
-
mxmlNewText( mxml_node_t * parent, int - whitespace, const char * string);Arguments
----
-- - Name Description - parent Parent node or MXML_NO_PARENT - whitespace 1 = leading whitespace, 0 = no - whitespace - string String Returns
-New node
- - -mxmlNewTextf()
-Description
-Create a new formatted text fragment node.
-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.
-Syntax
-mxml_node_t * -
-
mxmlNewTextf( mxml_node_t * parent, int - whitespace, const char * format, ...);Arguments
----
-- - Name Description - parent Parent node or MXML_NO_PARENT - whitespace 1 = leading whitespace, 0 = no - whitespace - format Printf-style frmat string - ... Additional args as needed Returns
-New node
- - -- - Mini-XML 2.3 mxmlNewXML()
-Description
-Create a new XML document tree.
-The "version" argument specifies the version number to put in the - ?xml element node. If NULL, version 1.0 is assumed.
-Syntax
-mxml_node_t * -
-
mxmlNewXML( const char * version);Arguments
----
-- - Name Description - version Version number to use Returns
-New ?xml node
- - -- - Mini-XML 2.3 mxmlRelease()
-Description
-Release a node.
-When the reference count reaches zero, the node (and any children) is - deleted via mxmlDelete().
-Syntax
-int -
-
mxmlRelease( mxml_node_t * node);Arguments
----
-- - Name Description - node Node Returns
-New reference count
- - -mxmlRemove()
-Description
-Remove a node from its parent.
-Does not free memory used by the node - use mxmlDelete() for that. - This function does nothing if the node has no parent.
-Syntax
-void -
-
mxmlRemove( mxml_node_t * node);Arguments
----
-- - Name Description - node Node to remove Returns
-Nothing.
- - -- - Mini-XML 2.3 mxmlRetain()
-Description
-Retain a node.
-Syntax
-int -
-
mxmlRetain( mxml_node_t * node);Arguments
----
-- - Name Description - node Node Returns
-New reference count
- - -- - Mini-XML 2.3 mxmlSAXLoadFd()
-Description
-Load a file descriptor into an XML node tree using a SAX callback.
-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. If - MXML_NO_CALLBACK is specified then all child nodes will be either - MXML_ELEMENT or MXML_TEXT nodes.
-The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK, - MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading - child nodes of the specified type.
-The SAX callback must call mxmlRetain() for any nodes that need to be - kept for later use. Otherwise, nodes are deleted when the parent node - is closed or after each data, comment, CDATA, or directive node.
-Syntax
-mxml_node_t * -
-
mxmlSAXLoadFd( mxml_node_t * top, int - fd, mxml_load_cb_t cb, -mxml_sax_cb_t sax_cb, void * sax_data);Arguments
----
-- - Name Description - top Top node - fd File descriptor to read from - cb Callback function or MXML_NO_CALLBACK - sax_cb SAX callback or MXML_NO_CALLBACK - sax_data SAX user data Returns
-First node or NULL if the file could not be read.
- - -- - Mini-XML 2.3 mxmlSAXLoadFile()
-Description
-Load a file into an XML node tree using a SAX callback.
-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. If - MXML_NO_CALLBACK is specified then all child nodes will be either - MXML_ELEMENT or MXML_TEXT nodes.
-The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK, - MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading - child nodes of the specified type.
-The SAX callback must call mxmlRetain() for any nodes that need to be - kept for later use. Otherwise, nodes are deleted when the parent node - is closed or after each data, comment, CDATA, or directive node.
-Syntax
-mxml_node_t * -
-
mxmlSAXLoadFile( mxml_node_t * top, FILE - * fp, mxml_load_cb_t cb, -mxml_sax_cb_t sax_cb, void * sax_data);Arguments
----
-- - Name Description - top Top node - fp File to read from - cb Callback function or MXML_NO_CALLBACK - sax_cb SAX callback or MXML_NO_CALLBACK - sax_data SAX user data Returns
-First node or NULL if the file could not be read.
- - -- - Mini-XML 2.3 mxmlSAXLoadString()
-Description
-Load a string into an XML node tree using a SAX callback.
-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. If MXML_NO_CALLBACK is specified then all child nodes will be - either MXML_ELEMENT or MXML_TEXT nodes.
-The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK, - MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading - child nodes of the specified type.
-The SAX callback must call mxmlRetain() for any nodes that need to be - kept for later use. Otherwise, nodes are deleted when the parent node - is closed or after each data, comment, CDATA, or directive node.
-Syntax
-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);Arguments
----
-- - Name Description - top Top node - s String to load - cb Callback function or MXML_NO_CALLBACK - sax_cb SAX callback or MXML_NO_CALLBACK - sax_data SAX user data Returns
-First node or NULL if the string has errors.
- - -mxmlSaveAllocString() -
-Description
-Save an XML node tree to an allocated string.
-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 - allocated.
-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 before MXML_TEXT nodes with - leading whitespace and before attribute names inside opening element - tags.
-Syntax
-char * -
-
mxmlSaveAllocString( mxml_node_t * node, - mxml_save_cb_t cb);Arguments
----
-- - Name Description - node Node to write - cb Whitespace callback or MXML_NO_CALLBACK Returns
-Allocated string or NULL
- - -mxmlSaveFd()
-Description
-Save an XML tree to a file descriptor.
-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 before MXML_TEXT nodes with - leading whitespace and before attribute names inside opening element - tags.
-Syntax
-int -
-
mxmlSaveFd( mxml_node_t * node, int fd, mxml_save_cb_t cb);Arguments
----
-- - Name Description - node Node to write - fd File descriptor to write to - cb Whitespace callback or MXML_NO_CALLBACK Returns
-0 on success, -1 on error.
- - -mxmlSaveFile()
-Description
-Save an XML tree to a file.
-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 before MXML_TEXT nodes with - leading whitespace and before attribute names inside opening element - tags.
-Syntax
-int -
-
mxmlSaveFile( mxml_node_t * node, FILE * - fp, mxml_save_cb_t cb);Arguments
----
-- - Name Description - node Node to write - fp File to write to - cb Whitespace callback or MXML_NO_CALLBACK Returns
-0 on success, -1 on error.
- - -mxmlSaveString()
-Description
-Save an XML node tree to a string.
-This function returns the total number of bytes that would be - required for the string but only copies (bufsize - 1) characters into - the specified buffer.
-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 before MXML_TEXT nodes with - leading whitespace and before attribute names inside opening element - tags.
-Syntax
-int -
-
mxmlSaveString( mxml_node_t * node, char - * buffer, int bufsize, mxml_save_cb_t - cb);Arguments
----
-- - Name Description - node Node to write - buffer String buffer - bufsize Size of string buffer - cb Whitespace callback or MXML_NO_CALLBACK Returns
-Size of string
- - -- - Mini-XML 2.3 mxmlSetCDATA()
-Description
-Set the element name of a CDATA node.
-The node is not changed if it is not a CDATA element node.
-Syntax
-int -
-
mxmlSetCDATA( mxml_node_t * node, const - char * data);Arguments
----
-- - Name Description - node Node to set - data New data string Returns
-0 on success, -1 on failure
- - -- - Mini-XML 2.1 mxmlSetCustom()
-Description
-Set the data and destructor of a custom data node.
-The node is not changed if it is not a custom node.
-Syntax
-int -
-
mxmlSetCustom( mxml_node_t * node, void - * data, mxml_custom_destroy_cb_t - destroy);Arguments
----
-- - Name Description - node Node to set - data New data pointer - destroy New destructor function Returns
-0 on success, -1 on failure
- - --mxmlSetCustomHandlers()
-Description
-Set the handling functions for custom data.
-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 and NULL on error.
-Syntax
-void -
-
mxmlSetCustomHandlers( -mxml_custom_load_cb_t load, -mxml_custom_save_cb_t save);Arguments
----
-- - Name Description - load Load function - save Save function Returns
-Nothing.
- - -mxmlSetElement()
-Description
-Set the name of an element node.
-The node is not changed if it is not an element node.
-Syntax
-int -
-
mxmlSetElement( mxml_node_t * node, - const char * name);Arguments
----
-- - Name Description - node Node to set - name New name string Returns
-0 on success, -1 on failure
- - -mxmlSetErrorCallback() -
-Description
-Set the error message callback.
-Syntax
-void -
-
mxmlSetErrorCallback( mxml_error_cb_t - cb);Arguments
----
-- - Name Description - cb Error callback function Returns
-Nothing.
- - -mxmlSetInteger()
-Description
-Set the value of an integer node.
-The node is not changed if it is not an integer node.
-Syntax
-int -
-
mxmlSetInteger( mxml_node_t * node, int - integer);Arguments
----
-- - Name Description - node Node to set - integer Integer value Returns
-0 on success, -1 on failure
- - -mxmlSetOpaque()
-Description
-Set the value of an opaque node.
-The node is not changed if it is not an opaque node.
-Syntax
-int -
-
mxmlSetOpaque( mxml_node_t * node, const - char * opaque);Arguments
----
-- - Name Description - node Node to set - opaque Opaque string Returns
-0 on success, -1 on failure
- - -mxmlSetReal()
-Description
-Set the value of a real number node.
-The node is not changed if it is not a real number node.
-Syntax
-int -
-
mxmlSetReal( mxml_node_t * node, double - real);Arguments
----
-- - Name Description - node Node to set - real Real number value Returns
-0 on success, -1 on failure
- - -mxmlSetText()
-Description
-Set the value of a text node.
-The node is not changed if it is not a text node.
-Syntax
-int -
-
mxmlSetText( mxml_node_t * node, int - whitespace, const char * string);Arguments
----
-- - Name Description - node Node to set - whitespace 1 = leading whitespace, 0 = no - whitespace - string String Returns
-0 on success, -1 on failure
- - -mxmlSetTextf()
-Description
-Set the value of a text node to a formatted string.
-The node is not changed if it is not a text node.
-Syntax
-int -
-
mxmlSetTextf( mxml_node_t * node, int - whitespace, const char * format, ...);Arguments
----
-- - Name Description - node Node to set - whitespace 1 = leading whitespace, 0 = no - whitespace - format Printf-style format string - ... Additional arguments as needed Returns
-0 on success, -1 on failure
- - -- - Mini-XML 2.3 mxmlSetWrapMargin()
-Description
-Set the the wrap margin when saving XML data.
-Wrapping is disabled when "column" is <= 0.
-Syntax
-void -
-
mxmlSetWrapMargin( int column);Arguments
----
-- - Name Description - column Column for wrapping Returns
-Nothing.
- - -mxmlWalkNext()
-Description
-Walk to the next logical node in the tree.
-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.
-Syntax
-mxml_node_t * -
-
mxmlWalkNext( mxml_node_t * node, -mxml_node_t * top, int descend);Arguments
----
-- - Name Description - node Current node - top Top node - descend Descend into tree - MXML_DESCEND, - MXML_NO_DESCEND, or MXML_DESCEND_FIRST Returns
-Next node or NULL
- - -mxmlWalkPrev()
-Description
-Walk to the previous logical node in the tree.
-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.
-Syntax
-mxml_node_t * -
-
mxmlWalkPrev( mxml_node_t * node, -mxml_node_t * top, int descend);Arguments
----
-- - Name Description - node Current node - top Top node - descend Descend into tree - MXML_DESCEND, - MXML_NO_DESCEND, or MXML_DESCEND_FIRST Returns
-Previous node or NULL
- - -Structures
-
An XML element attribute value.
- struct mxml_attr_s
-
{
-
char * name;
-
char * value;
-
};
Name | Description |
---|---|
name | Attribute name |
value | Attribute value |
An XML custom value.
- struct mxml_custom_s
-
{
-
void * data;
-
mxml_custom_destroy_cb_t
- destroy;
-
};
Name | Description |
---|---|
data | Pointer to (allocated) custom data |
destroy | Pointer to destructor function |
An XML element value.
- struct mxml_element_s
-
{
-
mxml_attr_t * attrs;
-
char * name;
-
int num_attrs;
-
};
Name | Description |
---|---|
attrs | Attributes |
name | Name of element |
num_attrs | Number of attributes |
An XML node index.
- struct mxml_index_s
-
{
-
int alloc_nodes;
-
char * attr;
-
int cur_node;
-
mxml_node_t ** nodes;
-
int num_nodes;
-
};
Name | Description |
---|---|
alloc_nodes | Allocated nodes in index |
attr | Attribute used for indexing or NULL |
cur_node | Current node |
nodes | Node array |
num_nodes | Number of nodes in index |
An XML node.
- struct mxml_node_s
-
{
-
struct mxml_node_s * child;
-
struct mxml_node_s * last_child;
-
struct mxml_node_s * next;
-
struct mxml_node_s * parent;
-
struct mxml_node_s * prev;
-
int ref_count;
-
mxml_type_t type;
-
void * user_data;
-
mxml_value_t value;
-
};
Name | Description |
---|---|
child | First child node |
last_child | Last child node |
next | Next node under same parent |
parent | Parent node |
prev | Previous node under same parent |
ref_count | Use count |
type | Node type |
user_data | User data |
value | Node value |
An XML text value.
- struct mxml_text_s
-
{
-
char * string;
-
int whitespace;
-
};
Name | Description |
---|---|
string | Fragment string |
whitespace | Leading whitespace? |
An XML element attribute value.
-typedef struct mxml_attr_s - mxml_attr_t;
- - -Custom data destructor
-typedef void (*mxml_custom_destroy_cb_t)(void *);
- - -Custom data load callback function
-typedef int (*mxml_custom_load_cb_t)( -mxml_node_t *, const char *);
- - -Custom data save callback function
-typedef char * (*mxml_custom_save_cb_t)( -mxml_node_t *);
- - -An XML custom value.
-typedef struct mxml_custom_s - mxml_custom_t;
- - -An XML element value.
-typedef struct mxml_element_s - mxml_element_t;
- - -Error callback function
-typedef void (*mxml_error_cb_t)(const char *);
- - -An XML node index.
-typedef struct mxml_index_s - mxml_index_t;
- - -Load callback function
-typedef mxml_type_t (*mxml_load_cb_t)( -mxml_node_t *);
- - -An XML node.
-typedef struct mxml_node_s - mxml_node_t;
- - -Save callback function
-typedef const char * (*mxml_save_cb_t)( -mxml_node_t *, int);
- - -SAX callback function
-typedef void (*mxml_sax_cb_t)(mxml_node_t - *, mxml_sax_event_t, void *);
- - -SAX event type.
-typedef enum mxml_sax_event_e - mxml_sax_event_t;
- - -An XML text value.
-typedef struct mxml_text_s - mxml_text_t;
- - -An XML node value.
-typedef union mxml_value_u - mxml_value_t;
- - -An XML node value.
- union mxml_value_u
-
{
-
mxml_custom_t custom;
-
mxml_element_t element;
-
int integer;
-
char * opaque;
-
double real;
-
mxml_text_t text;
-
};
Name | Description |
---|---|
custom - - Mini-XML 2.1 | Custom data |
element | Element |
integer | Integer number |
opaque | Opaque string |
real | Real number |
text | Text fragment |
Add a node to a tree.
+ void mxmlAdd (
+
mxml_node_t *parent,
+
int where,
+
mxml_node_t *child,
+
mxml_node_t *node
+
);
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 is NULL, puts the new node at the beginning of the child + list (MXML_ADD_BEFORE) or at the end of the child list + (MXML_ADD_AFTER). The constant MXML_ADD_TO_PARENT can be used to + specify a NULL child pointer.
+Delete a node and all of its children.
+ void mxmlDelete (
+
mxml_node_t *node
+
);
If the specified node has a parent, this function + first removes the node from its parent using the mxmlRemove() function.
+Delete an attribute.
+ void mxmlElementDeleteAttr (
+
mxml_node_t *node,
+
const char *name
+
);
Get an attribute.
+ const char *mxmlElementGetAttr (
+
mxml_node_t *node,
+
const char *name
+
);
Attribute value or NULL
+This function returns NULL if the node is not an + element or the named attribute does not exist.
+Set an attribute.
+ void mxmlElementSetAttr (
+
mxml_node_t *node,
+
const char *name,
+
const char *value
+
);
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.
+Set an attribute with a formatted value.
+ void mxmlElementSetAttrf (
+
mxml_node_t *node,
+
const char *name,
+
const char *format,
+
...
+
);
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.
+Add a callback to convert entities to Unicode.
+int mxmlEntityAddCallback (void);
+0 on success, -1 on failure
+Get the name that corresponds to the character + value.
+ const char *mxmlEntityGetName (
+
int val
+
);
Entity name or NULL
+If val does not need to be represented by a named + entity, NULL is returned.
+Get the character corresponding to a named + entity.
+ int mxmlEntityGetValue (
+
const char *name
+
);
Character value or -1 on error
+The entity name can also be a numeric constant. -1 + is returned if the name is not known.
+Remove a callback.
+void mxmlEntityRemoveCallback (void);
+Find the named element.
+ mxml_node_t *mxmlFindElement
+ (
+
mxml_node_t *node,
+
mxml_node_t *top,
+
const char *name,
+
const char *attr,
+
const char *value,
+
int descend
+
);
Element node or NULL
+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 whether the search descends into child + nodes; normally you will use MXML_DESCEND_FIRST for the initial search + and MXML_NO_DESCEND to find additional direct descendents of the node. + The top node argument constrains the search to a particular node's + children.
+Delete an index.
+ void mxmlIndexDelete (
+
mxml_index_t *ind
+
);
Return the next node in the index.
+ mxml_node_t *mxmlIndexEnum (
+
mxml_index_t *ind
+
);
Next node or NULL if there is none
+Nodes are returned in the sorted order of the + index.
+Find the next matching node.
+ mxml_node_t *mxmlIndexFind (
+
mxml_index_t *ind,
+
const char *element,
+
const char *value
+
);
Node or NULL if none found
+You should call mxmlIndexReset() prior to using + this function for the first time with a particular set of "element" and + "value" strings. Passing NULL for both "element" and "value" is + equivalent to calling mxmlIndexEnum().
+Create a new index.
+ mxml_index_t *mxmlIndexNew
+ (
+
mxml_node_t *node,
+
const char *element,
+
const char *attr
+
);
New index
+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.
+Reset the enumeration/find pointer in the index + and return the first node in the index.
+ mxml_node_t *mxmlIndexReset
+ (
+
mxml_index_t *ind
+
);
First node or NULL if there is none
+This function should be called prior to using + mxmlIndexEnum() or mxmlIndexFind() for the first time.
+Load a file descriptor into an XML node tree.
+ mxml_node_t *mxmlLoadFd (
+
mxml_node_t *top,
+
int fd,
+
mxml_load_cb_t cb
+
);
First node or NULL if the file could not be read.
+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. If MXML_NO_CALLBACK is specified then all child nodes will
+ be either MXML_ELEMENT or MXML_TEXT nodes.
+
+
The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
+ MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
+ child nodes of the specified type.
Load a file into an XML node tree.
+ mxml_node_t *mxmlLoadFile (
+
mxml_node_t *top,
+
FILE *fp,
+
mxml_load_cb_t cb
+
);
First node or NULL if the file could not be read.
+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. If MXML_NO_CALLBACK is specified then all child nodes will
+ be either MXML_ELEMENT or MXML_TEXT nodes.
+
+
The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
+ MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
+ child nodes of the specified type.
Load a string into an XML node tree.
+ mxml_node_t *mxmlLoadString
+ (
+
mxml_node_t *top,
+
const char *s,
+
mxml_load_cb_t cb
+
);
First node or NULL if the string has errors.
+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. If MXML_NO_CALLBACK is specified then all child
+ nodes will be either MXML_ELEMENT or MXML_TEXT nodes.
+
+
The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
+ MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
+ child nodes of the specified type.
Create a new CDATA node.
+ mxml_node_t *mxmlNewCDATA (
+
mxml_node_t *parent,
+
const char *data
+
);
New node
+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 use the + MXML_ELEMENT type.
+Create a new custom data node.
+ mxml_node_t *mxmlNewCustom (
+
mxml_node_t *parent,
+
void *data,
+
mxml_custom_destroy_cb_t
+ destroy
+
);
New node
+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.
+Create a new element node.
+ mxml_node_t *mxmlNewElement
+ (
+
mxml_node_t *parent,
+
const char *name
+
);
New node
+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.
+Create a new integer node.
+ mxml_node_t *mxmlNewInteger
+ (
+
mxml_node_t *parent,
+
int integer
+
);
New node
+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.
+Create a new opaque string.
+ mxml_node_t *mxmlNewOpaque (
+
mxml_node_t *parent,
+
const char *opaque
+
);
New node
+The new opaque 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 node has no parent. The opaque string + must be nul-terminated and is copied into the new node.
+Create a new real number node.
+ mxml_node_t *mxmlNewReal (
+
mxml_node_t *parent,
+
double real
+
);
New node
+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.
+Create a new text fragment node.
+ mxml_node_t *mxmlNewText (
+
mxml_node_t *parent,
+
int whitespace,
+
const char *string
+
);
New node
+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.
+Create a new formatted text fragment node.
+ mxml_node_t *mxmlNewTextf (
+
mxml_node_t *parent,
+
int whitespace,
+
const char *format,
+
...
+
);
New node
+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.
+Create a new XML document tree.
+ mxml_node_t *mxmlNewXML (
+
const char *version
+
);
New ?xml node
+The "version" argument specifies the version + number to put in the ?xml element node. If NULL, version 1.0 is + assumed.
+Release a node.
+ int mxmlRelease (
+
mxml_node_t *node
+
);
New reference count
+When the reference count reaches zero, the node + (and any children) is deleted via mxmlDelete().
+Remove a node from its parent.
+ void mxmlRemove (
+
mxml_node_t *node
+
);
Does not free memory used by the node - use + mxmlDelete() for that. This function does nothing if the node has no + parent.
+Retain a node.
+ int mxmlRetain (
+
mxml_node_t *node
+
);
New reference count
+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
+
);
First node or NULL if the file could not be read.
+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. If MXML_NO_CALLBACK is specified then all child nodes will
+ be either MXML_ELEMENT or MXML_TEXT nodes.
+
+
The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
+ MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
+ child nodes of the specified type.
+
+
The SAX callback must call mxmlRetain() for any nodes that need to
+ be kept for later use. Otherwise, nodes are deleted when the parent
+ node is closed or after each data, comment, CDATA, or directive node.
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
+
);
First node or NULL if the file could not be read.
+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. If MXML_NO_CALLBACK is specified then all child nodes will
+ be either MXML_ELEMENT or MXML_TEXT nodes.
+
+
The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
+ MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
+ child nodes of the specified type.
+
+
The SAX callback must call mxmlRetain() for any nodes that need to
+ be kept for later use. Otherwise, nodes are deleted when the parent
+ node is closed or after each data, comment, CDATA, or directive node.
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
+
);
First node or NULL if the string has errors.
+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. If MXML_NO_CALLBACK is specified then all child
+ nodes will be either MXML_ELEMENT or MXML_TEXT nodes.
+
+
The constants MXML_INTEGER_CALLBACK, MXML_OPAQUE_CALLBACK,
+ MXML_REAL_CALLBACK, and MXML_TEXT_CALLBACK are defined for loading
+ child nodes of the specified type.
+
+
The SAX callback must call mxmlRetain() for any nodes that need to
+ be kept for later use. Otherwise, nodes are deleted when the parent
+ node is closed or after each data, comment, CDATA, or directive node.
Save an XML node tree to an allocated string.
+ char *mxmlSaveAllocString (
+
mxml_node_t *node,
+
mxml_save_cb_t cb
+
);
Allocated string or NULL
+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 allocated.
+
+
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 before
+ MXML_TEXT nodes with leading whitespace and before attribute names
+ inside opening element tags.
Save an XML tree to a file descriptor.
+ int mxmlSaveFd (
+
mxml_node_t *node,
+
int fd,
+
mxml_save_cb_t cb
+
);
0 on success, -1 on error.
+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 before + MXML_TEXT nodes with leading whitespace and before attribute names + inside opening element tags.
+Save an XML tree to a file.
+ int mxmlSaveFile (
+
mxml_node_t *node,
+
FILE *fp,
+
mxml_save_cb_t cb
+
);
0 on success, -1 on error.
+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 before + MXML_TEXT nodes with leading whitespace and before attribute names + inside opening element tags.
+Save an XML node tree to a string.
+ int mxmlSaveString (
+
mxml_node_t *node,
+
char *buffer,
+
int bufsize,
+
mxml_save_cb_t cb
+
);
Size of string
+This function returns the total number of bytes
+ that would be required for the string but only copies (bufsize - 1)
+ characters into the specified buffer.
+
+
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 before
+ MXML_TEXT nodes with leading whitespace and before attribute names
+ inside opening element tags.
Set the element name of a CDATA node.
+ int mxmlSetCDATA (
+
mxml_node_t *node,
+
const char *data
+
);
0 on success, -1 on failure
+The node is not changed if it is not a CDATA + element 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
+
);
0 on success, -1 on failure
+The node is not changed if it is not a custom + node.
+Set the handling functions for custom data.
+ void mxmlSetCustomHandlers (
+
mxml_custom_load_cb_t
+ load,
+
mxml_custom_save_cb_t save
+
);
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 and NULL on error.
Set the name of an element node.
+ int mxmlSetElement (
+
mxml_node_t *node,
+
const char *name
+
);
0 on success, -1 on failure
+The node is not changed if it is not an element + node.
+Set the error message callback.
+ void mxmlSetErrorCallback (
+
mxml_error_cb_t cb
+
);
Set the value of an integer node.
+ int mxmlSetInteger (
+
mxml_node_t *node,
+
int integer
+
);
0 on success, -1 on failure
+The node is not changed if it is not an integer + node.
+Set the value of an opaque node.
+ int mxmlSetOpaque (
+
mxml_node_t *node,
+
const char *opaque
+
);
0 on success, -1 on failure
+The node is not changed if it is not an opaque + node.
+Set the value of a real number node.
+ int mxmlSetReal (
+
mxml_node_t *node,
+
double real
+
);
0 on success, -1 on failure
+The node is not changed if it is not a real number + node.
+Set the value of a text node.
+ int mxmlSetText (
+
mxml_node_t *node,
+
int whitespace,
+
const char *string
+
);
0 on success, -1 on failure
+The node is not changed if it is not a text node.
+Set the value of a text node to a formatted + string.
+ int mxmlSetTextf (
+
mxml_node_t *node,
+
int whitespace,
+
const char *format,
+
...
+
);
0 on success, -1 on failure
+The node is not changed if it is not a text node.
+Set the the wrap margin when saving XML data.
+ void mxmlSetWrapMargin (
+
int column
+
);
Wrapping is disabled when "column" is <= 0.
+Walk to the next logical node in the tree.
+ mxml_node_t *mxmlWalkNext (
+
mxml_node_t *node,
+
mxml_node_t *top,
+
int descend
+
);
Next node or NULL
+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.
+Walk to the previous logical node in the tree.
+ mxml_node_t *mxmlWalkPrev (
+
mxml_node_t *node,
+
mxml_node_t *top,
+
int descend
+
);
Previous node or NULL
+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.
+An XML element attribute value.
+typedef struct mxml_attr_s + mxml_attr_t;
+Custom data destructor
+typedef void (*mxml_custom_destroy_cb_t)(void *);
+Custom data load callback function
+typedef int (*mxml_custom_load_cb_t)( +mxml_node_t *, const char *);
+Custom data save callback function
+typedef char *(*mxml_custom_save_cb_t)( +mxml_node_t *);
+An XML custom value.
+typedef struct mxml_custom_s + mxml_custom_t;
+An XML element value.
+typedef struct mxml_element_s + mxml_element_t;
+Error callback function
+typedef void (*mxml_error_cb_t)(const char *);
+An XML node index.
+typedef struct mxml_index_s + mxml_index_t;
+Load callback function
+typedef mxml_type_t (*mxml_load_cb_t)( +mxml_node_t *);
+An XML node.
+typedef struct mxml_node_s + mxml_node_t;
+Save callback function
+typedef const char *(*mxml_save_cb_t)( +mxml_node_t *, int);
+SAX callback function
+typedef void (*mxml_sax_cb_t)( +mxml_node_t *, mxml_sax_event_t, void *);
+SAX event type.
+typedef enum +mxml_sax_event_e mxml_sax_event_t;
+An XML text value.
+typedef struct mxml_text_s + mxml_text_t;
+An XML node value.
+typedef union mxml_value_u + mxml_value_t;
+An XML element attribute value.
+struct mxml_attr_s {
+
char *name;
+
char *value;
+
};
An XML custom value.
+struct mxml_custom_s {
+
void *data;
+
mxml_custom_destroy_cb_t
+ destroy;
+
};
An XML element value.
+struct mxml_element_s {
+
mxml_attr_t *attrs;
+
char *name;
+
int num_attrs;
+
};
An XML node index.
+struct mxml_index_s {
+
int alloc_nodes;
+
char *attr;
+
int cur_node;
+
mxml_node_t **nodes;
+
int num_nodes;
+
};
An XML node.
+struct mxml_node_s {
+
struct mxml_node_s *child;
+
struct mxml_node_s *last_child;
+
struct mxml_node_s *next;
+
struct mxml_node_s *parent;
+
struct mxml_node_s *prev;
+
int ref_count;
+
mxml_type_t type;
+
void *user_data;
+
mxml_value_t value;
+
};
An XML text value.
+struct mxml_text_s {
+
char *string;
+
int whitespace;
+
};
An XML node value.
+union mxml_value_u {
+
mxml_custom_t custom;
+
mxml_element_t element;
+
int integer;
+
char *opaque;
+
double real;
+
mxml_text_t text;
+
};
SAX event type.
+The XML node type.
+