include/apr_xml.h

Go to the documentation of this file.
00001 /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
00002  * applicable.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00020 #ifndef APR_XML_H
00021 #define APR_XML_H
00022 
00028 #include "apr_pools.h"
00029 #include "apr_tables.h"
00030 #include "apr_file_io.h"
00031 
00032 #include "apu.h"
00033 
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif
00037 
00042 /* -------------------------------------------------------------------- */
00043 
00044 /* ### these will need to move at some point to a more logical spot */
00045 
00047 typedef struct apr_text apr_text;
00048 
00050 struct apr_text {
00052     const char *text;
00054     struct apr_text *next;
00055 };
00056 
00058 typedef struct apr_text_header apr_text_header;
00059 
00061 struct apr_text_header {
00063     apr_text *first;
00065     apr_text *last;
00066 };
00067 
00074 APU_DECLARE(void) apr_text_append(apr_pool_t *p, apr_text_header *hdr,
00075                                   const char *text);
00076 
00077 
00078 /* --------------------------------------------------------------------
00079 **
00080 ** XML PARSING
00081 */
00082 
00083 /*
00084 ** Qualified namespace values
00085 **
00086 ** APR_XML_NS_DAV_ID
00087 **    We always insert the "DAV:" namespace URI at the head of the
00088 **    namespace array. This means that it will always be at ID==0,
00089 **    making it much easier to test for.
00090 **
00091 ** APR_XML_NS_NONE
00092 **    This special ID is used for two situations:
00093 **
00094 **    1) The namespace prefix begins with "xml" (and we do not know
00095 **       what it means). Namespace prefixes with "xml" (any case) as
00096 **       their first three characters are reserved by the XML Namespaces
00097 **       specification for future use. mod_dav will pass these through
00098 **       unchanged. When this identifier is used, the prefix is LEFT in
00099 **       the element/attribute name. Downstream processing should not
00100 **       prepend another prefix.
00101 **
00102 **    2) The element/attribute does not have a namespace.
00103 **
00104 **       a) No prefix was used, and a default namespace has not been
00105 **          defined.
00106 **       b) No prefix was used, and the default namespace was specified
00107 **          to mean "no namespace". This is done with a namespace
00108 **          declaration of:  xmlns=""
00109 **          (this declaration is typically used to override a previous
00110 **          specification for the default namespace)
00111 **
00112 **       In these cases, we need to record that the elem/attr has no
00113 **       namespace so that we will not attempt to prepend a prefix.
00114 **       All namespaces that are used will have a prefix assigned to
00115 **       them -- mod_dav will never set or use the default namespace
00116 **       when generating XML. This means that "no prefix" will always
00117 **       mean "no namespace".
00118 **
00119 **    In both cases, the XML generation will avoid prepending a prefix.
00120 **    For the first case, this means the original prefix/name will be
00121 **    inserted into the output stream. For the latter case, it means
00122 **    the name will have no prefix, and since we never define a default
00123 **    namespace, this means it will have no namespace.
00124 **
00125 ** Note: currently, mod_dav understands the "xmlns" prefix and the
00126 **     "xml:lang" attribute. These are handled specially (they aren't
00127 **     left within the XML tree), so the APR_XML_NS_NONE value won't ever
00128 **     really apply to these values.
00129 */
00130 #define APR_XML_NS_DAV_ID       0       
00131 #define APR_XML_NS_NONE         -10     
00133 #define APR_XML_NS_ERROR_BASE   -100    
00135 #define APR_XML_NS_IS_ERROR(e)  ((e) <= APR_XML_NS_ERROR_BASE)
00136 
00138 typedef struct apr_xml_attr apr_xml_attr;
00140 typedef struct apr_xml_elem apr_xml_elem;
00142 typedef struct apr_xml_doc apr_xml_doc;
00143 
00145 struct apr_xml_attr {
00147     const char *name;
00149     int ns;
00150 
00152     const char *value;
00153 
00155     struct apr_xml_attr *next;
00156 };
00157 
00159 struct apr_xml_elem {
00161     const char *name;
00163     int ns;
00165     const char *lang;
00166 
00168     apr_text_header first_cdata;
00170     apr_text_header following_cdata;
00171 
00173     struct apr_xml_elem *parent;        
00175     struct apr_xml_elem *next;  
00177     struct apr_xml_elem *first_child;
00179     struct apr_xml_attr *attr;          
00180 
00181     /* used only during parsing */
00183     struct apr_xml_elem *last_child;
00185     struct apr_xml_ns_scope *ns_scope;
00186 
00187     /* used by modules during request processing */
00189     void *priv;
00190 };
00191 
00193 #define APR_XML_ELEM_IS_EMPTY(e) ((e)->first_child == NULL && \
00194                                   (e)->first_cdata.first == NULL)
00195 
00197 struct apr_xml_doc {
00199     apr_xml_elem *root; 
00201     apr_array_header_t *namespaces;
00202 };
00203 
00205 typedef struct apr_xml_parser apr_xml_parser;
00206 
00212 APU_DECLARE(apr_xml_parser *) apr_xml_parser_create(apr_pool_t *pool);
00213 
00224 APU_DECLARE(apr_status_t) apr_xml_parse_file(apr_pool_t *p,
00225                                              apr_xml_parser **parser,
00226                                              apr_xml_doc **ppdoc,
00227                                              apr_file_t *xmlfd,
00228                                              apr_size_t buffer_length);
00229 
00230 
00239 APU_DECLARE(apr_status_t) apr_xml_parser_feed(apr_xml_parser *parser,
00240                                               const char *data,
00241                                               apr_size_t len);
00242 
00251 APU_DECLARE(apr_status_t) apr_xml_parser_done(apr_xml_parser *parser,
00252                                               apr_xml_doc **pdoc);
00253 
00261 APU_DECLARE(char *) apr_xml_parser_geterror(apr_xml_parser *parser,
00262                                             char *errbuf,
00263                                             apr_size_t errbufsize);
00264 
00265 
00282 APU_DECLARE(void) apr_xml_to_text(apr_pool_t *p, const apr_xml_elem *elem,
00283                                   int style, apr_array_header_t *namespaces,
00284                                   int *ns_map, const char **pbuf,
00285                                   apr_size_t *psize);
00286 
00287 /* style argument values: */
00288 #define APR_XML_X2T_FULL         0      
00289 #define APR_XML_X2T_INNER        1      
00290 #define APR_XML_X2T_LANG_INNER   2      
00291 #define APR_XML_X2T_FULL_NS_LANG 3      
00299 APU_DECLARE(const char *) apr_xml_empty_elem(apr_pool_t *p,
00300                                              const apr_xml_elem *elem);
00301 
00312 APU_DECLARE(const char *) apr_xml_quote_string(apr_pool_t *p, const char *s,
00313                                                int quotes);
00314 
00320 APU_DECLARE(void) apr_xml_quote_elem(apr_pool_t *p, apr_xml_elem *elem);
00321 
00322 /* manage an array of unique URIs: apr_xml_insert_uri() and APR_XML_URI_ITEM() */
00323 
00330 APU_DECLARE(int) apr_xml_insert_uri(apr_array_header_t *uri_array,
00331                                     const char *uri);
00332 
00334 #define APR_XML_GET_URI_ITEM(ary, i) (((const char * const *)(ary)->elts)[i])
00335 
00336 #ifdef __cplusplus
00337 }
00338 #endif
00339 
00340 #endif /* APR_XML_H */

Generated on Tue Sep 11 08:13:14 2007 for Apache Portable Runtime Utility Library by  doxygen 1.5.2