2 This file is part of libXMLRPC - a C library for xml-encoded function calls.
4 Author: Dan Libby (dan@libby.com)
5 Epinions.com may be contacted at feedback@epinions-inc.com
9 Copyright 2000 Epinions, Inc.
11 Subject to the following 3 conditions, Epinions, Inc. permits you, free
12 of charge, to (a) use, copy, distribute, modify, perform and display this
13 software and associated documentation files (the "Software"), and (b)
14 permit others to whom the Software is furnished to do so as well.
16 1) The above copyright notice and this permission notice shall be included
17 without modification in all copies or substantial portions of the
20 2) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF
21 ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY
22 IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 PURPOSE OR NONINFRINGEMENT.
25 3) IN NO EVENT SHALL EPINIONS, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26 SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
27 OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER ARISING, INCLUDING
28 NEGLIGENCE), EVEN IF EPINIONS, INC. IS AWARE OF THE POSSIBILITY OF SUCH
33 #ifndef __XML_ELEMENT_H__
34 #define __XML_ELEMENT_H__
39 #include "simplestring.h"
40 #include "encodings.h"
46 /****d* enum/XML_ELEM_VERBOSITY
50 * verbosity/readability options for generated xml
52 * XML_ELEM_OUTPUT_OPTIONS
55 typedef enum _xml_elem_verbosity {
56 xml_elem_no_white_space, /* compact xml with no white space */
57 xml_elem_newlines_only, /* add newlines for enhanced readability */
58 xml_elem_pretty /* add newlines and indent accordint to depth */
63 /****d* enum/XML_ELEM_ESCAPING
67 * xml escaping options for generated xml
69 * XML_ELEM_OUTPUT_OPTIONS
72 typedef enum _xml_elem_escaping {
73 xml_elem_no_escaping = 0x000,
74 xml_elem_markup_escaping = 0x002, /* entity escape xml special chars */
75 xml_elem_non_ascii_escaping = 0x008, /* entity escape chars above 127 */
76 xml_elem_non_print_escaping = 0x010, /* entity escape non print (illegal) chars */
77 xml_elem_cdata_escaping = 0x020, /* wrap in cdata section */
82 /****s* struct/XML_ELEM_OUTPUT_OPTIONS
84 * XML_ELEM_OUTPUT_OPTIONS
86 * defines various output options
89 typedef struct _xml_output_options {
90 XML_ELEM_VERBOSITY verbosity; /* length/verbosity of xml */
91 XML_ELEM_ESCAPING escaping; /* how to escape special chars */
92 const char* encoding; /* <?xml encoding="<encoding>" ?> */
93 } STRUCT_XML_ELEM_OUTPUT_OPTIONS, *XML_ELEM_OUTPUT_OPTIONS;
96 /****s* struct/XML_ELEM_INPUT_OPTIONS
98 * XML_ELEM_INPUT_OPTIONS
100 * defines various input options
103 typedef struct _xml_input_options {
104 ENCODING_ID encoding; /* which encoding to use. */
105 } STRUCT_XML_ELEM_INPUT_OPTIONS, *XML_ELEM_INPUT_OPTIONS;
108 /****s* struct/XML_ELEM_ERROR
112 * defines an xml parser error
115 typedef struct _xml_elem_error {
117 const char* parser_error;
121 } STRUCT_XML_ELEM_ERROR, *XML_ELEM_ERROR;
125 /*-************************
126 * begin xml element stuff *
127 **************************/
129 /****s* struct/xml_elem_attr
133 * representation of an xml attribute, foo="bar"
136 typedef struct _xml_element_attr {
137 char* key; /* attribute key */
138 char* val; /* attribute value */
142 /****s* struct/xml_elem_attr
146 * representation of an xml element, eg <candidate name="Harry Browne" party="Libertarian"/>
149 typedef struct _xml_element {
150 const char* name; /* element identifier */
151 simplestring text; /* text contained between element begin/end pairs */
152 struct _xml_element* parent; /* element's parent */
154 queue attrs; /* attribute list */
155 queue children; /* child element list */
159 void xml_elem_free(xml_element* root);
160 void xml_elem_free_non_recurse(xml_element* root);
161 xml_element* xml_elem_new(void);
162 char* xml_elem_serialize_to_string(xml_element *el, XML_ELEM_OUTPUT_OPTIONS options, int *buf_len);
163 void xml_elem_serialize_to_stream(xml_element *el, FILE *output, XML_ELEM_OUTPUT_OPTIONS options);
164 xml_element* xml_elem_parse_buf(const char* in_buf, int len, XML_ELEM_INPUT_OPTIONS options, XML_ELEM_ERROR error);
166 /*-**********************
167 * end xml element stuff *
168 ************************/
170 /*-**********************
171 * Begin xml_element API *
172 ************************/
174 /****d* VALUE/XMLRPC_MACROS
176 * Some Helpful Macros
178 * Some macros for making life easier. Should be self-explanatory.
180 * XMLRPC_AddValueToVector ()
181 * XMLRPC_VectorGetValueWithID_Case ()
185 #define xml_elem_next_element(el) ((el) ? (xml_element *)Q_Next(&el->children) : NULL)
186 #define xml_elem_head_element(el) ((el) ? (xml_element *)Q_Head(&el->children) : NULL)
187 #define xml_elem_next_attr(el) ((el) ? (xml_element_attr *)Q_Next(&el->attrs) : NULL)
188 #define xml_elem_head_attr(el) ((el) ? (xml_element_attr *)Q_Head(&el->attrs) : NULL)
189 #define xml_elem_get_name(el) (char *)((el) ? el->name : NULL)
190 #define xml_elem_get_val(el) (char *)((el) ? el->text.str : NULL)
194 /*-********************
195 * End xml_element API *
196 **********************/
202 #endif /* __XML_ELEMENT_H__ */