Definitions

Previous: index ] [ Top: index ] [ Next: Functions except for xml_read ]

I define three basic datastructures for dealing with XML: the element, the attribute, and the element list. Each of these has a struct definition (_element, _attr, and _list respectively) and a pointer typedef (XML, ATTR, and ELEMENTLIST). My apologies that the names don't match up, but it makes sense to me: the struct names reflect a lower-level appreciation for what the objects are, while the typedefs relect a higher-level view of what they're to be used for. Yeah. Anyway, that's my left-brain rationalization for an essentially right-brained nomenclature.
 
typedef struct _element XML;
typedef struct _attr ATTR;
typedef ATTR XML_ATTR;
typedef struct _list ELEMENTLIST;

struct _element {
   char * name;
   ATTR * attrs;
   XML * parent;
   ELEMENTLIST * children;
};

struct _attr {
   char * name;
   char * value;
   ATTR * next;
};

struct _list {
   XML * element;
   ELEMENTLIST * next;
   ELEMENTLIST * prev;
};
Those datastructures suffice to represent an XML file in memory, semi-efficiently (although hash lookup for element and attribute names will be a nice feature at some later date) and completely.

In Windows, the XMLAPI compiles to a DLL (well, optionally). Since you need to specify which functions should be exported from a DLL (that is, visible to linkers), we need to define a special API spec XMLAPI. If told nothing else, we'll assume that the XMLAPI spec should simply be ignored:
 
#ifndef XMLAPI
#define XMLAPI
#endif
But we can define XMLAPI on the compiler's command line to export API functions from the DLL.

Anyway, the XML API itself consists of quite a little list of functions, as follows:
 
XMLAPI void xml_write (FILE * file, XML * xml);
XMLAPI void xml_writecontent (FILE * file, XML * xml);
XMLAPI void xml_writehtml (FILE * file, XML * xml);
XMLAPI void xml_writecontenthtml (FILE * file, XML * xml);
XMLAPI char * xml_string (XML * xml);
XMLAPI char * xml_stringcontent (XML * xml);
XMLAPI char * xml_stringhtml (XML * xml);
XMLAPI char * xml_stringcontenthtml (XML * xml);
XMLAPI void xml_prepend (XML * parent, XML * child);
XMLAPI void xml_append (XML * parent, XML * child);
XMLAPI void xml_replace (XML * xml, XML * newxml);
XMLAPI void xml_replacecontent (XML * parent, XML * child);
XMLAPI XML * xml_loc (XML * start, const char * loc);
XMLAPI XML * xml_locf (XML * start, const char * loc, ...);
XMLAPI void xml_getloc (XML * xml, char *loc, int len);
XMLAPI char * xml_getlocbuf (XML * xml);
XMLAPI void xml_set (XML * xml, const char * name, const char * value);
XMLAPI void xml_setf (XML * xml, const char * name, const char * format, ...);
XMLAPI void xml_setnum (XML * xml, const char *attr, int number);
XMLAPI void xml_set_nodup (XML * xml, const char * name, char * value);
XMLAPI const char * xml_attrval (XML * element,const char * name);
XMLAPI int xml_attrvalnum (XML * element,const char * name);
XMLAPI XML_ATTR * xml_attrfirst (XML * element);
XMLAPI XML_ATTR * xml_attrnext  (XML_ATTR * attr);
XMLAPI const char * xml_attrname (XML_ATTR * attr);
XMLAPI const char * xml_attrvalue (XML_ATTR * attr);
XMLAPI XML * xml_create (const char * name);
XMLAPI XML * xml_createtext (const char * value);
XMLAPI XML * xml_createtextf (const char * format, ...);
XMLAPI XML * xml_createtextlen (const char * value, int len);
XMLAPI void xml_free (XML * xml);
XMLAPI void xml_delete(XML * piece);
XMLAPI XML * xml_first (XML * xml);
XMLAPI XML * xml_firstelem (XML * xml);
XMLAPI XML * xml_last (XML * xml);
XMLAPI XML * xml_lastelem (XML * xml);
XMLAPI XML * xml_next (XML * xml);
XMLAPI XML * xml_nextelem (XML * xml);
XMLAPI XML * xml_prev (XML * xml);
XMLAPI XML * xml_prevelem (XML * xml);
XMLAPI XML * xml_copy (XML * xml);
XMLAPI XML * xml_copyinto (XML * target, XML * source);
XMLAPI XML * xml_read (FILE * file);
XMLAPI XML * xml_read_error (FILE * file);
XMLAPI XML * xml_parse (const char * buf);
Previous: index ] [ Top: index ] [ Next: Functions except for xml_read ]


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