Main Page | Modules | Namespace List | Data Structures | File List | Data Fields | Globals | Related Pages

/usr/src/rpmbuilder/BUILD/apr-util-APU_0_9_BRANCH/include/apr_xml.h

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

Generated on Fri Apr 23 07:22:21 2004 for Apache Portable Runtime Utility Library by doxygen 1.3.4