Back to index

php5  5.3.10
xml_element.h
Go to the documentation of this file.
00001 /*
00002   This file is part of libXMLRPC - a C library for xml-encoded function calls.
00003 
00004   Author: Dan Libby (dan@libby.com)
00005   Epinions.com may be contacted at feedback@epinions-inc.com
00006 */
00007 
00008 /*  
00009   Copyright 2000 Epinions, Inc. 
00010 
00011   Subject to the following 3 conditions, Epinions, Inc.  permits you, free 
00012   of charge, to (a) use, copy, distribute, modify, perform and display this 
00013   software and associated documentation files (the "Software"), and (b) 
00014   permit others to whom the Software is furnished to do so as well.  
00015 
00016   1) The above copyright notice and this permission notice shall be included 
00017   without modification in all copies or substantial portions of the 
00018   Software.  
00019 
00020   2) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF 
00021   ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY 
00022   IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR 
00023   PURPOSE OR NONINFRINGEMENT.  
00024 
00025   3) IN NO EVENT SHALL EPINIONS, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, 
00026   SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT 
00027   OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER ARISING, INCLUDING 
00028   NEGLIGENCE), EVEN IF EPINIONS, INC.  IS AWARE OF THE POSSIBILITY OF SUCH 
00029   DAMAGES.    
00030 
00031 */
00032 
00033 #ifndef __XML_ELEMENT_H__
00034  #define __XML_ELEMENT_H__
00035 
00036 /* includes */
00037 #include <stdio.h>
00038 #include "queue.h"
00039 #include "simplestring.h"
00040 #include "encodings.h"
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 /****d* enum/XML_ELEM_VERBOSITY
00047  * NAME
00048  *   XML_ELEM_VERBOSITY
00049  * NOTES
00050  *   verbosity/readability options for generated xml
00051  * SEE ALSO
00052  *   XML_ELEM_OUTPUT_OPTIONS
00053  * SOURCE
00054  */
00055 typedef enum _xml_elem_verbosity {
00056    xml_elem_no_white_space,    /* compact xml with no white space            */
00057    xml_elem_newlines_only,     /* add newlines for enhanced readability      */
00058    xml_elem_pretty             /* add newlines and indent accordint to depth */
00059 } XML_ELEM_VERBOSITY;
00060 /******/
00061 
00062 
00063 /****d* enum/XML_ELEM_ESCAPING
00064  * NAME
00065  *   XML_ELEM_ESCAPING
00066  * NOTES
00067  * xml escaping options for generated xml
00068  * SEE ALSO
00069  *   XML_ELEM_OUTPUT_OPTIONS
00070  * SOURCE
00071  */
00072 typedef enum _xml_elem_escaping {
00073    xml_elem_no_escaping             = 0x000,
00074    xml_elem_markup_escaping         = 0x002,   /* entity escape xml special chars         */
00075    xml_elem_non_ascii_escaping      = 0x008,   /* entity escape chars above 127           */
00076    xml_elem_non_print_escaping      = 0x010,   /* entity escape non print (illegal) chars */
00077    xml_elem_cdata_escaping          = 0x020,   /* wrap in cdata section                   */
00078 } XML_ELEM_ESCAPING;
00079 /******/
00080 
00081 
00082 /****s* struct/XML_ELEM_OUTPUT_OPTIONS
00083  * NAME
00084  *   XML_ELEM_OUTPUT_OPTIONS
00085  * NOTES
00086  *   defines various output options
00087  * SOURCE
00088  */
00089 typedef struct _xml_output_options {
00090    XML_ELEM_VERBOSITY           verbosity;      /* length/verbosity of xml        */
00091    XML_ELEM_ESCAPING            escaping;       /* how to escape special chars    */
00092    const char*                  encoding;       /* <?xml encoding="<encoding>" ?> */
00093 } STRUCT_XML_ELEM_OUTPUT_OPTIONS, *XML_ELEM_OUTPUT_OPTIONS;
00094 /******/
00095 
00096 /****s* struct/XML_ELEM_INPUT_OPTIONS
00097  * NAME
00098  *   XML_ELEM_INPUT_OPTIONS
00099  * NOTES
00100  *   defines various input options
00101  * SOURCE
00102  */
00103 typedef struct _xml_input_options {
00104   ENCODING_ID                  encoding;       /* which encoding to use.       */
00105 } STRUCT_XML_ELEM_INPUT_OPTIONS, *XML_ELEM_INPUT_OPTIONS;
00106 /******/
00107 
00108 /****s* struct/XML_ELEM_ERROR
00109  * NAME
00110  *   XML_ELEM_ERROR
00111  * NOTES
00112  *   defines an xml parser error
00113  * SOURCE
00114  */
00115 typedef struct _xml_elem_error {
00116   int parser_code;
00117   const char* parser_error;
00118   long line;
00119   long column;
00120   long byte_index;
00121 } STRUCT_XML_ELEM_ERROR, *XML_ELEM_ERROR;
00122 /******/
00123 
00124 
00125 /*-************************
00126 * begin xml element stuff *
00127 **************************/
00128 
00129 /****s* struct/xml_elem_attr
00130  * NAME
00131  *  xml_elem_attr
00132  * NOTES
00133  *   representation of an xml attribute, foo="bar"
00134  * SOURCE
00135  */
00136 typedef struct _xml_element_attr {
00137    char* key;        /* attribute key   */
00138    char* val;        /* attribute value */
00139 } xml_element_attr;
00140 /******/
00141 
00142 /****s* struct/xml_elem_attr
00143  * NAME
00144  *  xml_elem_attr
00145  * NOTES
00146  *   representation of an xml element, eg <candidate name="Harry Browne" party="Libertarian"/>
00147  * SOURCE
00148  */
00149 typedef struct _xml_element {
00150    const char*   name;           /* element identifier */
00151    simplestring  text;           /* text contained between element begin/end pairs */
00152    struct _xml_element* parent;  /* element's parent */
00153                                  
00154    queue        attrs;           /* attribute list */
00155    queue        children;        /* child element list */
00156 } xml_element;
00157 /******/
00158 
00159 void xml_elem_free(xml_element* root);
00160 void xml_elem_free_non_recurse(xml_element* root);
00161 xml_element* xml_elem_new(void);
00162 char* xml_elem_serialize_to_string(xml_element *el, XML_ELEM_OUTPUT_OPTIONS options, int *buf_len);
00163 void xml_elem_serialize_to_stream(xml_element *el, FILE *output, XML_ELEM_OUTPUT_OPTIONS options);
00164 xml_element* xml_elem_parse_buf(const char* in_buf, int len, XML_ELEM_INPUT_OPTIONS options, XML_ELEM_ERROR error);
00165 
00166 /*-**********************
00167 * end xml element stuff *
00168 ************************/
00169 
00170 /*-**********************
00171 * Begin xml_element API *
00172 ************************/
00173 
00174 /****d* VALUE/XMLRPC_MACROS
00175  * NAME
00176  *   Some Helpful Macros
00177  * NOTES
00178  *   Some macros for making life easier.  Should be self-explanatory.
00179  * SEE ALSO
00180  *   XMLRPC_AddValueToVector ()
00181  *   XMLRPC_VectorGetValueWithID_Case ()
00182  *   XMLRPC_VALUE
00183  * SOURCE
00184  */
00185 #define xml_elem_next_element(el) ((el) ? (xml_element *)Q_Next(&el->children) : NULL)
00186 #define xml_elem_head_element(el) ((el) ? (xml_element *)Q_Head(&el->children) : NULL)
00187 #define xml_elem_next_attr(el) ((el) ? (xml_element_attr *)Q_Next(&el->attrs) : NULL)
00188 #define xml_elem_head_attr(el) ((el) ? (xml_element_attr *)Q_Head(&el->attrs) : NULL)
00189 #define xml_elem_get_name(el) (char *)((el) ? el->name : NULL)
00190 #define xml_elem_get_val(el) (char *)((el) ? el->text.str : NULL)
00191 /******/
00192 
00193 
00194 /*-********************
00195 * End xml_element API *
00196 **********************/
00197 
00198 #ifdef __cplusplus
00199 }
00200 #endif
00201 
00202 #endif /* __XML_ELEMENT_H__ */