Functions except for xml_read

Previous: Definitions ] [ Top: index ] [ Next: xml_write: Writing XML data to disk ]

So here's my budding XML manipulation API. First, the include files, then a list of pieces of code (defined on other pages) which get pulled in to build the source file.

July 18, 2001: Note that I'm getting more agnostic about the memory allocation used by XMLAPI; originally, of course, it was exclusively malloc-based, but with the Python wrapper I decided it was time to allow the compiler to specify variants.

Also for the Python wrapper, I'm not including any reference to the external expat library; these functions will be reimplemented on the pyexpat module instead, in native Python. This avoids a double linkage, as Python already includes its own version of expat.

These changes haven't been tested yet, or incorporated into the Python wrapper, so don't get too bent out of shape if they don't work.
 
#include <stdio.h>

#ifdef PYTHON
#define XMLAPI_MALLOC_PYTHON
#undef XMLAPI_MALLOC_NATIVE
#endif

#ifndef XMLAPI_MALLOC_NATIVE
#define XMLAPI_MALLOC_NATIVE
#endif

#ifdef XMLAPI_MALLOC_NATIVE
#include <malloc.h>
#define MALLOC(x) malloc(x)
#define REALLOC(x,y) realloc((x),(y))
#define FREE(x) free(x)
#endif

#ifdef XMLAPI_MALLOC_PYTHON
#include <python.h>
#define MALLOC(x) PyMem_Malloc(x)
#define REALLOC(x,y) PyMem_Realloc((x),(y))
#define FREE(x,y) PyMem_Free(x)
#endif

#include <string.h>
#include <stdlib.h>
#include <stdarg.h>




#ifndef PYTHON
#include <expat.h>
#endif

#include "xmlapi.h"

/* Note to self: put these *after* xmlapi.h... (What was I thinking?) */
XMLAPI char * xml_strdup (const char * str)
{
   char * ret;

   ret = MALLOC (strlen (str) + 1);
   strcpy (ret, str);
   return (ret);
}
XMLAPI void xml_strfree (char * str)
{
   free (str);
}
See xml_string: Writing XML data to strings in memory

See xml_create: Creating an empty element
See Working with attributes: xml_set and xml_attrval
See xml_prepend: Inserting elements
See xml_append: Inserting elements
See xml_replace and xml_replacecontent: Replacing an element with another.
See inserting things: xml_insertbefore and xml_insertafter
See xml_createtext: a shortcut for plain text
See xml_write: Writing XML data to disk
See xml_free: Cleaning up afterwards
See Deleting pieces: xml_delete
See Children: xml_first and xml_last
See Siblings: xml_next and xml_prev
See Bookmarking things: xml_loc and xml_getloc
#ifndef PYTHON
See xml_read: Using expat to parse XML files into memory
#endif
See xml_copy: making fresh copies of XML
See xml_attr*: Working with attributes
See xml_is: Checking an object's name
See xml_search: Searching trees for elements
See xml_charcodings: dealing with UTF-8 and systems that don't quite get it
See xml_sort: Sorting children
See xml_assemble: Putting together SOAP responses
Previous: Definitions ] [ Top: index ] [ Next: xml_write: Writing XML data to disk ]


This code and documentation are released under the terms of the GNU license. They are copyright (c) 2000-2003, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license. This presentation was created using LPML.