apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Holsman <i...@cnet.com>
Subject [contrib] apr_xml_parse_file
Date Tue, 07 Aug 2001 19:58:35 GMT
I'd really like to get this into the next beta.
so if someone could review/commit it that would
be great.

Cheers
Ian

Index: apr_xml.c
===================================================================
RCS file: /home/cvspublic/apr-util/xml/apr_xml.c,v
retrieving revision 1.21
diff -u -r1.21 apr_xml.c
--- apr_xml.c	2001/04/26 21:29:00	1.21
+++ apr_xml.c	2001/08/07 19:54:48
@@ -60,6 +60,7 @@
 #include "apr_want.h"
 
 #include "apr_xml.h"
+#include "apr_file_io.h"
 
 #include "apu_config.h"
 
@@ -479,7 +480,38 @@
     return errbuf;
 }
 
+APU_DECLARE(apr_status_t) apr_xml_parse_file(apr_pool_t *p,
apr_xml_parser**parser,apr_xml_doc **ppdoc, apr_file_t *xmlfd,int
buffer_length)
+{	
+    apr_status_t rv;
+    char *buffer;
+    apr_size_t length;
+
+    *parser = apr_xml_parser_create(p);
+    if (*parser == NULL ) {
+        /* FIXME: returnng  a error code would be nice, but we dont get
one ;( */
+        return APR_EGENERAL;
+    }
+    buffer = apr_palloc(p,buffer_length);
+    length=buffer_length;
+
+    rv = apr_file_read( xmlfd, buffer, &length);
+
+    while (rv == APR_SUCCESS ) {
+        rv = apr_xml_parser_feed(  *parser, buffer, length);
+        if (rv != APR_SUCCESS ) {
+            return rv;
+        }
 
+        length=buffer_length;
+        rv = apr_file_read( xmlfd, buffer, &length);
+    }
+    if ( rv != APR_EOF ) {
+        return rv;
+    }
+    rv = apr_xml_parser_done( *parser, ppdoc );
+    *parser=NULL;
+    return rv;
+}
 APU_DECLARE(void) apr_text_append(apr_pool_t * p, apr_text_header *hdr,
                                   const char *text)
 {


Index: apr_xml.h
===================================================================
RCS file: /home/cvspublic/apr-util/include/apr_xml.h,v
retrieving revision 1.13
diff -u -r1.13 apr_xml.h
--- apr_xml.h	2001/05/16 17:22:34	1.13
+++ apr_xml.h	2001/08/07 19:55:43
@@ -57,6 +57,7 @@
 
 #include "apr_pools.h"
 #include "apr_tables.h"
+#include "apr_file_io.h"
 
 #include "apu.h"
 
@@ -243,6 +244,17 @@
  * @return The new parser.
  */
 APU_DECLARE(apr_xml_parser *) apr_xml_parser_create(apr_pool_t *pool);
+/**
+ * Parse a File, producing a xml_doc
+ * @param pool The pool for allocating the parse results.
+ * @param parser A pointer to *parser (needed so calling function can
get errors), will be set to NULL on successfull completion.
+ * @param pdoc A pointer to *apr_xml_doc (which has the parsed results
in it)
+ * @param xmlfd A file to read from.
+ * @param int Buffer length which would be suitable 
+ * @return Any errors found during parsing.
+ */
+APU_DECLARE(apr_status_t) apr_xml_parse_file(apr_pool_t *p,
apr_xml_parser**parser,apr_xml_doc **ppdoc, apr_file_t *xmlfd,int
buffer_length);
+
 
 /**
  * Feed input into the parser


Index: Makefile.in
===================================================================
RCS file: /home/cvspublic/apr-util/test/Makefile.in,v
retrieving revision 1.12
diff -u -r1.12 Makefile.in
--- Makefile.in	2001/08/01 20:32:59	1.12
+++ Makefile.in	2001/08/07 19:54:29
@@ -1,7 +1,7 @@
 top_builddir=@top_builddir@
 INCLUDES=-I$(top_builddir)/include -I$(top_builddir)/include/private
-I@APR_SOURCE_DIR@/include
 TARGETS =
-PROGRAMS = testdbm testdate testmd4
+PROGRAMS = testdbm testdate testmd4 testxml
 
 # bring in rules.mk for standard functionality
 @INCLUDE_RULES@
@@ -17,6 +17,11 @@
 testdate_LDADD =  ../libaprutil.la @APR_SOURCE_DIR@/libapr.la
 testdate: $(testdate_OBJECTS) $(testdate_LDADD)
 	$(LINK) $(testdate_OBJECTS) $(testdate_LDADD) $(LIBS)
+
+testxml_OBJECTS = testxml.lo
+testxml_LDADD =  ../libaprutil.la @APR_SOURCE_DIR@/libapr.la
../xml/expat/lib/libexpat.la
+testxml: $(testxml_OBJECTS) $(testxml_LDADD)
+	$(LINK) $(testxml_OBJECTS) $(testxml_LDADD) $(LIBS)
 
 testmd4_OBJECTS = testmd4.lo
 testmd4_LDADD =  ../libaprutil.la @APR_SOURCE_DIR@/libapr.la

-- 
Ian Holsman          IanH@cnet.com
Performance Measurement & Analysis
CNET Networks   -   (415) 364-8608

Mime
View raw message