1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-24 06:50:08 +03:00

Release 0.2, 80% rewrite, nothing left intact ... Daniel

This commit is contained in:
Daniel Veillard 1998-08-13 03:39:55 +00:00
parent a65771c1ca
commit 260a68fd34
74 changed files with 6510 additions and 2663 deletions

View File

@ -1,3 +1,11 @@
Wed Aug 12 23:12:58 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
* New release 0.2, removed the old xml_* files so that it's
coherent with the other CVS base (W3C), far better conformance
to standard, new namespaces, decent entities support, beginning
of a SAX-like interface. Nearly nothing left intact, even the
test examples ...
1998-07-30 Christopher Blizzard <blizzard@appliedtheory.com>
* .cvsignore: Add .deps dir

View File

@ -5,14 +5,18 @@ noinst_PROGRAMS=tester
lib_LTLIBRARIES = libxml.la
libxml_la_SOURCES = \
xml_entities.c \
xml_parser.c \
xml_tree.c
SAX.c \
entities.c \
error.c \
parser.c \
tester.c \
tree.c
include_HEADERS = \
xml_entities.h \
xml_parser.h \
xml_tree.h
entities.h \
parser.h \
tree.h
DEPS = $(top_builddir)/libxml.la
LDADDS = $(top_builddir)/libxml.la @Z_LIBS@

34
Makefile.win Normal file
View File

@ -0,0 +1,34 @@
# This is a makefile for win32 systems (VC 5.0).
# Christopher Blizzard
# http://odin.appliedtheory.com/
CC = cl
CFLAGS = /c /GB /Gi /nologo /I. /DWIN32 /MT /Zi
LD = link
LDFLAGS = /DEBUG /NODEFAULTLIB:libc
AR = lib
all: xml.lib
test: tester.exe
SHARED_OBJS = entities.obj parser.obj tree.obj SAX.obj
xml.lib: $(SHARED_OBJS)
$(AR) /out:xml.lib $(SHARED_OBJS)
tester.obj: $(SHARED_OBJS)
$(CC) $(CFLAGS) tester.c /out:tester.obj
tester.exe: tester.obj xml.lib
$(LD) $(LDFLAGS) /out:tester.exe tester.obj xml.lib
clean:
-del /f $(SHARED_OBJS) tester.obj
-del /f tester.exe
-del /f xml.lib
-del /f *.pdb
-del /f *.idb
-del /f *.ilk

223
SAX.c Normal file
View File

@ -0,0 +1,223 @@
/*
* SAX.c : Default SAX handler to build a tree.
*/
#include <stdio.h>
#include <malloc.h>
#include "tree.h"
#include "parser.h"
#include "error.h"
/* #define DEBUG_SAX */
/*
* Return the public ID e.g. "-//SGMLSOURCE//DTD DEMO//EN"
*/
const CHAR *getPublicId(xmlParserCtxtPtr ctxt) {
return(NULL);
}
/*
* Return the system ID, basically URI or filename e.g.
* http://www.sgmlsource.com/dtds/memo.dtd
*/
const CHAR *getSystemId(xmlParserCtxtPtr ctxt) {
return(ctxt->input->filename);
}
/*
* Return the line number of the current parsing point.
*/
int getLineNumber(xmlParserCtxtPtr ctxt) {
return(ctxt->input->line);
}
/*
* Return the column number of the current parsing point.
*/
int getColumnNumber(xmlParserCtxtPtr ctxt) {
return(ctxt->input->col);
}
/*
* The default SAX Locator.
*/
xmlSAXLocator xmlDefaultSAXLocator = {
getPublicId, getSystemId, getLineNumber, getColumnNumber
};
/*
* Special entity resolver, better left to the parser, it has
* more context than the application layer.
*/
xmlParserInputPtr resolveEntity(xmlParserCtxtPtr ctxt,
const CHAR *publicId, const CHAR *systemId) {
#ifdef DEBUG_SAX
fprintf(stderr, "SAX.resolveEntity(%s, %s)\n", publicId, systemId);
#endif
return(NULL);
}
/*
* What to do when a notation declaration has been parsed.
* TODO Not handled currently.
*/
void notationDecl(xmlParserCtxtPtr ctxt, const CHAR *name,
const CHAR *publicId, const CHAR *systemId) {
#ifdef DEBUG_SAX
fprintf(stderr, "SAX.notationDecl(%s, %s, %s)\n", name, publicId, systemId);
#endif
}
/*
* What to do when an unparsed entity declaration is parsed
* TODO Create an Entity node.
*/
void unparsedEntityDecl(xmlParserCtxtPtr ctxt, const CHAR *name,
const CHAR *publicId, const CHAR *systemId,
const CHAR *notationName) {
#ifdef DEBUG_SAX
fprintf(stderr, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n",
name, publicId, systemId, notationName);
#endif
}
/*
* Receive the document locator at startup, actually xmlDefaultSAXLocator
* Everything is available on the context, so this is useless in our case.
*/
void setDocumentLocator(xmlParserCtxtPtr ctxt, xmlSAXLocatorPtr loc) {
#ifdef DEBUG_SAX
fprintf(stderr, "SAX.setDocumentLocator()\n");
#endif
}
/*
* called when the document start being processed.
*/
void startDocument(xmlParserCtxtPtr ctxt) {
#ifdef DEBUG_SAX
fprintf(stderr, "SAX.startDocument()\n");
#endif
}
/*
* called when the document end has been detected.
*/
void endDocument(xmlParserCtxtPtr ctxt) {
#ifdef DEBUG_SAX
fprintf(stderr, "SAX.endDocument()\n");
#endif
}
/*
* called when an opening tag has been processed.
* TODO We currently have a small pblm with the arguments ...
*/
void startElement(xmlParserCtxtPtr ctxt, const CHAR *name) {
xmlNodePtr parent;
#ifdef DEBUG_SAX
fprintf(stderr, "SAX.startElement(%s)\n", name);
#endif
if (ctxt->nodeNr < 2) return;
parent = ctxt->nodeTab[ctxt->nodeNr - 2];
if (parent != NULL)
xmlAddChild(parent, ctxt->node);
}
/*
* called when the end of an element has been detected.
*/
void endElement(xmlParserCtxtPtr ctxt, const CHAR *name) {
#ifdef DEBUG_SAX
fprintf(stderr, "SAX.endElement(%s)\n", name);
#endif
}
/*
* receiving some chars from the parser.
* Question: how much at a time ???
*/
void characters(xmlParserCtxtPtr ctxt, const CHAR *ch,
int start, int len) {
xmlNodePtr lastChild;
#ifdef DEBUG_SAX
fprintf(stderr, "SAX.characters(%.30s, %d, %d)\n", ch, start, len);
#endif
/*
* Handle the data if any. If there is no child
* add it as content, otherwise if the last child is text,
* concatenate it, else create a new node of type text.
*/
lastChild = xmlGetLastChild(ctxt->node);
if (lastChild == NULL)
xmlNodeAddContentLen(ctxt->node, &ch[start], len);
else {
if (xmlNodeIsText(lastChild))
xmlTextConcat(lastChild, &ch[start], len);
else {
lastChild = xmlNewTextLen(&ch[start], len);
xmlAddChild(ctxt->node, lastChild);
}
}
}
/*
* receiving some ignorable whitespaces from the parser.
* Question: how much at a time ???
*/
void ignorableWhitespace(xmlParserCtxtPtr ctxt, const CHAR *ch,
int start, int len) {
#ifdef DEBUG_SAX
fprintf(stderr, "SAX.ignorableWhitespace(%.30s, %d, %d)\n", ch, start, len);
#endif
}
/*
* A processing instruction has beem parsed.
*/
void processingInstruction(xmlParserCtxtPtr ctxt, const CHAR *target,
const CHAR *data) {
#ifdef DEBUG_SAX
fprintf(stderr, "SAX.processingInstruction(%s, %s)\n", target, data);
#endif
}
xmlSAXHandler xmlDefaultSAXHandler = {
resolveEntity,
notationDecl,
unparsedEntityDecl,
setDocumentLocator,
startDocument,
endDocument,
startElement,
endElement,
characters,
ignorableWhitespace,
processingInstruction,
xmlParserWarning,
xmlParserError,
xmlParserError,
};
void xmlDefaultSAXHandlerInit(void) {
xmlDefaultSAXHandler.resolveEntity = resolveEntity;
xmlDefaultSAXHandler.notationDecl = notationDecl;
xmlDefaultSAXHandler.unparsedEntityDecl = unparsedEntityDecl;
xmlDefaultSAXHandler.setDocumentLocator = setDocumentLocator;
xmlDefaultSAXHandler.startDocument = startDocument;
xmlDefaultSAXHandler.endDocument = endDocument;
xmlDefaultSAXHandler.startElement = startElement;
xmlDefaultSAXHandler.endElement = endElement;
xmlDefaultSAXHandler.characters = characters;
xmlDefaultSAXHandler.ignorableWhitespace = ignorableWhitespace;
xmlDefaultSAXHandler.processingInstruction = processingInstruction;
xmlDefaultSAXHandler.warning = xmlParserWarning;
xmlDefaultSAXHandler.error = xmlParserError;
xmlDefaultSAXHandler.fatalError = xmlParserError;
}

25
TODO
View File

@ -1,15 +1,11 @@
TODO for the XML parser:
- Support for UTF-8 encoding
- progressive parsing. Currently the parser uses a single
string containing the full document. The good point is
that there is no context associated with the parser, the
full state is in the stack. The bad point is that such a
recursive design is hard to make progressive ...
- Better error handling, use a dedicated, overridable error
handling function.
- Keep track of line numbers for better error reporting.
- Support for UTF-8 and UTF-16 encoding (Urgent !!!).
- progressive parsing. The entity support is a first step toward
asbtraction of an input stream. A large part of the context is still
located on the stack, moving to a state machine and putting everyting
in the parsing context should provide an adequate solution.
- DOM support, instead of using a proprietary in memory
format for the document representation, the parser should
call a DOM API to actually build the resulting document.
@ -17,14 +13,17 @@
representation of the document. Even better using RPC's
the parser can actually build the document in another
program.
- finish the support for Entities.
- Support for Comments (bad, should be in ASAP, they are parsed
but not stored).
- Support for PI.
- Support for CDATA.
but not stored), should be configurable.
- Improve the support of entities on save (+SAX).
Done:
- C++ support : John Ehresman <jehresma@dsg.harvard.edu>
- Updated code to follow more recent specs, added compatibility flag
- Better error handling, use a dedicated, overridable error
handling function.
- Support for CDATA.
- Keep track of line numbers for better error reporting.
- Support for PI (SAX one).
$Id$

View File

@ -5,7 +5,7 @@ DIE=0
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile GLIB."
echo "You must have autoconf installed to compile gnome-xml."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
DIE=1
@ -13,7 +13,7 @@ DIE=0
(libtool --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have libtool installed to compile GLIB."
echo "You must have libtool installed to compile gnome-xml."
echo "Get ftp://alpha.gnu.org/gnu/libtool-1.0h.tar.gz"
echo "(or a newer version if it is available)"
DIE=1
@ -21,7 +21,7 @@ DIE=0
(automake --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have automake installed to compile GLIB."
echo "You must have automake installed to compile gnome-xml."
echo "Get ftp://ftp.cygnus.com/pub/home/tromey/automake-1.2d.tar.gz"
echo "(or a newer version if it is available)"
DIE=1
@ -31,8 +31,8 @@ if test "$DIE" -eq 1; then
exit 1
fi
test -f xml_entities.h || {
echo "You must run this script in the top-level GLIB directory"
test -f entities.h || {
echo "You must run this script in the top-level gnome-xml directory"
exit 1
}

62
config.h Normal file
View File

@ -0,0 +1,62 @@
/* config.h. Generated automatically by configure. */
/* config.h.in. Generated automatically from configure.in by autoheader. */
/* Define if you have the strftime function. */
#define HAVE_STRFTIME 1
/* Define if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if you have the snprintf function. */
#define HAVE_SNPRINTF 1
/* Define if you have the strdup function. */
#define HAVE_STRDUP 1
/* Define if you have the strerror function. */
#define HAVE_STRERROR 1
/* Define if you have the strndup function. */
#define HAVE_STRNDUP 1
/* Define if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
/* Define if you have the <dirent.h> header file. */
#define HAVE_DIRENT_H 1
/* Define if you have the <errno.h> header file. */
#define HAVE_ERRNO_H 1
/* Define if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define if you have the <malloc.h> header file. */
#define HAVE_MALLOC_H 1
/* Define if you have the <ndir.h> header file. */
/* #undef HAVE_NDIR_H */
/* Define if you have the <stdarg.h> header file. */
#define HAVE_STDARG_H 1
/* Define if you have the <sys/dir.h> header file. */
/* #undef HAVE_SYS_DIR_H */
/* Define if you have the <sys/ndir.h> header file. */
/* #undef HAVE_SYS_NDIR_H */
/* Define if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define if you have the <time.h> header file. */
#define HAVE_TIME_H 1
/* Define if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define if you have the <zlib.h> header file. */
#define HAVE_ZLIB_H 1

View File

@ -1,8 +1,8 @@
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.2)
AC_INIT(xml_entities.h)
AC_INIT(entities.h)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(libxml, 0.10)
AM_INIT_AUTOMAKE(libxml, 0.20)
dnl Checks for programs.
AC_PROG_CC

426
entities.c Normal file
View File

@ -0,0 +1,426 @@
/*
* entities.c : implementation for the XML entities handking
*
* See Copyright for the status of this software.
*
* $Id$
*/
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include "entities.h"
/*
* The XML predefined entities.
*/
struct xmlPredefinedEntityValue {
const char *name;
const char *value;
};
struct xmlPredefinedEntityValue xmlPredefinedEntityValues[] = {
{ "lt", "<" },
{ "gt", ">" },
{ "apos", "'" },
{ "quot", "\"" },
{ "amp", "&" }
};
xmlEntitiesTablePtr xmlPredefinedEntities = NULL;
/*
* A buffer used for converting entities to their equivalent and back.
*/
static int buffer_size = 0;
static CHAR *buffer = NULL;
void growBuffer(void) {
buffer_size *= 2;
buffer = (CHAR *) realloc(buffer, buffer_size * sizeof(CHAR));
if (buffer == NULL) {
perror("realloc failed");
exit(1);
}
}
/*
* xmlFreeEntity : clean-up an entity record.
*/
void xmlFreeEntity(xmlEntityPtr entity) {
if (entity == NULL) return;
if (entity->name != NULL)
free((char *) entity->name);
if (entity->ExternalID != NULL)
free((char *) entity->ExternalID);
if (entity->SystemID != NULL)
free((char *) entity->SystemID);
if (entity->content != NULL)
free((char *) entity->content);
memset(entity, -1, sizeof(xmlEntity));
}
/*
* xmlAddDocEntity : register a new entity for an entities table.
*
* TODO !!! We should check here that the combination of type
* ExternalID and SystemID is valid.
*/
static void xmlAddEntity(xmlEntitiesTablePtr table, const CHAR *name, int type,
const CHAR *ExternalID, const CHAR *SystemID, CHAR *content) {
int i;
xmlEntityPtr cur;
int len;
for (i = 0;i < table->nb_entities;i++) {
cur = &table->table[i];
if (!xmlStrcmp(cur->name, name)) {
/*
* The entity is already defined in this Dtd, the spec says to NOT
* override it ... Is it worth a Warning ??? !!!
*/
return;
}
}
if (table->nb_entities >= table->max_entities) {
/*
* need more elements.
*/
table->max_entities *= 2;
table->table = (xmlEntityPtr)
realloc(table->table, table->max_entities * sizeof(xmlEntity));
if (table->table) {
perror("realloc failed");
exit(1);
}
}
cur = &table->table[table->nb_entities];
cur->name = xmlStrdup(name);
for (len = 0;name[0] != 0;name++)len++;
cur->len = len;
cur->type = type;
if (ExternalID != NULL)
cur->ExternalID = xmlStrdup(ExternalID);
else
cur->ExternalID = NULL;
if (SystemID != NULL)
cur->SystemID = xmlStrdup(SystemID);
else
cur->SystemID = NULL;
if (content != NULL)
cur->content = xmlStrdup(content);
else
cur->content = NULL;
table->nb_entities++;
}
/*
* Set up xmlPredefinedEntities from xmlPredefinedEntityValues.
*/
void xmlInitializePredefinedEntities(void) {
int i;
CHAR name[50];
CHAR value[50];
const char *in;
CHAR *out;
if (xmlPredefinedEntities != NULL) return;
xmlPredefinedEntities = xmlCreateEntitiesTable();
for (i = 0;i < sizeof(xmlPredefinedEntityValues) /
sizeof(xmlPredefinedEntityValues[0]);i++) {
in = xmlPredefinedEntityValues[i].name;
out = &name[0];
for (;(*out++ = (CHAR) *in);)in++;
in = xmlPredefinedEntityValues[i].value;
out = &value[0];
for (;(*out++ = (CHAR) *in);)in++;
xmlAddEntity(xmlPredefinedEntities, (const CHAR *) &name[0],
XML_INTERNAL_GENERAL_ENTITY, NULL, NULL,
&value[0]);
}
}
/*
* xmlAddDtdEntity : register a new entity for this DTD.
*/
void xmlAddDtdEntity(xmlDocPtr doc, const CHAR *name, int type,
const CHAR *ExternalID, const CHAR *SystemID, CHAR *content) {
xmlEntitiesTablePtr table;
if (doc->dtd == NULL) {
fprintf(stderr, "xmlAddDtdEntity: document without Dtd !\n");
return;
}
table = (xmlEntitiesTablePtr) doc->dtd->entities;
if (table == NULL) {
table = xmlCreateEntitiesTable();
doc->dtd->entities = table;
}
xmlAddEntity(table, name, type, ExternalID, SystemID, content);
}
/*
* xmlAddDocEntity : register a new entity for this document.
*/
void xmlAddDocEntity(xmlDocPtr doc, const CHAR *name, int type,
const CHAR *ExternalID, const CHAR *SystemID, CHAR *content) {
xmlEntitiesTablePtr table;
table = (xmlEntitiesTablePtr) doc->entities;
if (table == NULL) {
table = xmlCreateEntitiesTable();
doc->entities = table;
}
xmlAddEntity(doc->entities, name, type, ExternalID, SystemID, content);
}
/*
* xmlGetDtdEntity : do an entity lookup in the Dtd entity hash table and
* returns the corrsponding entity, if found, NULL otherwise.
*/
xmlEntityPtr xmlGetDtdEntity(xmlDocPtr doc, const CHAR *name) {
int i;
xmlEntityPtr cur;
xmlEntitiesTablePtr table;
if ((doc->dtd != NULL) && (doc->dtd->entities != NULL)) {
table = (xmlEntitiesTablePtr) doc->dtd->entities;
for (i = 0;i < table->nb_entities;i++) {
cur = &table->table[i];
if (!xmlStrcmp(cur->name, name)) return(cur);
}
}
return(NULL);
}
/*
* xmlGetDocEntity : do an entity lookup in the document entity hash table and
* returns the corrsponding entity, otherwise a lookup is done
* in the predefined entities too.
*/
xmlEntityPtr xmlGetDocEntity(xmlDocPtr doc, const CHAR *name) {
int i;
xmlEntityPtr cur;
xmlEntitiesTablePtr table;
if (doc->entities != NULL) {
table = (xmlEntitiesTablePtr) doc->entities;
for (i = 0;i < table->nb_entities;i++) {
cur = &table->table[i];
if (!xmlStrcmp(cur->name, name)) return(cur);
}
}
if (xmlPredefinedEntities == NULL)
xmlInitializePredefinedEntities();
table = xmlPredefinedEntities;
for (i = 0;i < table->nb_entities;i++) {
cur = &table->table[i];
if (!xmlStrcmp(cur->name, name)) return(cur);
}
return(NULL);
}
/*
* xmlEncodeEntities : do a global encoding of a string, replacing the
* basic content with their entities form.
* TODO !!!! rewite !!!
*/
CHAR *xmlEncodeEntities(xmlDocPtr doc, const CHAR *input) {
const CHAR *cur = input;
CHAR *out = buffer;
if (buffer == NULL) {
buffer_size = 1000;
buffer = (CHAR *) malloc(buffer_size * sizeof(CHAR));
if (buffer == NULL) {
perror("malloc failed");
exit(1);
}
out = buffer;
}
while (*cur != '\0') {
if (out - buffer > buffer_size - 100) {
int index = out - buffer;
growBuffer();
out = &buffer[index];
}
/*
* By default one have to encode at least '<', '>', '"' and '&' !
* One could try a better encoding using the entities defined and
* used as a compression code !!!.
*/
if (*cur == '<') {
*out++ = '&';
*out++ = 'l';
*out++ = 't';
*out++ = ';';
} else if (*cur == '>') {
*out++ = '&';
*out++ = 'g';
*out++ = 't';
*out++ = ';';
} else if (*cur == '&') {
*out++ = '&';
*out++ = 'a';
*out++ = 'm';
*out++ = 'p';
*out++ = ';';
} else if (*cur == '"') {
*out++ = '&';
*out++ = 'q';
*out++ = 'u';
*out++ = 'o';
*out++ = 't';
*out++ = ';';
} else if (*cur == '\'') {
*out++ = '&';
*out++ = 'a';
*out++ = 'p';
*out++ = 'o';
*out++ = 's';
*out++ = ';';
} else {
/*
* default case, just copy !
*/
*out++ = *cur;
}
cur++;
}
*out++ = 0;
return(buffer);
}
/*
* xmlCreateEntitiesTable : create and initialize an enmpty hash table
*/
xmlEntitiesTablePtr xmlCreateEntitiesTable(void) {
xmlEntitiesTablePtr ret;
ret = (xmlEntitiesTablePtr)
malloc(sizeof(xmlEntitiesTable));
if (ret == NULL) {
fprintf(stderr, "xmlCreateEntitiesTable : malloc(%d) failed\n",
sizeof(xmlEntitiesTable));
return(NULL);
}
ret->max_entities = XML_MIN_ENTITIES_TABLE;
ret->nb_entities = 0;
ret->table = (xmlEntityPtr )
malloc(ret->max_entities * sizeof(xmlEntity));
if (ret == NULL) {
fprintf(stderr, "xmlCreateEntitiesTable : malloc(%d) failed\n",
ret->max_entities * sizeof(xmlEntity));
free(ret);
return(NULL);
}
return(ret);
}
/*
* xmlFreeEntitiesTable : clean up and free an entities hash table.
*/
void xmlFreeEntitiesTable(xmlEntitiesTablePtr table) {
int i;
if (table == NULL) return;
for (i = 0;i < table->nb_entities;i++) {
xmlFreeEntity(&table->table[i]);
}
free(table->table);
free(table);
}
/*
* Dump the content of an entity table to the document output.
*/
void xmlDumpEntitiesTable(xmlEntitiesTablePtr table) {
int i;
xmlEntityPtr cur;
if (table == NULL) return;
for (i = 0;i < table->nb_entities;i++) {
cur = &table->table[i];
switch (cur->type) {
case XML_INTERNAL_GENERAL_ENTITY:
xmlBufferWriteChar("<!ENTITY ");
xmlBufferWriteCHAR(cur->name);
xmlBufferWriteChar(" \"");
xmlBufferWriteCHAR(cur->content);
xmlBufferWriteChar("\">\n");
break;
case XML_EXTERNAL_GENERAL_PARSED_ENTITY:
xmlBufferWriteChar("<!ENTITY ");
xmlBufferWriteCHAR(cur->name);
if (cur->ExternalID != NULL) {
xmlBufferWriteChar(" PUBLIC \"");
xmlBufferWriteCHAR(cur->ExternalID);
xmlBufferWriteChar("\" \"");
xmlBufferWriteCHAR(cur->SystemID);
xmlBufferWriteChar("\"");
} else {
xmlBufferWriteChar(" SYSTEM \"");
xmlBufferWriteCHAR(cur->SystemID);
xmlBufferWriteChar("\"");
}
xmlBufferWriteChar(">\n");
break;
case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY:
xmlBufferWriteChar("<!ENTITY ");
xmlBufferWriteCHAR(cur->name);
if (cur->ExternalID != NULL) {
xmlBufferWriteChar(" PUBLIC \"");
xmlBufferWriteCHAR(cur->ExternalID);
xmlBufferWriteChar("\" \"");
xmlBufferWriteCHAR(cur->SystemID);
xmlBufferWriteChar("\"");
} else {
xmlBufferWriteChar(" SYSTEM \"");
xmlBufferWriteCHAR(cur->SystemID);
xmlBufferWriteChar("\"");
}
if (cur->content != NULL) { /* Should be true ! */
xmlBufferWriteChar(" NDATA ");
xmlBufferWriteCHAR(cur->content);
}
xmlBufferWriteChar(">\n");
break;
case XML_INTERNAL_PARAMETER_ENTITY:
xmlBufferWriteChar("<!ENTITY % ");
xmlBufferWriteCHAR(cur->name);
xmlBufferWriteChar(" \"");
xmlBufferWriteCHAR(cur->content);
xmlBufferWriteChar("\">\n");
break;
case XML_EXTERNAL_PARAMETER_ENTITY:
xmlBufferWriteChar("<!ENTITY % ");
xmlBufferWriteCHAR(cur->name);
if (cur->ExternalID != NULL) {
xmlBufferWriteChar(" PUBLIC \"");
xmlBufferWriteCHAR(cur->ExternalID);
xmlBufferWriteChar("\" \"");
xmlBufferWriteCHAR(cur->SystemID);
xmlBufferWriteChar("\"");
} else {
xmlBufferWriteChar(" SYSTEM \"");
xmlBufferWriteCHAR(cur->SystemID);
xmlBufferWriteChar("\"");
}
xmlBufferWriteChar(">\n");
break;
default:
fprintf(stderr,
"xmlDumpEntitiesTable: internal: unknown type %d\n",
cur->type);
}
}
}

View File

@ -8,21 +8,31 @@
#ifndef __XML_ENTITIES_H__
#define __XML_ENTITIES_H__
#include "xml_parser.h"
#include "parser.h"
#ifdef __cplusplus
extern "C" {
#endif
#define XML_INTERNAL_GENERAL_ENTITY 1
#define XML_EXTERNAL_GENERAL_PARSED_ENTITY 2
#define XML_EXTERNAL_GENERAL_UNPARSED_ENTITY 3
#define XML_INTERNAL_PARAMETER_ENTITY 4
#define XML_EXTERNAL_PARAMETER_ENTITY 5
/*
* An unit of storage for an entity, contains the string, the value
* and the linkind data needed for the linking in the hash table.
*/
typedef struct xmlEntity {
const CHAR *id; /* The entity name */
CHAR *value; /* The entity CHAR equivalent */
int type; /* The entity type */
int len; /* The lenght of the name */
const CHAR *name; /* Name of the entity */
const CHAR *ExternalID; /* External identifier for PUBLIC Entity */
const CHAR *SystemID; /* URI for a SYSTEM or PUBLIC Entity */
CHAR *content; /* The entity content or ndata if unparsed */
} xmlEntity, *xmlEntityPtr;
/*
@ -42,14 +52,16 @@ typedef struct xmlEntitiesTable {
* External functions :
*/
extern void xmlAddDocEntity(xmlDocPtr doc, CHAR *value, const CHAR *id);
extern void xmlAddDtdEntity(xmlDtdPtr dtd, CHAR *value, const CHAR *id);
extern CHAR *xmlGetEntity(xmlDocPtr doc, const CHAR *id);
extern CHAR *xmlSubstituteEntities(xmlDocPtr doc, const CHAR *input);
extern void xmlAddDocEntity(xmlDocPtr doc, const CHAR *name, int type,
const CHAR *ExternalID, const CHAR *SystemID, CHAR *content);
extern void xmlAddDtdEntity(xmlDocPtr doc, const CHAR *name, int type,
const CHAR *ExternalID, const CHAR *SystemID, CHAR *content);
extern xmlEntityPtr xmlGetDocEntity(xmlDocPtr doc, const CHAR *name);
extern xmlEntityPtr xmlGetDtdEntity(xmlDocPtr doc, const CHAR *name);
extern CHAR *xmlEncodeEntities(xmlDocPtr doc, const CHAR *input);
extern CHAR *xmlDecodeEntities(xmlDocPtr doc, const CHAR *input, int len);
extern xmlEntitiesTablePtr xmlCreateEntitiesTable(void);
extern void xmlFreeEntitiesTable(xmlEntitiesTablePtr table);
extern void xmlDumpEntitiesTable(xmlEntitiesTablePtr table);
#ifdef __cplusplus
}

93
error.c Normal file
View File

@ -0,0 +1,93 @@
/*
* error.c: module displaying errors
*/
#include <stdio.h>
#include <stdarg.h>
#include "parser.h"
/*
* Display and format error messages.
*/
void xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...) {
const CHAR *cur, *base;
va_list args;
int n;
va_start(args, msg);
if (ctxt->input->filename)
fprintf(stderr, "%s:%d: ", ctxt->input->filename,
ctxt->input->line);
else
fprintf(stderr, "line %d: ", ctxt->input->line);
fprintf(stderr, "error: ");
vfprintf(stderr, msg, args);
va_end(ap);
cur = ctxt->input->cur;
base = ctxt->input->base;
while ((*cur == '\n') || (*cur == '\r')) {
cur--;
base--;
}
n = 0;
while ((n++ < 60) && (cur >= base) && (*cur != '\n') && (*cur != '\r'))
cur--;
if ((*cur == '\n') || (*cur == '\r')) cur++;
base = cur;
n = 0;
while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
fprintf(stderr, "%c", (unsigned char) *cur++);
n++;
}
fprintf(stderr, "\n");
cur = ctxt->input->cur;
while ((*cur == '\n') || (*cur == '\r'))
cur--;
n = 0;
while ((cur != base) && (n++ < 60)) {
fprintf(stderr, " ");
base++;
}
fprintf(stderr,"^\n");
}
/*
* Display and format error messages.
*/
void xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...) {
const CHAR *cur, *base;
va_list args;
int n;
va_start(args, msg);
if (ctxt->input->filename)
fprintf(stderr, "%s:%d: ", ctxt->input->filename,
ctxt->input->line);
else
fprintf(stderr, "line %d: ", ctxt->input->line);
fprintf(stderr, "warning: ");
vfprintf(stderr, msg, args);
va_end(ap);
cur = ctxt->input->cur;
base = ctxt->input->base;
n = 0;
while ((n++ < 60) && (cur >= base) && (*cur != '\n') && (*cur != '\r'))
cur--;
if ((*cur != '\n') || (*cur != '\r')) cur++;
base = cur;
n = 0;
while ((*cur != 0) && (*cur != '\n') && (*cur != '\r') && (n < 79)) {
fprintf(stderr, "%c", (unsigned char) *cur++);
n++;
}
fprintf(stderr, "\n");
cur = ctxt->input->cur;
n = 0;
while ((cur != base) && (n++ < 60)) {
fprintf(stderr, " ");
base++;
}
fprintf(stderr,"^\n");
}

70
include/libxml/entities.h Normal file
View File

@ -0,0 +1,70 @@
/*
* entities.h : interface for the XML entities handking
*
* See Copyright for the status of this software.
*
* $Id$
*/
#ifndef __XML_ENTITIES_H__
#define __XML_ENTITIES_H__
#include "parser.h"
#ifdef __cplusplus
extern "C" {
#endif
#define XML_INTERNAL_GENERAL_ENTITY 1
#define XML_EXTERNAL_GENERAL_PARSED_ENTITY 2
#define XML_EXTERNAL_GENERAL_UNPARSED_ENTITY 3
#define XML_INTERNAL_PARAMETER_ENTITY 4
#define XML_EXTERNAL_PARAMETER_ENTITY 5
/*
* An unit of storage for an entity, contains the string, the value
* and the linkind data needed for the linking in the hash table.
*/
typedef struct xmlEntity {
int type; /* The entity type */
int len; /* The lenght of the name */
const CHAR *name; /* Name of the entity */
const CHAR *ExternalID; /* External identifier for PUBLIC Entity */
const CHAR *SystemID; /* URI for a SYSTEM or PUBLIC Entity */
CHAR *content; /* The entity content or ndata if unparsed */
} xmlEntity, *xmlEntityPtr;
/*
* ALl entities are stored in a table there is one table per DTD
* and one extra per document.
*/
#define XML_MIN_ENTITIES_TABLE 32
typedef struct xmlEntitiesTable {
int nb_entities; /* number of elements stored */
int max_entities; /* maximum number of elements */
xmlEntityPtr table; /* the table of entities */
} xmlEntitiesTable, *xmlEntitiesTablePtr;
/*
* External functions :
*/
extern void xmlAddDocEntity(xmlDocPtr doc, const CHAR *name, int type,
const CHAR *ExternalID, const CHAR *SystemID, CHAR *content);
extern void xmlAddDtdEntity(xmlDocPtr doc, const CHAR *name, int type,
const CHAR *ExternalID, const CHAR *SystemID, CHAR *content);
extern xmlEntityPtr xmlGetDocEntity(xmlDocPtr doc, const CHAR *name);
extern xmlEntityPtr xmlGetDtdEntity(xmlDocPtr doc, const CHAR *name);
extern CHAR *xmlEncodeEntities(xmlDocPtr doc, const CHAR *input);
extern xmlEntitiesTablePtr xmlCreateEntitiesTable(void);
extern void xmlFreeEntitiesTable(xmlEntitiesTablePtr table);
extern void xmlDumpEntitiesTable(xmlEntitiesTablePtr table);
#ifdef __cplusplus
}
#endif
# endif /* __XML_ENTITIES_H__ */

168
include/libxml/parser.h Normal file
View File

@ -0,0 +1,168 @@
/*
* parser.h : constants and stuff related to the XML parser.
*
* See Copyright for the status of this software.
*
* $Id$
*/
#ifndef __XML_PARSER_H__
#define __XML_PARSER_H__
#include "tree.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Constants.
*/
#define XML_DEFAULT_VERSION "1.0"
typedef struct xmlParserInput {
const char *filename; /* The file analyzed, if any */
const CHAR *base; /* Base of the array to parse */
const CHAR *cur; /* Current char being parsed */
int line; /* Current line */
int col; /* Current column */
} xmlParserInput, *xmlParserInputPtr;
typedef struct xmlParserNodeInfo {
const struct xmlNode* node;
/* Position & line # that text that created the node begins & ends on */
unsigned long begin_pos;
unsigned long begin_line;
unsigned long end_pos;
unsigned long end_line;
} xmlParserNodeInfo;
typedef struct xmlParserNodeInfoSeq {
unsigned long maximum;
unsigned long length;
xmlParserNodeInfo* buffer;
} xmlParserNodeInfoSeq, *xmlParserNodeInfoSeqPtr;
typedef struct xmlParserCtxt {
struct xmlSAXHandler *sax; /* The SAX handler */
xmlDocPtr doc; /* the document being built */
/* Input stream stack */
xmlParserInputPtr input; /* Current input stream */
int inputNr; /* Number of current input streams */
int inputMax; /* Max number of input streams */
xmlParserInputPtr *inputTab; /* stack of inputs */
/* Node analysis stack */
xmlNodePtr node; /* Current parsed Node */
int nodeNr; /* Depth of the parsing stack */
int nodeMax; /* Max depth of the parsing stack */
xmlNodePtr *nodeTab; /* array of nodes */
int record_info; /* Whether node info should be kept */
xmlParserNodeInfoSeq node_seq; /* info about each node parsed */
} xmlParserCtxt, *xmlParserCtxtPtr;
/*
* a SAX Locator.
*/
typedef struct xmlSAXLocator {
const CHAR *(*getPublicId)(xmlParserCtxtPtr ctxt);
const CHAR *(*getSystemId)(xmlParserCtxtPtr ctxt);
int (*getLineNumber)(xmlParserCtxtPtr ctxt);
int (*getColumnNumber)(xmlParserCtxtPtr ctxt);
} xmlSAXLocator, *xmlSAXLocatorPtr;
/*
* a SAX Exception.
*/
typedef xmlParserInputPtr (*resolveEntitySAXFunc) (xmlParserCtxtPtr ctxt,
const CHAR *publicId, const CHAR *systemId);
typedef void (*notationDeclSAXFunc)(xmlParserCtxtPtr ctxt, const CHAR *name,
const CHAR *publicId, const CHAR *systemId);
typedef void (*unparsedEntityDeclSAXFunc)(xmlParserCtxtPtr ctxt,
const CHAR *name, const CHAR *publicId,
const CHAR *systemId, const CHAR *notationName);
typedef void (*setDocumentLocatorSAXFunc) (xmlParserCtxtPtr ctxt,
xmlSAXLocatorPtr loc);
typedef void (*startDocumentSAXFunc) (xmlParserCtxtPtr ctxt);
typedef void (*endDocumentSAXFunc) (xmlParserCtxtPtr ctxt);
typedef void (*startElementSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *name);
typedef void (*endElementSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *name);
typedef void (*charactersSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *ch,
int start, int len);
typedef void (*ignorableWhitespaceSAXFunc) (xmlParserCtxtPtr ctxt,
const CHAR *ch, int start, int len);
typedef void (*processingInstructionSAXFunc) (xmlParserCtxtPtr ctxt,
const CHAR *target, const CHAR *data);
typedef void (*warningSAXFunc) (xmlParserCtxtPtr ctxt, const char *msg, ...);
typedef void (*errorSAXFunc) (xmlParserCtxtPtr ctxt, const char *msg, ...);
typedef void (*fatalErrorSAXFunc) (xmlParserCtxtPtr ctxt, const char *msg, ...);
typedef struct xmlSAXHandler {
resolveEntitySAXFunc resolveEntity;
notationDeclSAXFunc notationDecl;
unparsedEntityDeclSAXFunc unparsedEntityDecl;
setDocumentLocatorSAXFunc setDocumentLocator;
startDocumentSAXFunc startDocument;
endDocumentSAXFunc endDocument;
startElementSAXFunc startElement;
endElementSAXFunc endElement;
charactersSAXFunc characters;
ignorableWhitespaceSAXFunc ignorableWhitespace;
processingInstructionSAXFunc processingInstruction;
warningSAXFunc warning;
errorSAXFunc error;
fatalErrorSAXFunc fatalError;
} xmlSAXHandler, *xmlSAXHandlerPtr;
/*
* Global variables: just the SAX interface tables we are looking for full
* reentrancy of the code !
*/
xmlSAXLocator xmlDefaultSAXLocator;
xmlSAXHandler xmlDefaultSAXHandler;
/*
* Interfaces
*/
extern int xmlParseDocument(xmlParserCtxtPtr ctxt);
extern xmlDocPtr xmlParseDoc(CHAR *cur);
extern xmlDocPtr xmlParseMemory(char *buffer, int size);
extern xmlDocPtr xmlParseFile(const char *filename);
extern CHAR *xmlStrdup(const CHAR *input);
extern CHAR *xmlStrndup(const CHAR *input, int n);
extern CHAR *xmlStrchr(const CHAR *str, CHAR val);
extern int xmlStrcmp(const CHAR *str1, const CHAR *str2);
extern int xmlStrncmp(const CHAR *str1, const CHAR *str2, int len);
extern int xmlStrlen(const CHAR *str);
extern CHAR *xmlStrcat(CHAR *cur, const CHAR *add);
extern CHAR *xmlStrncat(CHAR *cur, const CHAR *add, int len);
extern void xmlInitParserCtxt(xmlParserCtxtPtr ctx);
extern void xmlClearParserCtxt(xmlParserCtxtPtr ctx);
extern void xmlSetupParserForBuffer(xmlParserCtxtPtr ctx, const CHAR* buffer,
const char* filename);
extern void xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...);
extern const xmlParserNodeInfo* xmlParserFindNodeInfo(const xmlParserCtxt* c,
const xmlNode* node);
extern void xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
extern void xmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeq* seq,
const xmlNode* node);
extern void xmlParserAddNodeInfo(xmlParserCtxtPtr ctx,
const xmlParserNodeInfo* info);
extern void xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...);
extern void xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...);
extern void xmlDefaultSAXHandlerInit(void);
#ifdef __cplusplus
}
#endif
#endif /* __XML_PARSER_H__ */

180
include/libxml/tree.h Normal file
View File

@ -0,0 +1,180 @@
/*
* tree.h : describes the structures found in an tree resulting
* from an XML parsing.
*
* See Copyright for the status of this software.
*
* $Id$
*/
#ifndef __XML_TREE_H__
#define __XML_TREE_H__
#ifdef __cplusplus
extern "C" {
#endif
/*
* Type definitions
*/
#ifdef UNICODE
typedef unsigned short CHAR;
#else
typedef unsigned char CHAR;
#endif
/*
* a DTD Notation definition
* TODO !!!!
*/
/*
* a DTD Attribute definition
* TODO !!!!
*/
/*
* a DTD Element definition.
*/
#define XML_ELEMENT_TYPE_EMPTY 1
#define XML_ELEMENT_TYPE_ANY 2
#define XML_ELEMENT_TYPE_MIXED 3
#define XML_ELEMENT_TYPE_ELEMENT 4
typedef struct xmlElement {
const CHAR *name; /* Element name */
int type; /* type (too simple, to extend ...) */
/* TODO !!! more needed */
} xmlElement, *xmlElementPtr;
/*
* An XML namespace.
* Note that prefix == NULL is valid, it defines the default namespace
* within the subtree (until overriden).
*/
#define XML_GLOBAL_NAMESPACE 1 /* old style global namespace */
#define XML_LOCAL_NAMESPACE 2 /* new style local scoping */
typedef struct xmlNs {
struct xmlNs *next; /* next Ns link for this node */
int type; /* global or local */
const CHAR *href; /* URL for the namespace */
const CHAR *prefix; /* prefix for the namespace */
} xmlNs, *xmlNsPtr;
/*
* An XML DtD, as defined by <!DOCTYPE.
*/
typedef struct xmlDtd {
const CHAR *name; /* Name of the DTD */
const CHAR *ExternalID; /* External identifier for PUBLIC DTD */
const CHAR *SystemID; /* URI for a SYSTEM or PUBLIC DTD */
void *elements; /* Hash table for elements if any */
void *entities; /* Hash table for entities if any */
/* struct xmlDtd *next; * next link for this document */
} xmlDtd, *xmlDtdPtr;
/*
* A attribute of an XML node.
*/
typedef struct xmlAttr {
struct xmlNode *node; /* attr->node link */
struct xmlAttr *next; /* parent->childs link */
const CHAR *name; /* the name of the property */
const CHAR *value; /* the value of the property */
} xmlAttr, *xmlAttrPtr;
/*
* A node in an XML tree.
*/
#define XML_TYPE_TEXT 1
#define XML_TYPE_COMMENT 2
#define XML_TYPE_ENTITY 3
typedef struct xmlNode {
struct xmlNode *parent; /* child->parent link */
struct xmlNode *next; /* next sibling link */
struct xmlNode *childs; /* parent->childs link */
struct xmlAttr *properties; /* properties list */
int type; /* type number in the DTD */
const CHAR *name; /* the name of the node, or the entity */
xmlNs *ns; /* pointer to the associated namespace */
xmlNs *nsDef; /* namespace definitions on this node */
CHAR *content; /* the content */
} xmlNode, *xmlNodePtr;
/*
* An XML document.
*/
typedef struct xmlDoc {
char *name; /* name/filename/URI of the document */
const CHAR *version; /* the XML version string */
const CHAR *encoding; /* encoding, if any */
int standalone; /* standalone document (no external refs) */
struct xmlDtd *dtd; /* the document DTD if available */
struct xmlNs *oldNs; /* Global namespace, the old way */
void *entities; /* Hash table for general entities if any */
struct xmlNode *root; /* the document tree */
} xmlDoc, *xmlDocPtr;
/*
* Variables.
*/
extern xmlNsPtr baseDTD;
extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
/*
* Functions.
*/
extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
const CHAR *ExternalID, const CHAR *SystemID);
extern void xmlFreeDtd(xmlDtdPtr cur);
extern xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *AS);
extern xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *AS);
extern void xmlFreeNs(xmlNsPtr cur);
extern xmlDocPtr xmlNewDoc(const CHAR *version);
extern void xmlFreeDoc(xmlDocPtr cur);
extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
const CHAR *value);
extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
const CHAR *value);
extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
extern void xmlFreePropList(xmlAttrPtr cur);
extern void xmlFreeProp(xmlAttrPtr cur);
extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content);
extern xmlNodePtr xmlNewText(const CHAR *content);
extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
extern xmlNodePtr xmlNewComment(CHAR *content);
extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
extern int xmlNodeIsText(xmlNodePtr node);
extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
extern void xmlFreeNodeList(xmlNodePtr cur);
extern void xmlFreeNode(xmlNodePtr cur);
extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
const CHAR *nameSpace);
extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
const CHAR *href);
extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
const CHAR *name, CHAR *content);
extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
extern void xmlDocDump(FILE *f, xmlDocPtr doc);
extern void xmlBufferWriteCHAR(const CHAR *string);
extern void xmlBufferWriteChar(const char *string);
#ifdef __cplusplus
}
#endif
#endif /* __XML_TREE_H__ */

3334
parser.c Normal file

File diff suppressed because it is too large Load Diff

168
parser.h Normal file
View File

@ -0,0 +1,168 @@
/*
* parser.h : constants and stuff related to the XML parser.
*
* See Copyright for the status of this software.
*
* $Id$
*/
#ifndef __XML_PARSER_H__
#define __XML_PARSER_H__
#include "tree.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Constants.
*/
#define XML_DEFAULT_VERSION "1.0"
typedef struct xmlParserInput {
const char *filename; /* The file analyzed, if any */
const CHAR *base; /* Base of the array to parse */
const CHAR *cur; /* Current char being parsed */
int line; /* Current line */
int col; /* Current column */
} xmlParserInput, *xmlParserInputPtr;
typedef struct xmlParserNodeInfo {
const struct xmlNode* node;
/* Position & line # that text that created the node begins & ends on */
unsigned long begin_pos;
unsigned long begin_line;
unsigned long end_pos;
unsigned long end_line;
} xmlParserNodeInfo;
typedef struct xmlParserNodeInfoSeq {
unsigned long maximum;
unsigned long length;
xmlParserNodeInfo* buffer;
} xmlParserNodeInfoSeq, *xmlParserNodeInfoSeqPtr;
typedef struct xmlParserCtxt {
struct xmlSAXHandler *sax; /* The SAX handler */
xmlDocPtr doc; /* the document being built */
/* Input stream stack */
xmlParserInputPtr input; /* Current input stream */
int inputNr; /* Number of current input streams */
int inputMax; /* Max number of input streams */
xmlParserInputPtr *inputTab; /* stack of inputs */
/* Node analysis stack */
xmlNodePtr node; /* Current parsed Node */
int nodeNr; /* Depth of the parsing stack */
int nodeMax; /* Max depth of the parsing stack */
xmlNodePtr *nodeTab; /* array of nodes */
int record_info; /* Whether node info should be kept */
xmlParserNodeInfoSeq node_seq; /* info about each node parsed */
} xmlParserCtxt, *xmlParserCtxtPtr;
/*
* a SAX Locator.
*/
typedef struct xmlSAXLocator {
const CHAR *(*getPublicId)(xmlParserCtxtPtr ctxt);
const CHAR *(*getSystemId)(xmlParserCtxtPtr ctxt);
int (*getLineNumber)(xmlParserCtxtPtr ctxt);
int (*getColumnNumber)(xmlParserCtxtPtr ctxt);
} xmlSAXLocator, *xmlSAXLocatorPtr;
/*
* a SAX Exception.
*/
typedef xmlParserInputPtr (*resolveEntitySAXFunc) (xmlParserCtxtPtr ctxt,
const CHAR *publicId, const CHAR *systemId);
typedef void (*notationDeclSAXFunc)(xmlParserCtxtPtr ctxt, const CHAR *name,
const CHAR *publicId, const CHAR *systemId);
typedef void (*unparsedEntityDeclSAXFunc)(xmlParserCtxtPtr ctxt,
const CHAR *name, const CHAR *publicId,
const CHAR *systemId, const CHAR *notationName);
typedef void (*setDocumentLocatorSAXFunc) (xmlParserCtxtPtr ctxt,
xmlSAXLocatorPtr loc);
typedef void (*startDocumentSAXFunc) (xmlParserCtxtPtr ctxt);
typedef void (*endDocumentSAXFunc) (xmlParserCtxtPtr ctxt);
typedef void (*startElementSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *name);
typedef void (*endElementSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *name);
typedef void (*charactersSAXFunc) (xmlParserCtxtPtr ctxt, const CHAR *ch,
int start, int len);
typedef void (*ignorableWhitespaceSAXFunc) (xmlParserCtxtPtr ctxt,
const CHAR *ch, int start, int len);
typedef void (*processingInstructionSAXFunc) (xmlParserCtxtPtr ctxt,
const CHAR *target, const CHAR *data);
typedef void (*warningSAXFunc) (xmlParserCtxtPtr ctxt, const char *msg, ...);
typedef void (*errorSAXFunc) (xmlParserCtxtPtr ctxt, const char *msg, ...);
typedef void (*fatalErrorSAXFunc) (xmlParserCtxtPtr ctxt, const char *msg, ...);
typedef struct xmlSAXHandler {
resolveEntitySAXFunc resolveEntity;
notationDeclSAXFunc notationDecl;
unparsedEntityDeclSAXFunc unparsedEntityDecl;
setDocumentLocatorSAXFunc setDocumentLocator;
startDocumentSAXFunc startDocument;
endDocumentSAXFunc endDocument;
startElementSAXFunc startElement;
endElementSAXFunc endElement;
charactersSAXFunc characters;
ignorableWhitespaceSAXFunc ignorableWhitespace;
processingInstructionSAXFunc processingInstruction;
warningSAXFunc warning;
errorSAXFunc error;
fatalErrorSAXFunc fatalError;
} xmlSAXHandler, *xmlSAXHandlerPtr;
/*
* Global variables: just the SAX interface tables we are looking for full
* reentrancy of the code !
*/
xmlSAXLocator xmlDefaultSAXLocator;
xmlSAXHandler xmlDefaultSAXHandler;
/*
* Interfaces
*/
extern int xmlParseDocument(xmlParserCtxtPtr ctxt);
extern xmlDocPtr xmlParseDoc(CHAR *cur);
extern xmlDocPtr xmlParseMemory(char *buffer, int size);
extern xmlDocPtr xmlParseFile(const char *filename);
extern CHAR *xmlStrdup(const CHAR *input);
extern CHAR *xmlStrndup(const CHAR *input, int n);
extern CHAR *xmlStrchr(const CHAR *str, CHAR val);
extern int xmlStrcmp(const CHAR *str1, const CHAR *str2);
extern int xmlStrncmp(const CHAR *str1, const CHAR *str2, int len);
extern int xmlStrlen(const CHAR *str);
extern CHAR *xmlStrcat(CHAR *cur, const CHAR *add);
extern CHAR *xmlStrncat(CHAR *cur, const CHAR *add, int len);
extern void xmlInitParserCtxt(xmlParserCtxtPtr ctx);
extern void xmlClearParserCtxt(xmlParserCtxtPtr ctx);
extern void xmlSetupParserForBuffer(xmlParserCtxtPtr ctx, const CHAR* buffer,
const char* filename);
extern void xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...);
extern const xmlParserNodeInfo* xmlParserFindNodeInfo(const xmlParserCtxt* c,
const xmlNode* node);
extern void xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
extern void xmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeq* seq,
const xmlNode* node);
extern void xmlParserAddNodeInfo(xmlParserCtxtPtr ctx,
const xmlParserNodeInfo* info);
extern void xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...);
extern void xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...);
extern void xmlDefaultSAXHandlerInit(void);
#ifdef __cplusplus
}
#endif
#endif /* __XML_PARSER_H__ */

View File

@ -1,10 +1,5 @@
------- test/dav1 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.foo.bar/boxschema" prefix="R"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:multistatus>
<D:multistatus xmlns:D="http://www.ietf.org/standards/dav/" xmlns:R="http://www.foo.bar/boxschema">
<D:response>
<D:prop>
<R:bigbox>

View File

@ -1,8 +1,4 @@
------- test/dav10 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:owner>
<D:owner xmlns:D="http://www.ietf.org/standards/dav/">
<D:href>http://www.ics.uci.edu/~ejw/contact.html</D:href>
</D:owner>

View File

@ -1,9 +1,5 @@
------- test/dav11 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:prop>
<D:prop xmlns:D="http://www.ietf.org/standards/dav/">
<D:lockdiscovery>
<D:activelock>
<D:locktype>write</D:locktype>

View File

@ -1,6 +1,2 @@
------- test/dav12 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:href>http://www.ics.uci.edu/~ejw/contact.html</D:href>
<D:href xmlns:D="http://www.ietf.org/standards/dav/">http://www.ics.uci.edu/~ejw/contact.html</D:href>

View File

@ -1,9 +1,5 @@
------- test/dav13 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:multistatus>
<D:multistatus xmlns:D="http://www.ietf.org/standards/dav/">
<D:response>
<D:href>
http://webdav.sb.aol.com/workspace/webdav/proposal.doc

View File

@ -1,17 +0,0 @@
------- test/dav14 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/patch/" prefix="D"?>
<D:resourceupdate>
<D:replace XML-SPACE="PRESERVE">
<D:octet-range>14</D:octet-range>
003CTITLE003ENew
Title003C/TITLE003E </D:replace>
<D:delete>
<D:octet-range>38-50</D:octet-range>
</D:delete>
<D:insert XML-SPACE="PRESERVE">
<D:octet-range>86</D:octet-range>
003CP003ENew paragraph003C/P003E </D:insert>
</D:resourceupdate>

View File

@ -1,10 +1,5 @@
------- test/dav15 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.foocorp.com/Project/" prefix="F"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:prop>
<D:prop xmlns:D="http://www.ietf.org/standards/dav/" xmlns:F="http://www.foocorp.com/Project/">
<D:Source>
<D:link>
<F:projfiles>Source</F:projfiles>

View File

@ -1,9 +1,5 @@
------- test/dav16 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:propfind>
<D:propfind xmlns:D="http://www.ietf.org/standards/dav/">
<D:prop>
<lockdiscovery/>
</D:prop>

View File

@ -1,9 +1,5 @@
------- test/dav17 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:multistatus>
<D:multistatus xmlns:D="http://www.ietf.org/standards/dav/">
<D:response>
<D:prop>
<D:lockdiscovery>

View File

@ -1,9 +1,5 @@
------- test/dav18 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:propfind>
<D:propfind xmlns:D="http://www.ietf.org/standards/dav/">
<D:prop>
<supportedlock/>
</D:prop>

View File

@ -1,9 +1,5 @@
------- test/dav19 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:multistatus>
<D:multistatus xmlns:D="http://www.ietf.org/standards/dav/">
<D:response>
<D:prop>
<D:supportedlock>

View File

@ -1,10 +1,5 @@
------- test/dav2 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.foo.bar/boxschema/" prefix="R"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="S"?>
<S:multistatus>
<S:multistatus xmlns:S="http://www.ietf.org/standards/dav/" xmlns:R="http://www.foo.bar/boxschema/">
<S:response>
<S:href>http://www.foo.bar/container/</S:href>
<S:prop>

View File

@ -1,10 +1,5 @@
------- test/dav3 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.foo.bar/boxschema/" prefix="R"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:multistatus>
<D:multistatus xmlns:D="http://www.ietf.org/standards/dav/" xmlns:R="http://www.foo.bar/boxschema/">
<D:response>
<D:href>http://www.foo.bar/container/</D:href>
<D:prop>

View File

@ -1,10 +1,5 @@
------- test/dav4 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.w3.com/standards/z39.50/" prefix="Z"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:propertyupdate>
<D:propertyupdate xmlns:D="http://www.ietf.org/standards/dav/" xmlns:Z="http://www.w3.com/standards/z39.50/">
<D:set>
<D:prop>
<Z:authors>

View File

@ -1,10 +1,5 @@
------- test/dav5 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.w3.com/standards/z39.50/" prefix="Z"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:multistatus>
<D:multistatus xmlns:D="http://www.ietf.org/standards/dav/" xmlns:Z="http://www.w3.com/standards/z39.50/">
<D:response>
<D:prop>
<Z:Authors/>

View File

@ -1,9 +1,5 @@
------- test/dav6 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="D"?>
<D:multistatus>
<D:multistatus xmlns:D="http://www.ietf.org/standards/dav/">
<D:response>
<D:href>http://www.microsoft.com/user/yarong/dav_drafts/
</D:href>

View File

@ -1,9 +1,5 @@
------- test/dav7 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="d"?>
<d:multistatus>
<d:multistatus xmlns:d="http://www.ietf.org/standards/dav/">
<d:response>
<d:href>http://www.foo.bar/container/resource1</d:href>
<d:href>http://www.foo.bar/container/resource2</d:href>

View File

@ -1,9 +1,5 @@
------- test/dav8 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="d"?>
<d:multistatus>
<d:multistatus xmlns:d="http://www.ietf.org/standards/dav/">
<d:response>
<d:href>http://www.foo.bar/othercontainer/resource1</d:href>
<d:href>http://www.foo.bar/othercontainer/resource2</d:href>

View File

@ -1,9 +1,5 @@
------- test/dav9 -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.ietf.org/standards/dav/" prefix="d"?>
<d:multistatus>
<d:multistatus xmlns:d="http://www.ietf.org/standards/dav/">
<d:response>
<d:href>http://www.foo.bar/container/resource1</d:href>
<d:href>http://www.foo.bar/container/resource2</d:href>

3
result/dtd1 Normal file
View File

@ -0,0 +1,3 @@
<?xml version="1.0"?>
<!DOCTYPE MEMO PUBLIC "-//SGMLSOURCE//DTD MEMO//EN" "http://www.sgmlsource.com/dtds/memo.dtd">
<MEMO/>

7
result/ent1 Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE EXAMPLE SYSTEM "example.dtd" [
<!ENTITY xml "Extensible Markup Language">
]>
<EXAMPLE>
Extensible Markup Language
</EXAMPLE>

10
result/ent2 Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!DOCTYPE EXAMPLE SYSTEM "example.dtd" [
<!ENTITY xml "Extensible Markup Language">
<!ENTITY title PUBLIC "-//MY-TITLE//FR" "title.xml">
<!ENTITY image SYSTEM "img.gif" NDATA GIF>
]>
<EXAMPLE>
This text is about XML, the Extensible Markup Language and this is an embedded
</EXAMPLE>

7
result/ent3 Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE EXAMPLE SYSTEM "example.dtd" [
<!ENTITY xml "Extensible Markup Language">
]>
<EXAMPLE prop1="a&amp;b" prop2="Extensible Markup Language">
Test of entities in attributes.
</EXAMPLE>

View File

@ -1,26 +1,22 @@
------- test/p3p -----------
<?xml version="1.0"?>
<?xml:namespace ns="http://www.w3.org/TR/WD-rdf-syntax#" prefix="RDF"?>
<RDF:RDF>
<PROP assurance="http://www.TrustUs.org" agreeID="94df1293a3e519bb" entity="CoolCatalog" realm="http://www.CoolCatalog.com/catalogue/">
<RDF:RDF xmlns:p3p="http//www.w3.org/TR/1998/WD-P3P10-syntax#proposal.DTD" xmlns:RDF="http://www.w3.org/TR/WD-rdf-syntax#">
<PROP realm="http://www.CoolCatalog.com/catalogue/" entity="CoolCatalog" agreeID="94df1293a3e519bb" assurance="http://www.TrustUs.org">
<USES>
<STATEMENT consq="a site with clothes you&apos;d appreciate." id="0" recpnt="0" purp="2,3">
<STATEMENT purp="2,3" recpnt="0" id="0" consq="a site with clothes you&apos;d appreciate.">
<WITH>
<PREFIX name="User.">
<REF name="Name.First"/>
<REF optional="1" name="Bdate.Year"/>
<REF name="Bdate.Year" optional="1"/>
<REF name="Gender"/>
</PREFIX>
</WITH>
</STATEMENT>
</USES>
<USES>
<STATEMENT id="1" recpnt="0" purp="0" action="read&amp;write">
<STATEMENT action="read&amp;write" purp="0" recpnt="0" id="1">
<REF name="User.Shipping."/>
</STATEMENT>
</USES>
<DISCLOSURE other="0,1" access="3" discURI="http://www.CoolCatalog.com/PrivacyPractice.html"/>
<DISCLOSURE discURI="http://www.CoolCatalog.com/PrivacyPractice.html" access="3" other="0,1"/>
</PROP>
</RDF:RDF>

81
result/rdf1 Normal file
View File

@ -0,0 +1,81 @@
<?xml version="1.0"?>
<RDF:RDF xmlns:RPM="http://www.rpm.org/" xmlns:RDF="http://www.w3.org/TR/WD-rdf-syntax#">
<RDF:Description HREF="ftp://rufus.w3.org/linux/redhat/redhat-5.1/i386/RedHat/RPMS/rpm-2.5-2.i386.rpm">
<RPM:Name>rpm</RPM:Name>
<RPM:Version>2.5</RPM:Version>
<RPM:Release>2</RPM:Release>
<RPM:Arch>i386</RPM:Arch>
<RPM:Os>Linux</RPM:Os>
<RPM:Distribution>Manhattan </RPM:Distribution>
<RPM:Vendor>Red Hat Software</RPM:Vendor>
<RPM:Packager>Red Hat Software &lt;bugs@redhat.com&gt;</RPM:Packager>
<RPM:Group>Utilities/System</RPM:Group>
<RPM:Summary>Red Hat Package Manager</RPM:Summary>
<RPM:Description>RPM is a powerful package manager, which can be used to build, install,
query, verify, update, and uninstall individual software packages. A
package consists of an archive of files, and package information, including
name, version, and description.</RPM:Description>
<RPM:Copyright>GPL</RPM:Copyright>
<RPM:Changelog>* Sun May 10 1998 Prospector System &lt;bugs@redhat.com&gt;
- translations modified for de, fr, tr
</RPM:Changelog>
<RPM:Sources>rpm-2.5-2.src.rpm</RPM:Sources>
<RPM:SourcesFtp>ftp://ftp.redhat.com/pub/redhat/redhat-5.1/SRPMS</RPM:SourcesFtp>
<RPM:BuildDate>Sun May 10 14:52:32 1998</RPM:BuildDate>
<RPM:Date>894826352</RPM:Date>
<RPM:Size>850599</RPM:Size>
<RPM:BuildHost>porky.redhat.com</RPM:BuildHost>
<RPM:Provides>
<RDF:Bag>
<RPM:Resource>rpm</RPM:Resource>
</RDF:Bag>
</RPM:Provides>
<RPM:Requires>
<RDF:Bag>
<RPM:Resource>/bin/sh</RPM:Resource>
<RPM:Resource>ld-linux.so.2</RPM:Resource>
<RPM:Resource>libc.so.6</RPM:Resource>
<RPM:Resource>libdb.so.2</RPM:Resource>
<RPM:Resource>libz.so.1</RPM:Resource>
<RPM:Resource>/bin/bash</RPM:Resource>
<RPM:Resource>/bin/sh</RPM:Resource>
</RDF:Bag>
</RPM:Requires>
<RPM:Files>/bin/rpm
/usr/bin/find-provides
/usr/bin/find-requires
/usr/bin/gendiff
/usr/bin/rpm2cpio
/usr/doc/rpm-2.5
/usr/doc/rpm-2.5/CHANGES
/usr/doc/rpm-2.5/RPM-PGP-KEY
/usr/doc/rpm-2.5/buildroot
/usr/doc/rpm-2.5/dependencies
/usr/doc/rpm-2.5/format
/usr/doc/rpm-2.5/groups
/usr/doc/rpm-2.5/macros
/usr/doc/rpm-2.5/queryformat
/usr/doc/rpm-2.5/relocatable
/usr/doc/rpm-2.5/signatures
/usr/doc/rpm-2.5/spec
/usr/doc/rpm-2.5/triggers
/usr/lib/rpmpopt
/usr/lib/rpmrc
/usr/man/man8/rpm.8
/usr/man/man8/rpm2cpio.8
/usr/share/locale/de/LC_MESSAGES/rpm.mo
/usr/share/locale/fr/LC_MESSAGES/rpm.mo
/usr/share/locale/pt-br/LC_MESSAGES/rpm.mo
/usr/share/locale/sv/LC_MESSAGES/rpm.mo
/usr/share/locale/tr/LC_MESSAGES/rpm.mo
/usr/src/redhat
/usr/src/redhat/BUILD
/usr/src/redhat/RPMS
/usr/src/redhat/RPMS/i386
/usr/src/redhat/RPMS/noarch
/usr/src/redhat/SOURCES
/usr/src/redhat/SPECS
/usr/src/redhat/SRPMS
</RPM:Files>
</RDF:Description>
</RDF:RDF>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href ="http://www.ietf.org/standards/dav/" AS = "D"?>
<?namespace href = "http://www.foo.bar/boxschema" AS = "R"?>
<D:multistatus>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href="http://www.ietf.org/standards/dav/" AS = "D"?>
<D:owner>
<D:href>http://www.ics.uci.edu/~ejw/contact.html</D:href>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href ="http://www.ietf.org/standards/dav/" AS = "D"?>
<D:prop>
<D:lockdiscovery>

View File

@ -1,3 +1,3 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href="http://www.ietf.org/standards/dav/" AS = "D"?>
<D:href>http://www.ics.uci.edu/~ejw/contact.html</D:href>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href = "http://www.ietf.org/standards/dav/" AS = "D"?>
<D:multistatus>
<D:response>

View File

@ -1,10 +0,0 @@
<?XML version="1.0">
<?namespace href = "http://www.ietf.org/standards/dav/patch/" AS =
"D"?>
<D:resourceupdate>
<D:replace XML-SPACE = "PRESERVE">
<D:octet-range>14</D:octet-range>&003CTITLE&003ENew
Title&003C/TITLE&003E</D:replace>
<D:delete><D:octet-range>38-50</D:octet-range></D:delete>
<D:insert XML-SPACE = "PRESERVE"><D:octet-range>86</D:octet-range>&003CP&003ENew paragraph&003C/P&003E</D:insert>
</D:resourceupdate>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href = "http://www.ietf.org/standards/dav/" AS = "D"?>
<?namespace href = "http://www.foocorp.com/Project/" AS = "F"?>
<D:prop>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href = "http://www.ietf.org/standards/dav/" AS = "D"?>
<D:propfind>
<D:prop><lockdiscovery/></D:prop>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href ="http://www.ietf.org/standards/dav/" AS = "D"?>
<D:multistatus>
<D:response>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href = "http://www.ietf.org/standards/dav/" AS = "D"?>
<D:propfind>
<D:prop><supportedlock/></D:prop>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href ="http://www.ietf.org/standards/dav/" AS = "D"?>
<D:multistatus>
<D:response>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href = "http://www.ietf.org/standards/dav/" AS = "S"?>
<?namespace href = "http://www.foo.bar/boxschema/" AS = "R"?>
<S:multistatus>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href = "http://www.ietf.org/standards/dav/" AS = "D"?>
<?namespace href = "http://www.foo.bar/boxschema/" AS = "R"?>
<D:multistatus>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href = "http://www.ietf.org/standards/dav/" AS = "D"?>
<?namespace href = "http://www.w3.com/standards/z39.50/" AS = "Z"?>
<D:propertyupdate>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href="http://www.ietf.org/standards/dav/" AS = "D"?>
<?namespace href="http://www.w3.com/standards/z39.50/" AS = "Z"?>
<D:multistatus>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href = "http://www.ietf.org/standards/dav/" AS = "D"?>
<D:multistatus>
<D:response>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href = "http://www.ietf.org/standards/dav/" AS = "d"?>
<d:multistatus>
<d:response>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href = "http://www.ietf.org/standards/dav/" AS = "d"?>
<d:multistatus>
<d:response>

View File

@ -1,4 +1,4 @@
<?XML version="1.0">
<?XML version="1.0"?>
<?namespace href = "http://www.ietf.org/standards/dav/" AS = "d"?>
<d:multistatus>
<d:response>

5
test/dtd1 Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0"?>
<!DOCTYPE MEMO PUBLIC "-//SGMLSOURCE//DTD MEMO//EN"
"http://www.sgmlsource.com/dtds/memo.dtd">
<MEMO>
</MEMO>

7
test/ent1 Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE EXAMPLE SYSTEM "example.dtd" [
<!ENTITY xml "Extensible Markup Language">
]>
<EXAMPLE>
&xml;
</EXAMPLE>

11
test/ent2 Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE EXAMPLE SYSTEM "example.dtd" [
<!ENTITY xml "Extensible Markup Language">
<!ENTITY title PUBLIC "-//MY-TITLE//FR" "title.xml">
<!ENTITY image SYSTEM "img.gif" NDATA GIF>
]>
<EXAMPLE>
&title;
This text is about XML, the &xml; and this is an embedded &image;
</EXAMPLE>

8
test/ent3 Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!DOCTYPE EXAMPLE SYSTEM "example.dtd" [
<!ENTITY xml "Extensible Markup Language">
]>
<EXAMPLE prop1="a&amp;b" prop2="&xml;">
Test of entities in attributes.
</EXAMPLE>

View File

@ -1,3 +1,4 @@
<?xml version="1.0"?>
<?xml:namespace ns="http//www.w3.org/TR/1998/WD-P3P10-syntax#proposal.DTD" prefix="p3p"?>
<?xml:namespace ns="http://www.w3.org/TR/WD-rdf-syntax#" prefix="RDF"?>
<RDF:RDF><PROP realm="http://www.CoolCatalog.com/catalogue/"

83
test/rdf1 Normal file
View File

@ -0,0 +1,83 @@
<?XML version="1.0"?>
<?namespace href="http://www.rpm.org/" AS="RPM"?>
<?namespace href="http://www.w3.org/TR/WD-rdf-syntax#" AS="RDF"?>
<RDF:RDF>
<RDF:Description RDF:HREF="ftp://rufus.w3.org/linux/redhat/redhat-5.1/i386/RedHat/RPMS/rpm-2.5-2.i386.rpm">
<RPM:Name>rpm</RPM:Name>
<RPM:Version>2.5</RPM:Version>
<RPM:Release>2</RPM:Release>
<RPM:Arch>i386</RPM:Arch>
<RPM:Os>Linux</RPM:Os>
<RPM:Distribution>Manhattan </RPM:Distribution>
<RPM:Vendor>Red Hat Software</RPM:Vendor>
<RPM:Packager>Red Hat Software &lt;bugs@redhat.com&gt;</RPM:Packager>
<RPM:Group>Utilities/System</RPM:Group>
<RPM:Summary>Red Hat Package Manager</RPM:Summary>
<RPM:Description>RPM is a powerful package manager, which can be used to build, install,
query, verify, update, and uninstall individual software packages. A
package consists of an archive of files, and package information, including
name, version, and description.</RPM:Description>
<RPM:Copyright>GPL</RPM:Copyright>
<RPM:Changelog>* Sun May 10 1998 Prospector System &lt;bugs@redhat.com&gt;
- translations modified for de, fr, tr
</RPM:Changelog>
<RPM:Sources>rpm-2.5-2.src.rpm</RPM:Sources>
<RPM:SourcesFtp>ftp://ftp.redhat.com/pub/redhat/redhat-5.1/SRPMS</RPM:SourcesFtp>
<RPM:BuildDate>Sun May 10 14:52:32 1998</RPM:BuildDate>
<RPM:Date>894826352</RPM:Date>
<RPM:Size>850599</RPM:Size>
<RPM:BuildHost>porky.redhat.com</RPM:BuildHost>
<RPM:Provides>
<RDF:Bag>
<RPM:Resource>rpm</RPM:Resource>
</RDF:Bag>
</RPM:Provides>
<RPM:Requires>
<RDF:Bag>
<RPM:Resource>/bin/sh</RPM:Resource>
<RPM:Resource>ld-linux.so.2</RPM:Resource>
<RPM:Resource>libc.so.6</RPM:Resource>
<RPM:Resource>libdb.so.2</RPM:Resource>
<RPM:Resource>libz.so.1</RPM:Resource>
<RPM:Resource>/bin/bash</RPM:Resource>
<RPM:Resource>/bin/sh</RPM:Resource>
</RDF:Bag>
</RPM:Requires>
<RPM:Files>/bin/rpm
/usr/bin/find-provides
/usr/bin/find-requires
/usr/bin/gendiff
/usr/bin/rpm2cpio
/usr/doc/rpm-2.5
/usr/doc/rpm-2.5/CHANGES
/usr/doc/rpm-2.5/RPM-PGP-KEY
/usr/doc/rpm-2.5/buildroot
/usr/doc/rpm-2.5/dependencies
/usr/doc/rpm-2.5/format
/usr/doc/rpm-2.5/groups
/usr/doc/rpm-2.5/macros
/usr/doc/rpm-2.5/queryformat
/usr/doc/rpm-2.5/relocatable
/usr/doc/rpm-2.5/signatures
/usr/doc/rpm-2.5/spec
/usr/doc/rpm-2.5/triggers
/usr/lib/rpmpopt
/usr/lib/rpmrc
/usr/man/man8/rpm.8
/usr/man/man8/rpm2cpio.8
/usr/share/locale/de/LC_MESSAGES/rpm.mo
/usr/share/locale/fr/LC_MESSAGES/rpm.mo
/usr/share/locale/pt-br/LC_MESSAGES/rpm.mo
/usr/share/locale/sv/LC_MESSAGES/rpm.mo
/usr/share/locale/tr/LC_MESSAGES/rpm.mo
/usr/src/redhat
/usr/src/redhat/BUILD
/usr/src/redhat/RPMS
/usr/src/redhat/RPMS/i386
/usr/src/redhat/RPMS/noarch
/usr/src/redhat/SOURCES
/usr/src/redhat/SPECS
/usr/src/redhat/SRPMS
</RPM:Files>
</RDF:Description>
</RDF:RDF>

View File

@ -6,20 +6,33 @@
* $Id$
*/
#ifdef WIN32
#define HAVE_FCNTL_H
#include <io.h>
#else
#include <config.h>
#endif
#include <sys/types.h>
#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
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include "xml_parser.h"
#include "xml_tree.h"
#include "parser.h"
#include "tree.h"
#define MAX_BUF 500000
static CHAR buffer[MAX_BUF] =
/*
* Note: there is a couple of errors introduced on purpose.
*/
static CHAR buffer[] =
"\n\
<?xml version=\"1.0\">\n\
<?xml:namespace ns = \"http://www.ietf.org/standards/dav/\" prefix = \"D\"?>\n\
@ -40,37 +53,31 @@ static CHAR buffer[MAX_BUF] =
\n\
";
int readFile(char *filename) {
int input;
int res;
memset(buffer, 0, sizeof(buffer));
input = open (filename, O_RDONLY);
if (input < 0) {
fprintf (stderr, "Cannot read file %s :\n", filename);
perror ("open failed");
return(-1);
}
res = read(input, buffer, sizeof(buffer));
if (res < 0) {
fprintf (stderr, "Cannot read file %s :\n", filename);
perror ("read failed");
return(-1);
}
if (res >= MAX_BUF) {
fprintf (stderr, "Read only %d byte of %s, increase MAX_BUF\n",
res, filename);
return(-1);
}
close(input);
return(res);
}
void parseAndPrint(CHAR *buf) {
void parseAndPrintFile(char *filename) {
xmlDocPtr doc;
/*
* build a fake XML document from a string;
* build an XML tree from a string;
*/
doc = xmlParseFile(filename);
/*
* print it.
*/
xmlDocDump(stdout, doc);
/*
* free it.
*/
xmlFreeDoc(doc);
}
void parseAndPrintBuffer(CHAR *buf) {
xmlDocPtr doc;
/*
* build an XML tree from a string;
*/
doc = xmlParseDoc(buf);
@ -90,13 +97,10 @@ int main(int argc, char **argv) {
if (argc > 1) {
for (i = 1; i < argc ; i++) {
if (readFile(argv[i]) >= 0) {
printf("\n\n------- %s -----------\n", argv[i]);
parseAndPrint(buffer);
}
parseAndPrintFile(argv[i]);
}
} else
parseAndPrint(buffer);
parseAndPrintBuffer(buffer);
return(0);
}

1209
tree.c Normal file

File diff suppressed because it is too large Load Diff

180
tree.h Normal file
View File

@ -0,0 +1,180 @@
/*
* tree.h : describes the structures found in an tree resulting
* from an XML parsing.
*
* See Copyright for the status of this software.
*
* $Id$
*/
#ifndef __XML_TREE_H__
#define __XML_TREE_H__
#ifdef __cplusplus
extern "C" {
#endif
/*
* Type definitions
*/
#ifdef UNICODE
typedef unsigned short CHAR;
#else
typedef unsigned char CHAR;
#endif
/*
* a DTD Notation definition
* TODO !!!!
*/
/*
* a DTD Attribute definition
* TODO !!!!
*/
/*
* a DTD Element definition.
*/
#define XML_ELEMENT_TYPE_EMPTY 1
#define XML_ELEMENT_TYPE_ANY 2
#define XML_ELEMENT_TYPE_MIXED 3
#define XML_ELEMENT_TYPE_ELEMENT 4
typedef struct xmlElement {
const CHAR *name; /* Element name */
int type; /* type (too simple, to extend ...) */
/* TODO !!! more needed */
} xmlElement, *xmlElementPtr;
/*
* An XML namespace.
* Note that prefix == NULL is valid, it defines the default namespace
* within the subtree (until overriden).
*/
#define XML_GLOBAL_NAMESPACE 1 /* old style global namespace */
#define XML_LOCAL_NAMESPACE 2 /* new style local scoping */
typedef struct xmlNs {
struct xmlNs *next; /* next Ns link for this node */
int type; /* global or local */
const CHAR *href; /* URL for the namespace */
const CHAR *prefix; /* prefix for the namespace */
} xmlNs, *xmlNsPtr;
/*
* An XML DtD, as defined by <!DOCTYPE.
*/
typedef struct xmlDtd {
const CHAR *name; /* Name of the DTD */
const CHAR *ExternalID; /* External identifier for PUBLIC DTD */
const CHAR *SystemID; /* URI for a SYSTEM or PUBLIC DTD */
void *elements; /* Hash table for elements if any */
void *entities; /* Hash table for entities if any */
/* struct xmlDtd *next; * next link for this document */
} xmlDtd, *xmlDtdPtr;
/*
* A attribute of an XML node.
*/
typedef struct xmlAttr {
struct xmlNode *node; /* attr->node link */
struct xmlAttr *next; /* parent->childs link */
const CHAR *name; /* the name of the property */
const CHAR *value; /* the value of the property */
} xmlAttr, *xmlAttrPtr;
/*
* A node in an XML tree.
*/
#define XML_TYPE_TEXT 1
#define XML_TYPE_COMMENT 2
#define XML_TYPE_ENTITY 3
typedef struct xmlNode {
struct xmlNode *parent; /* child->parent link */
struct xmlNode *next; /* next sibling link */
struct xmlNode *childs; /* parent->childs link */
struct xmlAttr *properties; /* properties list */
int type; /* type number in the DTD */
const CHAR *name; /* the name of the node, or the entity */
xmlNs *ns; /* pointer to the associated namespace */
xmlNs *nsDef; /* namespace definitions on this node */
CHAR *content; /* the content */
} xmlNode, *xmlNodePtr;
/*
* An XML document.
*/
typedef struct xmlDoc {
char *name; /* name/filename/URI of the document */
const CHAR *version; /* the XML version string */
const CHAR *encoding; /* encoding, if any */
int standalone; /* standalone document (no external refs) */
struct xmlDtd *dtd; /* the document DTD if available */
struct xmlNs *oldNs; /* Global namespace, the old way */
void *entities; /* Hash table for general entities if any */
struct xmlNode *root; /* the document tree */
} xmlDoc, *xmlDocPtr;
/*
* Variables.
*/
extern xmlNsPtr baseDTD;
extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
extern int xmlIndentTreeOutput; /* try to indent the tree dumps */
/*
* Functions.
*/
extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
const CHAR *ExternalID, const CHAR *SystemID);
extern void xmlFreeDtd(xmlDtdPtr cur);
extern xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *AS);
extern xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *AS);
extern void xmlFreeNs(xmlNsPtr cur);
extern xmlDocPtr xmlNewDoc(const CHAR *version);
extern void xmlFreeDoc(xmlDocPtr cur);
extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
const CHAR *value);
extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
const CHAR *value);
extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
extern void xmlFreePropList(xmlAttrPtr cur);
extern void xmlFreeProp(xmlAttrPtr cur);
extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content);
extern xmlNodePtr xmlNewText(const CHAR *content);
extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
extern xmlNodePtr xmlNewComment(CHAR *content);
extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
extern int xmlNodeIsText(xmlNodePtr node);
extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
extern void xmlFreeNodeList(xmlNodePtr cur);
extern void xmlFreeNode(xmlNodePtr cur);
extern void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
extern void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
extern void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
extern void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
const CHAR *nameSpace);
extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
const CHAR *href);
extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
const CHAR *name, CHAR *content);
extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
extern void xmlDocDump(FILE *f, xmlDocPtr doc);
extern void xmlBufferWriteCHAR(const CHAR *string);
extern void xmlBufferWriteChar(const char *string);
#ifdef __cplusplus
}
#endif
#endif /* __XML_TREE_H__ */

View File

@ -1,353 +0,0 @@
/*
* entities.c : implementation for the XML entities handking
*
* See Copyright for the status of this software.
*
* $Id$
*/
#include <stdio.h>
#include <malloc.h>
#include <strings.h>
#include "xml_entities.h"
/*
* A buffer used for converting entities to their equivalent and back.
*/
static CHAR *buffer = NULL;
static int buffer_size = 0;
void growBuffer(void) {
buffer_size *= 2;
buffer = (CHAR *) realloc(buffer, buffer_size * sizeof(CHAR));
if (buffer == NULL) {
perror("realloc failed");
exit(1);
}
}
/*
* xmlFreeEntity : clean-up an entity record.
*/
void xmlFreeEntity(xmlEntityPtr entity) {
if (entity == NULL) return;
if (entity->value != NULL) free(entity->value);
entity->value = NULL;
if (entity->id != NULL)
free((char *) entity->id);
}
/*
* xmlAddDocEntity : register a new entity for an entities table.
*/
static void xmlAddEntity(xmlEntitiesTablePtr table, CHAR *value,
const CHAR *id) {
int i;
xmlEntityPtr cur;
for (i = 0;i < table->nb_entities;i++) {
cur = &table->table[i];
if (!xmlStrcmp(cur->id, id)) {
free(cur->value);
cur->value = xmlStrdup(value);
}
}
if (table->nb_entities >= table->max_entities) {
/*
* need more elements.
*/
table->max_entities *= 2;
table->table = (xmlEntityPtr)
realloc(table->table, table->max_entities * sizeof(xmlEntity));
if (table->table) {
perror("realloc failed");
exit(1);
}
}
cur = &table->table[table->nb_entities];
cur->value = xmlStrdup(value);
cur->id = xmlStrdup(id);
table->nb_entities++;
}
/*
* xmlAddDtdEntity : register a new entity for this document.
*/
void xmlAddDtdEntity(xmlDtdPtr dtd, CHAR *value, const CHAR *id) {
xmlEntitiesTablePtr table;
table = (xmlEntitiesTablePtr) dtd->entities;
if (table == NULL) {
table = xmlCreateEntitiesTable();
dtd->entities = table;
}
xmlAddEntity(table, value, id);
}
/*
* xmlAddDocEntity : register a new entity for this document.
*/
void xmlAddDocEntity(xmlDocPtr doc, CHAR *value, const CHAR *id) {
xmlEntitiesTablePtr table;
table = (xmlEntitiesTablePtr) doc->entities;
if (table == NULL) {
table = xmlCreateEntitiesTable();
doc->entities = table;
}
xmlAddEntity(table, value, id);
}
/*
* xmlGetEntity : do an entity lookup in the hash table and
* returns the corrsponding CHAR *, if found, zero otherwise.
*/
CHAR *xmlGetEntity(xmlDocPtr doc, const CHAR *id) {
int i;
xmlEntityPtr cur;
xmlEntitiesTablePtr table;
if (doc->entities == NULL) return(0);
table = (xmlEntitiesTablePtr) doc->entities;
for (i = 0;i < table->nb_entities;i++) {
cur = &table->table[i];
if (!xmlStrcmp(cur->id, id)) return(cur->value);
}
return(NULL);
}
/*
* xmlReadEntities : read an entity.
*/
const CHAR *xmlReadEntity(xmlDocPtr doc, const CHAR **input) {
static CHAR *entity = NULL;
static int entity_size = 100;
const CHAR *cur = *input;
if (entity == NULL) {
entity = (CHAR *) malloc(entity_size * sizeof(CHAR));
if (entity == NULL) {
fprintf(stderr, "xmlReadEntity : cannot allocate %d bytes\n",
entity_size * sizeof(CHAR));
return(NULL);
}
}
if (*cur == '&') {
cur++;
if (*cur == '#') {
/* TODO !!!!
fprintf(stderr, "Character reference not yet implemented\n"); */
} else {
/* TODO !!!!
fprintf(stderr, "Entity search not yet implemented\n"); */
}
}
/*
* The few predefined entities.
*/
if ((cur[0] == 'a') && (cur[1] == 'm') && (cur[2] == 'p') &&
(cur[3] == ';')) {
entity[0] = '%';
entity[1] = 0;
cur += 3;
*input = cur;
return(entity);
} else if ((cur[0] == 'q') && (cur[1] == 'u') && (cur[2] == 'o') &&
(cur[3] == 't') && (cur[4] == ';')) {
entity[0] = '"';
entity[1] = 0;
cur += 4;
*input = cur;
return(entity);
} else if ((cur[0] == 'a') && (cur[1] == 'p') && (cur[2] == 'o') &&
(cur[3] == 's') && (cur[4] == ';')) {
entity[0] = '\'';
entity[1] = 0;
cur += 4;
*input = cur;
return(entity);
} else if ((cur[0] == 'l') && (cur[1] == 't') && (cur[2] == ';')) {
entity[0] = '<';
entity[1] = 0;
cur += 2;
*input = cur;
return(entity);
} else if ((cur[0] == 'g') && (cur[1] == 't') && (cur[2] == ';')) {
entity[0] = '>';
entity[1] = 0;
cur += 2;
*input = cur;
return(entity);
}
return(NULL);
}
/*
* xmlDecodeEntities : do a global entities lookup on a input string
* and returns a duplicate after the entities substitution.
*/
CHAR *xmlDecodeEntities(xmlDocPtr doc, const CHAR *input, int len) {
const CHAR *cur = input;
CHAR *out = buffer;
int i;
if (buffer == NULL) {
buffer_size = 1000;
buffer = (CHAR *) malloc(buffer_size * sizeof(CHAR));
if (buffer == NULL) {
perror("malloc failed");
exit(1);
}
out = buffer;
}
for (i = 0;(*cur != 0) && (cur - input < len);cur++) {
if (*cur == '&') {
const CHAR *entity = xmlReadEntity(doc, &cur);
if (entity != NULL)
while (*entity != 0) {
*out++ = *entity++;
i++;
if (i + 10 > buffer_size) {
int index = out - buffer;
growBuffer();
out = &buffer[index];
}
}
} else if (*cur == '%') {
/* TODO !!!!!
fprintf(stderr, " \n"); */
} else {
*out++ = *cur;
i++;
}
if (i + 10 > buffer_size) {
int index = out - buffer;
growBuffer();
out = &buffer[index];
}
}
*out++ = 0;
return(buffer);
}
/*
* xmlEncodeEntities : do a global encoding of a string, replacing the
* basic values with their entities form.
*/
CHAR *xmlEncodeEntities(xmlDocPtr doc, const CHAR *input) {
const CHAR *cur = input;
CHAR *out = buffer;
if (buffer == NULL) {
buffer_size = 1000;
buffer = (CHAR *) malloc(buffer_size * sizeof(CHAR));
if (buffer == NULL) {
perror("malloc failed");
exit(1);
}
out = buffer;
}
while (*cur != '\0') {
if (out - buffer > buffer_size - 100) {
int index = out - buffer;
growBuffer();
out = &buffer[index];
}
/*
* By default one have to encode at least '<', '>', '"' and '&' !
* One could try a better encoding using the entities defined and
* used as a compression code !!!.
*/
if (*cur == '<') {
*out++ = '&';
*out++ = 'l';
*out++ = 't';
*out++ = ';';
} else if (*cur == '>') {
*out++ = '&';
*out++ = 'g';
*out++ = 't';
*out++ = ';';
} else if (*cur == '&') {
*out++ = '&';
*out++ = 'a';
*out++ = 'm';
*out++ = 'p';
*out++ = ';';
} else if (*cur == '"') {
*out++ = '&';
*out++ = 'q';
*out++ = 'u';
*out++ = 'o';
*out++ = 't';
*out++ = ';';
} else if (*cur == '\'') {
*out++ = '&';
*out++ = 'a';
*out++ = 'p';
*out++ = 'o';
*out++ = 's';
*out++ = ';';
} else {
/*
* default case, just copy !
*/
*out++ = *cur;
}
cur++;
}
*out++ = 0;
return(buffer);
}
/*
* xmlCreateEntitiesTable : create and initialize an enmpty hash table
*/
xmlEntitiesTablePtr xmlCreateEntitiesTable(void) {
xmlEntitiesTablePtr ret;
ret = (xmlEntitiesTablePtr)
malloc(sizeof(xmlEntitiesTable));
if (ret == NULL) {
fprintf(stderr, "xmlCreateEntitiesTable : malloc(%d) failed\n",
sizeof(xmlEntitiesTable));
return(NULL);
}
ret->max_entities = XML_MIN_ENTITIES_TABLE;
ret->nb_entities = 0;
ret->table = (xmlEntityPtr )
malloc(ret->max_entities * sizeof(xmlEntity));
if (ret == NULL) {
fprintf(stderr, "xmlCreateEntitiesTable : malloc(%d) failed\n",
ret->max_entities * sizeof(xmlEntity));
free(ret);
return(NULL);
}
return(ret);
}
/*
* xmlFreeEntitiesTable : clean up and free an entities hash table.
*/
void xmlFreeEntitiesTable(xmlEntitiesTablePtr table) {
int i;
if (table == NULL) return;
for (i = 0;i < table->nb_entities;i++) {
xmlFreeEntity(&table->table[i]);
}
free(table->table);
free(table);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,61 +0,0 @@
/*
* parser.h : constants and stuff related to the XML parser.
*
* See Copyright for the status of this software.
*
* $Id$
*/
#ifndef __XML_PARSER_H__
#define __XML_PARSER_H__
#include "xml_tree.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Constants.
*/
#define XML_DEFAULT_VERSION "1.0"
typedef struct xmlParserCtxt {
const char *filename; /* The file analyzed, if any */
const CHAR *base; /* Base of the array to parse */
const CHAR *cur; /* Current char being parsed */
int line; /* Current line */
int col; /* Current column */
xmlDocPtr doc; /* the document being built */
int depth; /* Depth of current element */
int max_depth; /* Max depth allocated */
xmlNodePtr *nodes; /* The node hierarchy being built */
} xmlParserCtxt, *xmlParserCtxtPtr;
/*
* Interfaces
*/
extern int xmlParseDocument(xmlParserCtxtPtr ctxt);
extern xmlDocPtr xmlParseDoc(CHAR *cur);
extern xmlDocPtr xmlParseMemory(char *buffer, int size);
extern xmlDocPtr xmlParseFile(const char *filename);
extern CHAR *xmlStrdup(const CHAR *input);
extern CHAR *xmlStrndup(const CHAR *input, int n);
extern CHAR *xmlStrchr(const CHAR *str, CHAR val);
extern int xmlStrcmp(const CHAR *str1, const CHAR *str2);
extern int xmlStrncmp(const CHAR *str1, const CHAR *str2, int len);
extern void xmlInitParserCtxt(xmlParserCtxtPtr ctx);
extern void xmlClearParserCtxt(xmlParserCtxtPtr ctx);
extern void xmlSetupParserForBuffer(xmlParserCtxtPtr ctx, const CHAR* buffer,
const char* filename);
extern void xmlReportError(xmlParserCtxtPtr ctx, const CHAR* msg);
#ifdef __cplusplus
}
#endif
#endif /* __XML_PARSER_H__ */

View File

@ -1,731 +0,0 @@
/*
* tree.c : implemetation of access function for an XML tree.
*
* See Copyright for the status of this software.
*
* $Id$
*/
#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
#include <string.h> /* for memset() only ! */
#include "xml_tree.h"
#include "xml_entities.h"
static CHAR xmlStringText[] = { 't', 'e', 'x', 't', 0 };
int oldXMLWDcompatibility = 0;
/************************************************************************
* *
* Allocation and deallocation of basic structures *
* *
************************************************************************/
/*
* Creation of a new DTD.
*/
xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *href, const CHAR *AS) {
xmlDtdPtr cur;
/*
* Allocate a new DTD and fill the fields.
*/
cur = (xmlDtdPtr) malloc(sizeof(xmlDtd));
if (cur == NULL) {
fprintf(stderr, "xmlNewDtd : malloc failed\n");
return(NULL);
}
cur->next = NULL;
if (href != NULL)
cur->href = xmlStrdup(href);
else
cur->href = NULL;
if (AS != NULL)
cur->AS = xmlStrdup(AS);
else
cur->AS = NULL;
if (doc != NULL) {
cur->next = doc->dtds;
doc->dtds = cur;
}
return(cur);
}
/*
* Freeing a DTD
*/
void xmlFreeDtd(xmlDtdPtr cur) {
if (cur == NULL) {
fprintf(stderr, "xmlFreeDtd : DTD == NULL\n");
return;
}
if (cur->href != NULL) free((char *) cur->href);
if (cur->AS != NULL) free((char *) cur->AS);
memset(cur, -1, sizeof(xmlDtd));
free(cur);
}
/*
* Freeing a DTD list
*/
void xmlFreeDtdList(xmlDtdPtr cur) {
xmlDtdPtr next;
if (cur == NULL) {
fprintf(stderr, "xmlFreeDtdList : dtd == NULL\n");
return;
}
while (cur != NULL) {
next = cur->next;
xmlFreeDtd(cur);
cur = next;
}
}
/*
* Creation of a new document
*/
xmlDocPtr xmlNewDoc(const CHAR *version) {
xmlDocPtr cur;
if (version == NULL) {
fprintf(stderr, "xmlNewDoc : version == NULL\n");
return(NULL);
}
/*
* Allocate a new document and fill the fields.
*/
cur = (xmlDocPtr) malloc(sizeof(xmlDoc));
if (cur == NULL) {
fprintf(stderr, "xmlNewDoc : malloc failed\n");
return(NULL);
}
cur->version = xmlStrdup(version);
cur->root = NULL;
cur->dtds = NULL;
return(cur);
}
/*
* Freeing a document : all the tree is freed too.
*/
void xmlFreeDoc(xmlDocPtr cur) {
if (cur == NULL) {
fprintf(stderr, "xmlFreeDoc : document == NULL\n");
return;
}
free((char *) cur->version);
if (cur->root != NULL) xmlFreeNode(cur->root);
if (cur->dtds != NULL) xmlFreeDtdList(cur->dtds);
memset(cur, -1, sizeof(xmlDoc));
free(cur);
}
/*
* Creation of a new property element in a given DTD.
*/
xmlPropPtr xmlNewProp(xmlNodePtr node, const CHAR *name, const CHAR *value) {
xmlPropPtr cur;
if (name == NULL) {
fprintf(stderr, "xmlNewProp : name == NULL\n");
return(NULL);
}
/*
* Allocate a new property and fill the fields.
*/
cur = (xmlPropPtr) malloc(sizeof(xmlProp));
if (cur == NULL) {
fprintf(stderr, "xmlNewProp : malloc failed\n");
return(NULL);
}
cur->node = node;
cur->name = xmlStrdup(name);
if (value != NULL)
cur->value = xmlStrdup(value);
else
cur->value = NULL;
if (node != NULL) {
cur->next = node->properties;
node->properties = cur;
} else
cur->next = NULL;
return(cur);
}
/*
* Freeing a property list : Free a property and all its siblings,
* this is a recursive behaviour, all the childs
* are freed too.
*/
void xmlFreePropList(xmlPropPtr cur) {
xmlPropPtr next;
if (cur == NULL) {
fprintf(stderr, "xmlFreePropList : property == NULL\n");
return;
}
while (cur != NULL) {
next = cur->next;
xmlFreeProp(cur);
cur = next;
}
}
/*
* Freeing a property.
*/
void xmlFreeProp(xmlPropPtr cur) {
if (cur == NULL) {
fprintf(stderr, "xmlFreeProp : property == NULL\n");
return;
}
if (cur->name != NULL) free((char *) cur->name);
if (cur->value != NULL) free((char *) cur->value);
memset(cur, -1, sizeof(xmlProp));
free(cur);
}
/*
* Creation of a new node element in a given DTD.
* We don't assume that the "name" has already being strdup'd anymore !
*/
xmlNodePtr xmlNewNode(xmlDtdPtr dtd, const CHAR *name, CHAR *content) {
xmlNodePtr cur;
if (name == NULL) {
fprintf(stderr, "xmlNewNode : name == NULL\n");
return(NULL);
}
/*
* Allocate a new node and fill the fields.
*/
cur = (xmlNodePtr) malloc(sizeof(xmlNode));
if (cur == NULL) {
fprintf(stderr, "xmlNewNode : malloc failed\n");
return(NULL);
}
cur->parent = NULL;
cur->next = NULL;
cur->childs = NULL;
cur->properties = NULL;
cur->type = 0;
cur->name = xmlStrdup(name);
cur->dtd = dtd;
if (content != NULL)
cur->content = xmlStrdup(content);
else
cur->content = NULL;
return(cur);
}
/*
* Creation of a new node contening text.
*/
xmlNodePtr xmlNewText(CHAR *content) {
xmlNodePtr cur;
/*
* Allocate a new node and fill the fields.
*/
cur = (xmlNodePtr) malloc(sizeof(xmlNode));
if (cur == NULL) {
fprintf(stderr, "xmlNewNode : malloc failed\n");
return(NULL);
}
cur->parent = NULL;
cur->next = NULL;
cur->childs = NULL;
cur->properties = NULL;
cur->type = XML_TYPE_TEXT;
cur->name = xmlStrdup(xmlStringText);;
cur->dtd = NULL;
if (content != NULL)
cur->content = xmlStrdup(content);
else
cur->content = NULL;
return(cur);
}
/*
* Creation of a new child element, added at the end.
*/
xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlDtdPtr dtd,
const CHAR *name, CHAR *content) {
xmlNodePtr cur, prev;
if (parent == NULL) {
fprintf(stderr, "xmlNewChild : parent == NULL\n");
return(NULL);
}
if (name == NULL) {
fprintf(stderr, "xmlNewChild : name == NULL\n");
return(NULL);
}
/*
* Allocate a new node
*/
if (dtd == NULL)
cur = xmlNewNode(parent->dtd, name, content);
else
cur = xmlNewNode(dtd, name, content);
if (cur == NULL) return(NULL);
/*
* add the new element at the end of the childs list.
*/
cur->parent = parent;
if (parent->childs == NULL) {
parent->childs = cur;
} else {
prev = parent->childs;
while (prev->next != NULL) prev = prev->next;
prev->next = cur;
}
return(cur);
}
/*
* Add a new child element, added at the end.
*/
xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) {
xmlNodePtr prev;
if (parent == NULL) {
fprintf(stderr, "xmladdChild : parent == NULL\n");
return(NULL);
}
if (cur == NULL) {
fprintf(stderr, "xmladdChild : child == NULL\n");
return(NULL);
}
/*
* add the new element at the end of the childs list.
*/
cur->parent = parent;
if (parent->childs == NULL) {
parent->childs = cur;
} else {
prev = parent->childs;
while (prev->next != NULL) prev = prev->next;
prev->next = cur;
}
return(cur);
}
/*
* Freeing a node list : Free a node and all its siblings,
* this is a recursive behaviour, all the childs
* are freed too.
*/
void xmlFreeNodeList(xmlNodePtr cur) {
xmlNodePtr next;
if (cur == NULL) {
fprintf(stderr, "xmlFreeNodeList : node == NULL\n");
return;
}
while (cur != NULL) {
next = cur->next;
xmlFreeNode(cur);
cur = next;
}
}
/*
* Freeing a node : this is a recursive behaviour, all the childs
* are freed too.
*/
void xmlFreeNode(xmlNodePtr cur) {
if (cur == NULL) {
fprintf(stderr, "xmlFreeNode : node == NULL\n");
return;
}
if (cur->properties != NULL) xmlFreePropList(cur->properties);
if (cur->childs != NULL) xmlFreeNodeList(cur->childs);
if (cur->content != NULL) free(cur->content);
if (cur->name != NULL) free((char *) cur->name);
memset(cur, -1, sizeof(xmlNode));
free(cur);
}
/************************************************************************
* *
* Content access functions *
* *
************************************************************************/
/*
* Changing the content of a node.
*/
void xmlNodeSetContent(xmlNodePtr cur, CHAR *content) {
if (cur == NULL) {
fprintf(stderr, "xmlNodeSetContent : node == NULL\n");
return;
}
if (cur->content != NULL) free(cur->content);
if (content != NULL)
cur->content = xmlStrdup(content);
else
cur->content = NULL;
}
/*
* Search a Dtd registered under a given name space for a document.
*/
xmlDtdPtr xmlSearchDtd(xmlDocPtr doc, CHAR *nameSpace) {
xmlDtdPtr cur;
if ((doc == NULL) || (nameSpace == NULL)) return(NULL);
cur = doc->dtds;
while (cur != NULL) {
if ((cur->AS != NULL) && (!xmlStrcmp(cur->AS, nameSpace)))
return(cur);
cur = cur->next;
}
return(NULL);
}
/*
* Reading the content of a given property.
*/
const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name) {
xmlPropPtr prop = node->properties;
while (prop != NULL) {
if (!xmlStrcmp(prop->name, name)) return(prop->value);
prop = prop->next;
}
return(NULL);
}
/************************************************************************
* *
* Output : to a FILE or in memory *
* *
************************************************************************/
/*
* routine which manage and grows an output buffer. One can write
* standard char array's (8 bits char) or CHAR's arrays.
*/
static CHAR *buffer = NULL;
static int buffer_index = 0;
static int buffer_size = 0;
static void xmlBufferWriteCHAR(const CHAR *string) {
const CHAR *cur;
if (buffer == NULL) {
buffer_size = 50000;
buffer = (CHAR *) malloc(buffer_size * sizeof(CHAR));
if (buffer == NULL) {
fprintf(stderr, "xmlBufferWrite : out of memory!\n");
exit(1);
}
}
if (string == NULL) return;
for (cur = string;*cur != 0;cur++) {
if (buffer_index + 10 >= buffer_size) {
buffer_size *= 2;
buffer = (CHAR *) realloc(buffer, buffer_size * sizeof(CHAR));
if (buffer == NULL) {
fprintf(stderr, "xmlBufferWrite : out of memory!\n");
exit(1);
}
}
buffer[buffer_index++] = *cur;
}
buffer[buffer_index] = 0;
}
static void xmlBufferWriteChar(const char *string) {
const CHAR *cur;
if (buffer == NULL) {
buffer_size = 50000;
buffer = (CHAR *) malloc(buffer_size * sizeof(CHAR));
if (buffer == NULL) {
fprintf(stderr, "xmlBufferWrite : out of memory!\n");
exit(1);
}
}
if (string == NULL) return;
for (cur = string;*cur != 0;cur++) {
if (buffer_index + 10 >= buffer_size) {
buffer_size *= 2;
buffer = (CHAR *) realloc(buffer, buffer_size * sizeof(CHAR));
if (buffer == NULL) {
fprintf(stderr, "xmlBufferWrite : out of memory!\n");
exit(1);
}
}
buffer[buffer_index++] = *cur;
}
buffer[buffer_index] = 0;
}
/*
* Dump a DTD to the given FD
*/
static void xmlDtdDump(xmlDtdPtr cur) {
if (cur == NULL) {
fprintf(stderr, "xmlDtdDump : DTD == NULL\n");
return;
}
if (oldXMLWDcompatibility) {
xmlBufferWriteChar("<?namespace");
if (cur->href != NULL) {
xmlBufferWriteChar(" href=\"");
xmlBufferWriteCHAR(cur->href);
xmlBufferWriteChar("\"");
}
if (cur->AS != NULL) {
xmlBufferWriteChar(" AS=\"");
xmlBufferWriteCHAR(cur->AS);
xmlBufferWriteChar("\"");
}
xmlBufferWriteChar("?>\n");
} else {
xmlBufferWriteChar("<?xml:namespace");
if (cur->href != NULL) {
xmlBufferWriteChar(" ns=\"");
xmlBufferWriteCHAR(cur->href);
xmlBufferWriteChar("\"");
}
if (cur->AS != NULL) {
xmlBufferWriteChar(" prefix=\"");
xmlBufferWriteCHAR(cur->AS);
xmlBufferWriteChar("\"");
}
xmlBufferWriteChar("?>\n");
}
}
/*
* Dump an XML property to the given FD
*/
static void xmlPropDump(xmlDocPtr doc, xmlPropPtr cur) {
if (cur == NULL) {
fprintf(stderr, "xmlPropDump : property == NULL\n");
return;
}
xmlBufferWriteChar(" ");
xmlBufferWriteCHAR(cur->name);
if (cur->value) {
xmlBufferWriteChar("=\"");
xmlBufferWriteCHAR(xmlEncodeEntities(doc, cur->value));
xmlBufferWriteChar("\"");
}
}
/*
* Dump an XML property list to the given FD
*/
static void xmlPropListDump(xmlDocPtr doc, xmlPropPtr cur) {
if (cur == NULL) {
fprintf(stderr, "xmlPropListDump : property == NULL\n");
return;
}
while (cur != NULL) {
xmlPropDump(doc, cur);
cur = cur->next;
}
}
/*
* Dump an XML node list to the given FD
*/
static void xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level);
static void xmlNodeListDump(xmlDocPtr doc, xmlNodePtr cur, int level) {
if (cur == NULL) {
fprintf(stderr, "xmlNodeListDump : node == NULL\n");
return;
}
while (cur != NULL) {
xmlNodeDump(doc, cur, level);
cur = cur->next;
}
}
/*
* Dump an XML node to the given FD
*/
static void xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level) {
int i;
if (cur == NULL) {
fprintf(stderr, "xmlNodeDump : node == NULL\n");
return;
}
if (cur->type == XML_TYPE_TEXT) {
if (cur->content != NULL)
xmlBufferWriteCHAR(xmlEncodeEntities(doc, cur->content));
return;
}
for (i = 0;i < level;i++)
xmlBufferWriteChar(" ");
xmlBufferWriteChar("<");
if ((cur->dtd != NULL) && (cur->dtd->AS != NULL)) {
xmlBufferWriteCHAR(cur->dtd->AS);
xmlBufferWriteChar(":");
}
xmlBufferWriteCHAR(cur->name);
if (cur->properties != NULL)
xmlPropListDump(doc, cur->properties);
if ((cur->content == NULL) && (cur->childs == NULL)) {
xmlBufferWriteChar("/>\n");
return;
}
xmlBufferWriteChar(">");
if (cur->content != NULL)
xmlBufferWriteCHAR(xmlEncodeEntities(doc, cur->content));
if (cur->childs != NULL) {
xmlBufferWriteChar("\n");
xmlNodeListDump(doc, cur->childs, level + 1);
for (i = 0;i < level;i++)
xmlBufferWriteChar(" ");
}
xmlBufferWriteChar("</");
if ((cur->dtd != NULL) && (cur->dtd->AS != NULL)) {
xmlBufferWriteCHAR(cur->dtd->AS);
xmlBufferWriteChar(":");
}
xmlBufferWriteCHAR(cur->name);
xmlBufferWriteChar(">\n");
}
/*
* Dump an XML DTD list to the given FD
*/
static void xmlDtdListDump(xmlDtdPtr cur) {
if (cur == NULL) {
fprintf(stderr, "xmlDtdListDump : DTD == NULL\n");
return;
}
while (cur != NULL) {
xmlDtdDump(cur);
cur = cur->next;
}
}
/*
* Dump an XML document to memory.
*/
void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size) {
if (cur == NULL) {
fprintf(stderr, "xmlDocDump : document == NULL\n");
*mem = NULL;
*size = 0;
return;
}
buffer_index = 0;
if (oldXMLWDcompatibility)
xmlBufferWriteChar("<?XML version=\"");
else
xmlBufferWriteChar("<?xml version=\"");
xmlBufferWriteCHAR(cur->version);
xmlBufferWriteChar("\"?>\n");
if (cur->dtds != NULL)
xmlDtdListDump(cur->dtds);
if (cur->root != NULL)
xmlNodeDump(cur, cur->root, 0);
*mem = buffer;
*size = buffer_index;
}
/*
* Dump an XML document to the given FD
*/
void xmlDocDump(FILE *f, xmlDocPtr cur) {
if (cur == NULL) {
fprintf(stderr, "xmlDocDump : document == NULL\n");
return;
}
buffer_index = 0;
if (oldXMLWDcompatibility)
xmlBufferWriteChar("<?XML version=\"");
else
xmlBufferWriteChar("<?xml version=\"");
xmlBufferWriteCHAR(cur->version);
xmlBufferWriteChar("\"?>\n");
if (cur->dtds != NULL)
xmlDtdListDump(cur->dtds);
if (cur->root != NULL)
xmlNodeDump(cur, cur->root, 0);
fwrite(buffer, sizeof(CHAR), buffer_index, f);
}
/************************************************************************
* *
* Debug *
* *
************************************************************************/
#ifdef DEBUG_TREE
int main(void) {
xmlDocPtr doc;
xmlNodePtr tree, subtree;
xmlDtdPtr dtd1;
xmlDtdPtr dtd2;
/*
* build a fake XML document
*/
doc = xmlNewDoc("1.0");
dtd1 = xmlNewDtd(doc, "http://www.ietf.org/standards/dav/", "D");
dtd2 = xmlNewDtd(doc, "http://www.w3.com/standards/z39.50/", "Z");
doc->root = xmlNewNode(dtd1, "multistatus", NULL);
tree = xmlNewChild(doc->root, NULL, "response", NULL);
subtree = xmlNewChild(tree, NULL, "prop", NULL);
xmlNewChild(subtree, dtd2, "Authors", NULL);
subtree = xmlNewChild(tree, NULL, "status", "HTTP/1.1 420 Method Failure");
tree = xmlNewChild(doc->root, NULL, "response", NULL);
subtree = xmlNewChild(tree, NULL, "prop", NULL);
xmlNewChild(subtree, dtd2, "Copyright-Owner", NULL);
subtree = xmlNewChild(tree, NULL, "status", "HTTP/1.1 409 Conflict");
tree = xmlNewChild(doc->root, NULL, "responsedescription",
"Copyright Owner can not be deleted or altered");
/*
* print it.
*/
xmlDocDump(stdout, doc);
/*
* free it.
*/
xmlFreeDoc(doc);
return(0);
}
#endif

View File

@ -1,113 +0,0 @@
/*
* tree.h : describes the structures found in an tree resulting
* from an XML parsing.
*
* See Copyright for the status of this software.
*
* $Id$
*/
#ifndef __XML_TREE_H__
#define __XML_TREE_H__
#ifdef __cplusplus
extern "C" {
#endif
/*
* Type definitions
*/
#ifdef UNICODE
typedef unsigned short CHAR;
#else
typedef unsigned char CHAR;
#endif
/*
* Constants.
*/
#define XML_TYPE_TEXT 1
/*
* An XML DTD defining a given name space.
*/
typedef struct xmlDtd {
struct xmlDtd *next; /* next Dtd link for this document */
const CHAR *href; /* URL for the DTD */
const CHAR *AS; /* URL for the DTD */
void *entities; /* Hash table for entities if any */
} xmlDtd, *xmlDtdPtr;
/*
* A property of an XML node.
*/
typedef struct xmlProp {
struct xmlNode *node; /* prop->node link */
struct xmlProp *next; /* parent->childs link */
const CHAR *name; /* the name of the property */
const CHAR *value; /* the value of the property */
} xmlProp, *xmlPropPtr;
/*
* A node in an XML tree.
*/
typedef struct xmlNode {
struct xmlNode *parent; /* child->parent link */
struct xmlNode *next; /* next sibling link */
struct xmlNode *childs; /* parent->childs link */
struct xmlProp *properties; /* properties list */
int type; /* type number in the DTD */
const CHAR *name; /* the name of the node */
xmlDtd *dtd; /* pointer to the DTD */
CHAR *content; /* the content */
} xmlNode, *xmlNodePtr;
/*
* An XML document.
*/
typedef struct xmlDoc {
const CHAR *version; /* the XML version string */
struct xmlDtd *dtds; /* referenced DTDs */
struct xmlNode *root; /* parent->childs link */
void *entities; /* Hash table for entities if any */
} xmlDoc, *xmlDocPtr;
/*
* Variables.
*/
extern xmlDtdPtr baseDTD;
extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */
/*
* Functions.
*/
extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *href, const CHAR *AS);
extern void xmlFreeDtd(xmlDtdPtr cur);
extern xmlDocPtr xmlNewDoc(const CHAR *version);
extern void xmlFreeDoc(xmlDocPtr cur);
extern xmlPropPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
const CHAR *value);
extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
extern void xmlFreePropList(xmlPropPtr cur);
extern void xmlFreeProp(xmlPropPtr cur);
extern xmlNodePtr xmlNewNode(xmlDtdPtr dtd, const CHAR *name, CHAR *content);
extern xmlNodePtr xmlNewText(CHAR *content);
extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
extern void xmlFreeNodeList(xmlNodePtr cur);
extern void xmlFreeNode(xmlNodePtr cur);
extern void xmlNodeSetContent(xmlNodePtr cur, CHAR *content);
extern xmlDtdPtr xmlSearchDtd(xmlDocPtr doc, CHAR *nameSpace);
extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlDtdPtr dtd,
const CHAR *name, CHAR *content);
extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
extern void xmlDocDump(FILE *f, xmlDocPtr doc);
#ifdef __cplusplus
}
#endif
#endif /* __XML_TREE_H__ */