/***************************************************************************** * * FILE: sxml.h * DESCRIPTION: Skimpy XML Parser/Grafter header file * DATE: Wed, Sep 8 2004 * UPDATED: Fri, Aug 31 2007 * AUTHOR: Kouichi ABE (WALL) / °¤Éô¹¯°ì * E-MAIL: kouichi@MysticWALL.COM * URL: http://www.MysticWALL.COM/ * COPYRIGHT: (c) 2004-2007 °¤Éô¹¯°ì¡¿Kouichi ABE (WALL), All rights reserved. * LICENSE: * * Copyright (c) 2004-2007 Kouichi ABE (WALL) , * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: sxml.h,v 1.20 2007/08/31 09:57:44 kouichi Exp $ * *****************************************************************************/ #ifndef _SXML_H #define _SXML_H #include #include /****************************************************************************** * * Macros and structures definition * *****************************************************************************/ /* * Numeric release version identifier: * MNNFFPPS: major minor fix patch status * The status nibble has one of the values 0 for development, * 1 to e for betas 1 to 14, and f for release. * The patch level is exactly that. */ #define SXML_VERSION_NUMBER 0x10005000L #define SXML_VERSION "SXML/1.0.5" #define SXML_VERSION_TEXT SXML_VERSION " (2007/08/31)" #define SXML_VERSION_TEXT_LONG "Skimpy XML Library 1.0.5, Fri, Aug 31 2007" typedef enum { /* XML node type */ SXML_VERTEX, /* root node */ SXML_PROLOG, /* XML prolog */ SXML_ELEMENT, /* XML element with attributes */ SXML_CONTENT /* content of element */ } sxml_type_t; typedef struct _sxml_attr { /* XML element attribute */ const char * name; const char * value; struct _sxml_attr * next; } sxml_attr_t; typedef struct { /* XML element */ const char * name; /* name of element */ sxml_attr_t * attrs; /* attributes */ } sxml_element_t; typedef union { /* XML value union */ sxml_element_t element; /* element */ const char * content; /* content */ } sxml_value_t; typedef struct _sxml_node { /* XML node structure */ struct _sxml_node * parent; /* parent node */ struct _sxml_node * child; /* first child node */ struct _sxml_node * last_child; /* last child node (role of sentry) */ struct _sxml_node * next; /* next node under same parent */ struct _sxml_node * prev; /* previous node under same parent */ sxml_type_t type; /* node type */ sxml_value_t value; /* node value */ } sxml_node_t; /*****************************************************************************/ #define sxml_get_type(x) ((x)->type) #define sxml_get_child(x) ((x)->child) #define sxml_get_next_sibling(x) ((x)->next) #define sxml_get_prev_sibling(x) ((x)->prev) #define sxml_get_element_name(x) ((x)->value.element.name) /****************************************************************************** * * Global functions declaration * *****************************************************************************/ /* parse */ sxml_node_t * sxml_parse_file(int fd); void sxml_delete_node(sxml_node_t * node); sxml_node_t * sxml_find_prolog(sxml_node_t * node, const char * name); sxml_node_t * sxml_find_element(sxml_node_t * node, const char * name, const char * attr, const char * value); const char * sxml_get_attribute(sxml_node_t * node, const char * name); const char * sxml_get_content(sxml_node_t * node); /* print */ void sxml_print_tree(sxml_node_t * node, FILE * fout); void sxml_print_node(sxml_node_t * node, FILE * fout); /* graft */ sxml_node_t * sxml_new_vertex(void); sxml_node_t * sxml_new_prolog(sxml_node_t * parent, const char * name); sxml_node_t * sxml_new_element(sxml_node_t * parent, const char * name); sxml_node_t * sxml_set_content(sxml_node_t * element, const char * content); int sxml_set_attribute(sxml_node_t * node, const char * name, const char * value); int sxml_set_fattribute(sxml_node_t * node, const char * name, const char * fmt, ...); sxml_node_t * sxml_set_node(sxml_node_t * node, const char * name, const char * content); sxml_node_t * sxml_set_fnode(sxml_node_t * node, const char * name, const char * fmt, ...); #endif /* _SXML_H */