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

Implemment getters for all of mxml_node_t and mxml_index_t fields (STR #118)

Make mxml_node_s and mxml_index_s private (but still in the public header for
2.x).
parent 1a660a57
CHANGES - 2010-11-08
CHANGES - 2011-01-01
--------------------
CHANGES IN Mini-XML 2.7
- Added data accessor ("get") functions and made the mxml_node_t and
mxml_index_t structures private but still available in the Mini-XML
header to preserve source compatibility (STR #118)
- Updated the source headers to reference the Mini-XML license and its
exceptions to the LGPL2 (STR #108)
- Added a new mxmlFindValue() function to find the value node of a
......
......@@ -82,8 +82,8 @@ DOCFILES = doc/0.gif doc/1.gif doc/2.gif doc/3.gif doc/4.gif \
doc/A.gif doc/B.gif doc/C.gif doc/D.gif \
doc/mxml.html doc/mxmldoc.xsd \
README COPYING CHANGES
PUBLIBOBJS = mxml-attr.o mxml-entity.o mxml-file.o mxml-index.o \
mxml-node.o mxml-search.o mxml-set.o
PUBLIBOBJS = mxml-attr.o mxml-entity.o mxml-file.o mxml-get.o \
mxml-index.o mxml-node.o mxml-search.o mxml-set.o
LIBOBJS = $(PUBLIBOBJS) mxml-private.o mxml-string.o
OBJS = mxmldoc.o testmxml.o $(LIBOBJS)
TARGETS = $(LIBMXML) mxmldoc testmxml mxml.xml doc/mxml.man
......
<html>
<head>
<title>Mini-XML Programmers Manual, Version 2.7</title>
<meta name="copyright" content="Copyright 2003-2010">
<meta name="copyright" content="Copyright 2003-2011">
<meta name="author" content="Michael R. Sweet">
<meta name="keywords" content="XML, C, C++, library">
</head>
......@@ -188,7 +188,7 @@ manual:</p>
<!-- NEED 6 -->
<h2>Legal Stuff</h2>
<p>The Mini-XML library is copyright 2003-2010 by Michael Sweet. License terms
<p>The Mini-XML library is copyright 2003-2011 by Michael Sweet. License terms
are described in <a href="#LICENSE">Appendix A - Mini-XML License</a>.</p>
</body>
......
This diff is collapsed.
This diff is collapsed.
......@@ -3,7 +3,7 @@
<head>
<title>Mini-XML Programmers Manual</title>
<meta name="author" content="Michael R Sweet">
<meta name="copyright" content="Copyright 2003-2010">
<meta name="copyright" content="Copyright 2003-2011">
</head>
<body>
......@@ -11,7 +11,7 @@
<tr><td height="100%">
<H1 ALIGN="CENTER"><FONT SIZE="-1">Mini-XML Programmers Manual<br>
Version 2.6</H1>
Version 2.7</H1>
<P ALIGN="CENTER">MICHAEL R. SWEET</P>
......@@ -21,7 +21,7 @@ Version 2.6</H1>
<!-- NEW PAGE -->
<P><FONT SIZE="+1"><B>Mini-XML Programmers Manual, Version 2.7</B></FONT></P>
<P><B>Copyright &copy; 2003-2010 by Michael R. Sweet</B></P>
<P><B>Copyright &copy; 2003-2011 by Michael R. Sweet</B></P>
<P><SMALL>Permission is granted to copy, distribute and/or modify
this document under the terms of the GNU Library General Public
......
/*
* "$Id$"
*
* Node get functions for Mini-XML, a small XML-like file parsing library.
*
* Copyright 2011 by Michael R Sweet.
*
* These coded instructions, statements, and computer programs are the
* property of Michael R Sweet and are protected by Federal copyright
* law. Distribution and use rights are outlined in the file "COPYING"
* which should have been included with this file. If this file is
* missing or damaged, see the license at:
*
* http://www.minixml.org/
*
* Contents:
*
* mxmlGetCDATA() - Get the value for a CDATA node.
* mxmlGetCustom() - Get the value for a custom node.
* mxmlGetElement() - Get the name for an element node.
* mxmlGetFirstChild() - Get the first child of an element node.
* mxmlGetInteger() - Get the integer value from the specified node or its
* first child.
* mxmlGetLastChild() - Get the last child of an element node.
* mxmlGetNext() - Get the next node for the current parent.
* mxmlGetOpaque() - Get an opaque string value for a node or its first
* child.
* mxmlGetParent() - Get the parent node.
* mxmlGetPrevious() - Get the previous node for the current parent.
* mxmlGetReal() - Get the real value for a node or its first child.
* mxmlGetText() - Get the text value for a node or its first child.
* mxmlGetType() - Get the node type.
* mxmlGetUserData() - Get the user data pointer for a node.
*/
/*
* Include necessary headers...
*/
#include "config.h"
#include "mxml.h"
/*
* 'mxmlGetCDATA()' - Get the value for a CDATA node.
*
* @code NULL@ is returned if the node is not a CDATA element.
*
* @since Mini-XML 2.7@
*/
char * /* O - CDATA value or NULL */
mxmlGetCDATA(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT ||
strncmp(node->value.element.name, "![CDATA[", 8))
return (NULL);
/*
* Return the text following the CDATA declaration...
*/
return (node->value.element.name + 8);
}
/*
* 'mxmlGetCustom()' - Get the value for a custom node.
*
* @code NULL@ is returned if the node (or its first child) is not a custom
* value node.
*
* @since Mini-XML 2.7@
*/
void * /* O - Custom value or NULL */
mxmlGetCustom(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (NULL);
/*
* Return the integer value...
*/
if (node->type == MXML_CUSTOM)
return (node->value.custom.data);
else if (node->type == MXML_ELEMENT &&
node->child &&
node->child->type == MXML_CUSTOM)
return (node->child->value.custom.data);
else
return (NULL);
}
/*
* 'mxmlGetElement()' - Get the name for an element node.
*
* @code NULL@ is returned if the node is not an element node.
*
* @since Mini-XML 2.7@
*/
char * /* O - Element name or NULL */
mxmlGetElement(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT)
return (NULL);
/*
* Return the element name...
*/
return (node->value.element.name);
}
/*
* 'mxmlGetFirstChild()' - Get the first child of an element node.
*
* @code NULL@ is returned if the node is not an element node or if the node
* has no children.
*
* @since Mini-XML 2.7@
*/
mxml_node_t * /* O - First child or NULL */
mxmlGetFirstChild(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT)
return (NULL);
/*
* Return the first child node...
*/
return (node->child);
}
/*
* 'mxmlGetInteger()' - Get the integer value from the specified node or its
* first child.
*
* 0 is returned if the node (or its first child) is not an integer value node.
*
* @since Mini-XML 2.7@
*/
int /* O - Integer value or 0 */
mxmlGetInteger(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (0);
/*
* Return the integer value...
*/
if (node->type == MXML_INTEGER)
return (node->value.integer);
else if (node->type == MXML_ELEMENT &&
node->child &&
node->child->type == MXML_INTEGER)
return (node->child->value.integer);
else
return (0);
}
/*
* 'mxmlGetLastChild()' - Get the last child of an element node.
*
* @code NULL@ is returned if the node is not an element node or if the node
* has no children.
*
* @since Mini-XML 2.7@
*/
mxml_node_t * /* O - Last child or NULL */
mxmlGetLastChild(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT)
return (NULL);
/*
* Return the node type...
*/
return (node->last_child);
}
/*
* 'mxmlGetNext()' - Get the next node for the current parent.
*
* @code NULL@ is returned if this is the last child for the current parent.
*
* @since Mini-XML 2.7@
*/
mxml_node_t *
mxmlGetNext(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (NULL);
/*
* Return the node type...
*/
return (node->next);
}
/*
* 'mxmlGetOpaque()' - Get an opaque string value for a node or its first child.
*
* @code NULL@ is returned if the node (or its first child) is not an opaque
* value node.
*
* @since Mini-XML 2.7@
*/
char * /* O - Opaque string or NULL */
mxmlGetOpaque(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (NULL);
/*
* Return the integer value...
*/
if (node->type == MXML_OPAQUE)
return (node->value.opaque);
else if (node->type == MXML_ELEMENT &&
node->child &&
node->child->type == MXML_OPAQUE)
return (node->child->value.opaque);
else
return (NULL);
}
/*
* 'mxmlGetParent()' - Get the parent node.
*
* @code NULL@ is returned for a root node.
*
* @since Mini-XML 2.7@
*/
mxml_node_t * /* O - Parent node or NULL */
mxmlGetParent(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (NULL);
/*
* Return the node type...
*/
return (node->parent);
}
/*
* 'mxmlGetPrevious()' - Get the previous node for the current parent.
*
* @code NULL@ is returned if this is the first child for the current parent.
*
* @since Mini-XML 2.7@
*/
mxml_node_t * /* O - Previous node or NULL */
mxmlGetPrevious(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (NULL);
/*
* Return the node type...
*/
return (node->prev);
}
/*
* 'mxmlGetReal()' - Get the real value for a node or its first child.
*
* 0.0 is returned if the node (or its first child) is not a real value node.
*
* @since Mini-XML 2.7@
*/
double /* O - Real value or 0.0 */
mxmlGetReal(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (0.0);
/*
* Return the integer value...
*/
if (node->type == MXML_REAL)
return (node->value.real);
else if (node->type == MXML_ELEMENT &&
node->child &&
node->child->type == MXML_REAL)
return (node->child->value.real);
else
return (0.0);
}
/*
* 'mxmlGetText()' - Get the text value for a node or its first child.
*
* @code NULL@ is returned if the node (or its first child) is not a text node.
* The "whitespace" argument can be NULL.
*
* @since Mini-XML 2.7@
*/
char * /* O - Text string or NULL */
mxmlGetText(mxml_node_t *node, /* I - Node to get */
int *whitespace) /* O - 1 if string is preceded by whitespace, 0 otherwise */
{
/*
* Range check input...
*/
if (!node)
{
if (whitespace)
*whitespace = 0;
return (NULL);
}
/*
* Return the integer value...
*/
if (node->type == MXML_TEXT)
{
if (whitespace)
*whitespace = node->value.text.whitespace;
return (node->value.text.string);
}
else if (node->type == MXML_ELEMENT &&
node->child &&
node->child->type == MXML_TEXT)
{
if (whitespace)
*whitespace = node->child->value.text.whitespace;
return (node->child->value.text.string);
}
else
{
if (whitespace)
*whitespace = 0;
return (NULL);
}
}
/*
* 'mxmlGetType()' - Get the node type.
*
* @code MXML_IGNORE@ is returned if "node" is @code NULL@.
*
* @since Mini-XML 2.7@
*/
mxml_type_t /* O - Type of node */
mxmlGetType(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (MXML_IGNORE);
/*
* Return the node type...
*/
return (node->type);
}
/*
* 'mxmlGetUserData()' - Get the user data pointer for a node.
*
* @since Mini-XML 2.7@
*/
void * /* O - User data pointer */
mxmlGetUserData(mxml_node_t *node) /* I - Node to get */
{
/*
* Range check input...
*/
if (!node)
return (NULL);
/*
* Return the user data pointer...
*/
return (node->user_data);
}
/*
* End of "$Id$".
*/
......@@ -3,7 +3,7 @@
*
* Index support code for Mini-XML, a small XML-like file parsing library.
*
* Copyright 2003-2010 by Michael R Sweet.
* Copyright 2003-2011 by Michael R Sweet.
*
* These coded instructions, statements, and computer programs are the
* property of Michael R Sweet and are protected by Federal copyright
......@@ -15,15 +15,6 @@
*
* Contents:
*
* mxmlIndexDelete() - Delete an index.
* mxmlIndexEnum() - Return the next node in the index.
* mxmlIndexFind() - Find the next matching node.
* mxmlIndexNew() - Create a new index.
* mxmlIndexReset() - Reset the enumeration/find pointer in the index and
* return the first node in the index.
* index_compare() - Compare two nodes.
* index_find() - Compare a node with index values.
* index_sort() - Sort the nodes in the index...
*/
/*
......@@ -282,6 +273,30 @@ mxmlIndexFind(mxml_index_t *ind, /* I - Index to search */
}
/*
* 'mxmlIndexGetCount()' - Get the number of nodes in an index.
*
* @since Mini-XML 2.7@
*/
int /* I - Number of nodes in index */
mxmlIndexGetCount(mxml_index_t *ind) /* I - Index of nodes */
{
/*
* Range check input...
*/
if (!ind)
return (0);
/*
* Return the number of nodes in the index...
*/
return (ind->num_nodes);
}
/*
* 'mxmlIndexNew()' - Create a new index.
*
......
......@@ -3,7 +3,7 @@
*
* Node set functions for Mini-XML, a small XML-like file parsing library.
*
* Copyright 2003-2010 by Michael R Sweet.
* Copyright 2003-2011 by Michael R Sweet.
*
* These coded instructions, statements, and computer programs are the
* property of Michael R Sweet and are protected by Federal copyright
......@@ -15,14 +15,15 @@
*
* Contents:
*
* mxmlSetCustom() - Set the data and destructor of a custom data node.
* mxmlSetCDATA() - Set the element name of a CDATA node.
* mxmlSetElement() - Set the name of an element node.
* mxmlSetInteger() - Set the value of an integer node.
* mxmlSetOpaque() - Set the value of an opaque node.
* mxmlSetReal() - Set the value of a real number node.
* mxmlSetText() - Set the value of a text node.
* mxmlSetTextf() - Set the value of a text node to a formatted string.
* mxmlSetCDATA() - Set the element name of a CDATA node.
* mxmlSetCustom() - Set the data and destructor of a custom data node.
* mxmlSetElement() - Set the name of an element node.
* mxmlSetInteger() - Set the value of an integer node.
* mxmlSetOpaque() - Set the value of an opaque node.
* mxmlSetReal() - Set the value of a real number node.
* mxmlSetText() - Set the value of a text node.
* mxmlSetTextf() - Set the value of a text node to a formatted string.
* mxmlSetUserData() - Set the user data pointer for a node.
*/
/*
......@@ -34,68 +35,68 @@
/*
* 'mxmlSetCustom()' - Set the data and destructor of a custom data node.
* 'mxmlSetCDATA()' - Set the element name of a CDATA node.
*
* The node is not changed if it is not a custom node.
* The node is not changed if it is not a CDATA element node.
*
* @since Mini-XML 2.1@
* @since Mini-XML 2.3@
*/
int /* O - 0 on success, -1 on failure */
mxmlSetCustom(
mxml_node_t *node, /* I - Node to set */
void *data, /* I - New data pointer */
mxml_custom_destroy_cb_t destroy) /* I - New destructor function */
mxmlSetCDATA(mxml_node_t *node, /* I - Node to set */
const char *data) /* I - New data string */
{
/*
* Range check input...
*/
if (!node || node->type != MXML_CUSTOM)
if (!node || node->type != MXML_ELEMENT || !data ||
strncmp(node->value.element.name, "![CDATA[", 8))
return (-1);
/*
* Free any old element value and set the new value...
*/
if (node->value.custom.data && node->value.custom.destroy)
(*(node->value.custom.destroy))(node->value.custom.data);
if (node->value.element.name)
free(node->value.element.name);
node->value.custom.data = data;
node->value.custom.destroy = destroy;
node->value.element.name = _mxml_strdupf("![CDATA[%s]]", data);
return (0);
}
/*
* 'mxmlSetCDATA()' - Set the element name of a CDATA node.
* 'mxmlSetCustom()' - Set the data and destructor of a custom data node.
*
* The node is not changed if it is not a CDATA element node.
* The node is not changed if it is not a custom node.
*
* @since Mini-XML 2.3@
* @since Mini-XML 2.1@
*/
int /* O - 0 on success, -1 on failure */
mxmlSetCDATA(mxml_node_t *node, /* I - Node to set */
const char *data) /* I - New data string */
mxmlSetCustom(
mxml_node_t *node, /* I - Node to set */
void *data, /* I - New data pointer */
mxml_custom_destroy_cb_t destroy) /* I - New destructor function */
{
/*
* Range check input...
*/
if (!node || node->type != MXML_ELEMENT || !data ||
strncmp(node->value.element.name, "![CDATA[", 8))
if (!node || node->type != MXML_CUSTOM)
return (-1);
/*
* Free any old element value and set the new value...
*/
if (node->value.element.name)
free(node->value.element.name);
if (node->value.custom.data && node->value.custom.destroy)
(*(node->value.custom.destroy))(node->value.custom.data);
node->value.element.name = _mxml_strdupf("![CDATA[%s]]", data);
node->value.custom.data = data;
node->value.custom.destroy = destroy;
return (0);
}
......@@ -287,6 +288,32 @@ mxmlSetTextf(mxml_node_t *node, /* I - Node to set */
}
/*
* 'mxmlSetUserData()' - Set the user data pointer for a node.
*
* @since Mini-XML 2.7@
*/
int /* O - 0 on success, -1 on failure */
mxmlSetUserData(mxml_node_t *node, /* I - Node to set */
void *data) /* I - User data pointer */
{
/*
* Range check input...
*/
if (!node)
return (-1);
/*
* Set the user data pointer and return...
*/
node->user_data = data;
return (0);
}
/*
* End of "$Id$".
*/
......@@ -3,7 +3,7 @@
*
* Header file for Mini-XML, a small XML-like file parsing library.
*
* Copyright 2003-2010 by Michael R Sweet.
* Copyright 2003-2011 by Michael R Sweet.
*
* These coded instructions, statements, and computer programs are the
* property of Michael R Sweet and are protected by Federal copyright
......@@ -96,32 +96,32 @@ typedef void (*mxml_custom_destroy_cb_t)(void *);
typedef void (*mxml_error_cb_t)(const char *);
/**** Error callback function ****/
typedef struct mxml_attr_s /**** An XML element attribute value. ****/
typedef struct mxml_attr_s /**** An XML element attribute value. @private@ ****/
{
char *name; /* Attribute name */
char *value; /* Attribute value */
} mxml_attr_t;
typedef struct mxml_element_s /**** An XML element value. ****/
typedef struct mxml_element_s /**** An XML element value. @private@ ****/
{
char *name; /* Name of element */
int num_attrs; /* Number of attributes */
mxml_attr_t *attrs; /* Attributes */
} mxml_element_t;