Commit e1ca5033 authored by Daniel Veillard's avatar Daniel Veillard

Adding a new set of APIs based on the C# TextXmlReader API but converted

* Makefile.am xmlreader.c include/libxml/Makefile.am
  include/libxml/xmlreader.h:  Adding a new set of APIs based on
  the C# TextXmlReader API but converted to C. Allow to parse
  in constant memory usage, far simpler to program and explain
  than the SAX like APIs, unfinished but working.
* testReader.c: test program
Daniel
parent 70a296cb
Mon Dec 9 15:08:17 CET 2002 Daniel Veillard <daniel@veillard.com>
* Makefile.am xmlreader.c include/libxml/Makefile.am
include/libxml/xmlreader.h: Adding a new set of APIs based on
the C# TextXmlReader API but converted to C. Allow to parse
in constant memory usage, far simpler to program and explain
than the SAX like APIs, unfinished but working.
* testReader.c: test program
Sun Dec 8 18:36:01 CET 2002 Igor Zlatkovic <igor@stud.fh-frankfurt.de>
* win32/libxml2.def.src: applied YALDSP from Mark Vakoc
......
......@@ -8,7 +8,7 @@ DIST_SUBDIRS = include . doc example python
INCLUDES = -I$(top_builddir)/include -I@srcdir@/include @THREAD_CFLAGS@ @Z_CFLAGS@
noinst_PROGRAMS=testSchemas testSAX testHTML testXPath testURI testDocbook \
testThreads testC14N testAutomata testRegexp
testThreads testC14N testAutomata testRegexp testReader
bin_PROGRAMS = xmllint xmlcatalog
......@@ -26,14 +26,15 @@ libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c globals.c threads.c c14n.c \
xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \
triostr.c trio.c
triostr.c trio.c xmlreader.c
else
libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \
parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \
valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c \
xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \
catalog.c globals.c threads.c c14n.c \
xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c
xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \
xmlreader.c
endif
DEPS = $(top_builddir)/libxml2.la
......@@ -104,6 +105,11 @@ testSchemas_LDFLAGS =
testSchemas_DEPENDENCIES = $(DEPS)
testSchemas_LDADD= $(LDADDS)
testReader_SOURCES=testReader.c
testReader_LDFLAGS =
testReader_DEPENDENCIES = $(DEPS)
testReader_LDADD= $(LDADDS)
check-local: tests
testall : tests SVGtests SAXtests
......
......@@ -525,6 +525,7 @@ A:link, A:visited, A:active { text-decoration: underline }
<dd>
<a href="html/libxml-docbparser.html#DOCBPARSECHUNK">docbParseChunk</a>
<a href="html/libxml-htmltree.html#HTMLDOCDUMP">htmlDocDump</a>
<a href="html/libxml-htmltree.html#HTMLNODEDUMP">htmlNodeDump</a>
<a href="html/libxml-htmltree.html#HTMLNODEDUMPFILEFORMAT">htmlNodeDumpFileFormat</a>
<a href="html/libxml-htmlparser.html#HTMLPARSECHUNK">htmlParseChunk</a>
<a href="html/libxml-htmltree.html#HTMLSAVEFILE">htmlSaveFile</a>
......
......@@ -2714,7 +2714,7 @@
</function>
<function name='htmlNodeDump' file='HTMLtree'>
<info>Dump an HTML node, recursive behaviour,children are printed too, and formatting returns are added.</info>
<return type='void'/>
<return type='int' info='the number of byte written or -1 in case of error '/>
<arg name='buf' type='xmlBufferPtr' info='the HTML buffer output '/>
<arg name='doc' type='xmlDocPtr' info='the document '/>
<arg name='cur' type='xmlNodePtr' info='the current node '/>
......
......@@ -13322,6 +13322,7 @@
<word name='byte'>
<ref name='docbParseChunk'/>
<ref name='htmlDocDump'/>
<ref name='htmlNodeDump'/>
<ref name='htmlNodeDumpFileFormat'/>
<ref name='htmlParseChunk'/>
<ref name='htmlSaveFile'/>
......
......@@ -37,7 +37,8 @@ xmlinc_HEADERS = \
xmlschemas.h \
schemasInternals.h \
xmlschemastypes.h \
xmlunicode.h
xmlunicode.h \
xmlreader.h
install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(xmlincdir)
......
/*
* xmlreader.h : Interfaces, constants and types of the XML streaming API.
*
* See Copyright for the status of this software.
*
* daniel@veillard.com
*/
#ifndef __XML_XMLREADER_H__
#define __XML_XMLREADER_H__
#include <libxml/tree.h>
#include <libxml/xmlIO.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _xmlTextReader xmlTextReader;
typedef xmlTextReader *xmlTextReaderPtr;
/*
* Constructors & Destructor
*/
xmlTextReaderPtr xmlNewTextReader (xmlParserInputBufferPtr input);
xmlTextReaderPtr xmlNewTextReaderFilename(const char *URI);
void xmlFreeTextReader (xmlTextReaderPtr reader);
/*
* Iterators
*/
int xmlTextReaderRead (xmlTextReaderPtr reader);
/*
* Attributes of the node
*/
int xmlTextReaderAttributeCount(xmlTextReaderPtr reader);
xmlChar * xmlTextReaderBaseUri (xmlTextReaderPtr reader);
int xmlTextReaderDepth (xmlTextReaderPtr reader);
int xmlTextReaderHasAttributes(xmlTextReaderPtr reader);
int xmlTextReaderHasValue(xmlTextReaderPtr reader);
int xmlTextReaderIsDefault (xmlTextReaderPtr reader);
int xmlTextReaderIsEmptyElement(xmlTextReaderPtr reader);
xmlChar * xmlTextReaderLocalName (xmlTextReaderPtr reader);
xmlChar * xmlTextReaderName (xmlTextReaderPtr reader);
xmlChar * xmlTextReaderNamespaceUri(xmlTextReaderPtr reader);
int xmlTextReaderNodeType (xmlTextReaderPtr reader);
xmlChar * xmlTextReaderPrefix (xmlTextReaderPtr reader);
int xmlTextReaderQuoteChar (xmlTextReaderPtr reader);
xmlChar * xmlTextReaderValue (xmlTextReaderPtr reader);
xmlChar * xmlTextReaderXmlLang (xmlTextReaderPtr reader);
#ifdef __cplusplus
}
#endif
#endif /* __XML_XMLREADER_H__ */
......@@ -9871,6 +9871,7 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt,
oldsax = ctxt->sax;
ctxt->sax = oldctxt->sax;
ctxt->_private = oldctxt->_private;
if (oldctxt->myDoc == NULL) {
newDoc = xmlNewDoc(BAD_CAST "1.0");
if (newDoc == NULL) {
......
/*
* testSAX.c : a small tester program for parsing using the SAX API.
*
* See Copyright for the status of this software.
*
* daniel@veillard.com
*/
#include "libxml.h"
#include <string.h>
#include <stdarg.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <libxml/xmlreader.h>
int debug = 0;
int dump = 0;
int noent = 0;
int count = 0;
static void usage(const char *progname) {
printf("Usage : %s [options] XMLfiles ...\n", progname);
printf("\tParse the XML files using the xmlTextReader API\n");
printf("\tand output the result of the parsing\n");
exit(1);
}
static int elem, attrs;
static void processNode(xmlTextReaderPtr reader) {
int type;
type = xmlTextReaderNodeType(reader);
if (count) {
if (type == 1) {
elem++;
attrs += xmlTextReaderAttributeCount(reader);
}
} else {
xmlChar *name = xmlTextReaderName(reader);
if (name != NULL) {
printf("%s : %d", name, xmlTextReaderNodeType(reader));
xmlFree(name);
} else {
printf("NULL: %d", xmlTextReaderNodeType(reader));
}
if (xmlTextReaderIsEmptyElement(reader))
printf(" empty");
printf("\n");
}
}
static void handleFile(const char *filename) {
xmlTextReaderPtr reader;
int ret;
if (count) {
elem = 0;
attrs = 0;
}
reader = xmlNewTextReaderFilename(filename);
if (reader != NULL) {
/*
* Process all nodes in sequence
*/
ret = xmlTextReaderRead(reader);
while (ret == 1) {
processNode(reader);
ret = xmlTextReaderRead(reader);
}
/*
* Done, cleanup and status
*/
xmlFreeTextReader(reader);
if (ret != 0) {
printf("%s : failed to parse\n", filename);
} else if (count)
printf("%s : %d elements, %d attributes\n", filename, elem, attrs);
} else {
fprintf(stderr, "Unable to open %s\n", filename);
}
}
int main(int argc, char **argv) {
int i;
int files = 0;
if (argc <= 1) {
usage(argv[0]);
return(1);
}
LIBXML_TEST_VERSION
for (i = 1; i < argc ; i++) {
if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
debug++;
else if ((!strcmp(argv[i], "-dump")) || (!strcmp(argv[i], "--dump")))
dump++;
else if ((!strcmp(argv[i], "-count")) || (!strcmp(argv[i], "--count")))
count++;
else if ((!strcmp(argv[i], "-noent")) ||
(!strcmp(argv[i], "--noent")))
noent++;
}
if (noent != 0) xmlSubstituteEntitiesDefault(1);
for (i = 1; i < argc ; i++) {
if (argv[i][0] != '-') {
handleFile(argv[i]);
files ++;
}
}
xmlCleanupParser();
xmlMemoryDump();
return(0);
}
......@@ -2589,7 +2589,8 @@ xmlFreeNodeList(xmlNodePtr cur) {
if ((cur->children != NULL) &&
(cur->type != XML_ENTITY_REF_NODE))
xmlFreeNodeList(cur->children);
if (cur->properties != NULL)
if ((cur->type == XML_ELEMENT_NODE) &&
(cur->properties != NULL))
xmlFreePropList(cur->properties);
if ((cur->type != XML_ELEMENT_NODE) &&
(cur->type != XML_XINCLUDE_START) &&
......@@ -2666,7 +2667,7 @@ xmlFreeNode(xmlNodePtr cur) {
if ((cur->children != NULL) &&
(cur->type != XML_ENTITY_REF_NODE))
xmlFreeNodeList(cur->children);
if (cur->properties != NULL)
if ((cur->type == XML_ELEMENT_NODE) && (cur->properties != NULL))
xmlFreePropList(cur->properties);
if ((cur->type != XML_ELEMENT_NODE) &&
(cur->content != NULL) &&
......@@ -2701,7 +2702,11 @@ xmlFreeNode(xmlNodePtr cur) {
xmlFree((char *) cur->name);
}
if (cur->nsDef != NULL) xmlFreeNsList(cur->nsDef);
if (((cur->type == XML_ELEMENT_NODE) ||
(cur->type == XML_XINCLUDE_START) ||
(cur->type == XML_XINCLUDE_END)) &&
(cur->nsDef != NULL))
xmlFreeNsList(cur->nsDef);
xmlFree(cur);
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment