Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

xmlt.h

Go to the documentation of this file.
00001 /*
00002  *  xmlt.h - XML data structure.
00003  *           This file is part of the FreeLCD package.
00004  *
00005  *  $Id: xmlt_8h-source.html,v 1.1 2003/02/16 22:50:41 unicorn Exp $
00006  *
00007  *  This program is free software; you can redistribute it and/or modify it
00008  *  under the terms of the GNU General Public License as published by the
00009  *  Free Software Foundation; either version 2 of the License, or (at your
00010  *  option) any later version.
00011  * 
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00020  *  MA  02111-1307  USA
00021  *
00022  *  Copyright (c) 2002, 2003, Jeroen van den Berg <unicorn@hippie.nu>
00023  */
00024 
00028 
00029 #ifndef _XMLT_H
00030 #define _XMLT_H
00031 
00032 #include "slist.h"
00033 #include "dictionary.h"
00034 
00037 #define XML_UNKNOWN_TAG -1
00038 
00041 #define XML_UNKNOWN_ATTRIBUTE -1
00042 
00048 typedef struct
00049 {
00050   int attribute; 
00051   char *value; 
00052   char *unknown_attrib; 
00053 }
00054 xml_attribute;
00055 
00057 typedef enum
00058 {
00059   NODE, CDATA
00060 }
00061 xml_node_t;
00062 
00063 /* This struct represents a tag or character data in the XML document.
00064  * The exact behavior depends on the \a type field. If this is a NODE,
00065  * it represents a tag. A tag that can be translated with a dictionary
00066  * is stored by its respective integer value. If the tag was not found,
00067  * \a type is \ref XML_UNKNOWN_TAG, and the literal tag is stored in
00068  * \a cdata. If \a type is CDATA, all fields except for \a cdata and
00069  * \a parent lose their meaning.
00070  */
00071 typedef struct _xml_node
00072 {
00073   xml_node_t type; 
00074   int tag; 
00076   struct _xml_node *parent;
00077   slist attributes; 
00078   slist children; 
00079   char *cdata; 
00080 }
00081 xml_node;
00082 
00098 void *
00099 xmlt_create_context (void (*callback) (void *, xml_node *),
00100                      void *cb_data,
00101                      dictionary *tags, dictionary *attribs);
00102 
00109 int 
00110 xmlt_parse (void *context, const char *data, size_t len);
00111 
00115 void 
00116 xmlt_free_context (void *context);
00117 
00120 void 
00121 xmlt_free_document (xml_node *doc);
00122 
00128 void
00129 xmlt_rescan_document (xml_node *doc, dictionary *tags, dictionary *attribs);
00130 
00135 xml_node *
00136 xmlt_get_next (xml_node *iter, xml_node *doc);
00137 
00142 xml_node *
00143 xmlt_get_next_shallow (xml_node *iter);
00144 
00145 /* Find the first occurrence of a certain tag, starting right after the
00146  * given iterator, or at the first child of the document node if this
00147  * iterator is NULL. Searching is not done in depth.
00148  */
00149 xml_node *
00150 xmlt_find (xml_node *doc, xml_node *iter, int tag);
00151 
00152 /*  Same as xmlt_find, but with a customizable compare function */
00153 xml_node *
00154 xmlt_find_if (xml_node *doc, xml_node *iter, int(*compare)(xml_node*));
00155 
00156 /*  Get the contents of a node's attribute. Returns 0 if the attribute
00157  *  does not exist.
00158  */
00159 const char *
00160 xmlt_get_attrib (xml_node *node, int attribute);
00161 
00162 /* Get the first character data beneath a given node */
00163 const char *
00164 xmlt_get_first_cdata (xml_node *node);
00165 
00166 /*  Call the given function with a given pointer and every node in the 
00167  *  document 
00168  */
00169 void
00170 xmlt_for_each (xml_node *doc, void *user_data,
00171                void (*func) (void *, xml_node *));
00172 
00173 #endif /* Multiple include guard */

Generated on Sun Feb 16 23:39:49 2003 for FreeLCD by doxygen1.2.18