Serious upgrade of internal subset support, setup for gtk-doc, Daniel
diff --git a/ChangeLog b/ChangeLog
index a76b485..89481a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Mon Feb 22 11:24:56 CET 1999 Daniel Veillard <Daniel.Veillard@w3.org>
+
+	* parserInternals.h: added this header giving access to the parser
+	  internal functions.
+	* doc/Makefile.am : added a rebuild target which rebuilds the full
+	  set of documentations
+	* parser.[ch] tree.[ch] valid.[ch]: serious updates w.r.t. parsing
+	  the internal subset. 
+	* *.c *.h: modifications needed to generate the documentation using
+	  gtk-doc, cleanup of functions blocks, reorganisation of struct
+	  declarations.
+
 Tue Feb 16 17:27:29 CET 1999 Daniel Veillard <Daniel.Veillard@w3.org>
 
 	* Makefile.am, spec, doc/Makefile.am : upgrading to 0.99.8, fixing
diff --git a/SAX.c b/SAX.c
index 46afbb9..b416556 100644
--- a/SAX.c
+++ b/SAX.c
@@ -21,7 +21,7 @@
  *
  * Return the public ID e.g. "-//SGMLSOURCE//DTD DEMO//EN"
  *
- * return values: a CHAR *
+ * Returns a CHAR *
  */
 const CHAR *
 getPublicId(xmlParserCtxtPtr ctxt)
@@ -36,7 +36,7 @@
  * Return the system ID, basically URI or filename e.g.
  * http://www.sgmlsource.com/dtds/memo.dtd
  *
- * return values: a CHAR *
+ * Returns a CHAR *
  */
 const CHAR *
 getSystemId(xmlParserCtxtPtr ctxt)
@@ -50,7 +50,7 @@
  *
  * Return the line number of the current parsing point.
  *
- * return values: an int
+ * Returns an int
  */
 int
 getLineNumber(xmlParserCtxtPtr ctxt)
@@ -64,7 +64,7 @@
  *
  * Return the column number of the current parsing point.
  *
- * return values: an int
+ * Returns an int
  */
 int
 getColumnNumber(xmlParserCtxtPtr ctxt)
@@ -92,7 +92,7 @@
  * the ENTITY_REF nodes are built in the structure (and the parameter
  * values).
  *
- * return values: the xmlParserInputPtr if inlined or NULL for DOM behaviour.
+ * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
  */
 xmlParserInputPtr
 resolveEntity(xmlParserCtxtPtr ctxt, const CHAR *publicId, const CHAR *systemId)
@@ -114,8 +114,6 @@
  *
  * What to do when a notation declaration has been parsed.
  * TODO Not handled currently.
- *
- * return values: 
  */
 void
 notationDecl(xmlParserCtxtPtr ctxt, const CHAR *name,
@@ -136,8 +134,6 @@
  *
  * What to do when an unparsed entity declaration is parsed
  * TODO Create an Entity node.
- *
- * return values: 
  */
 void
 unparsedEntityDecl(xmlParserCtxtPtr ctxt, const CHAR *name,
@@ -157,8 +153,6 @@
  *
  * Receive the document locator at startup, actually xmlDefaultSAXLocator
  * Everything is available on the context, so this is useless in our case.
- *
- * return values: 
  */
 void
 setDocumentLocator(xmlParserCtxtPtr ctxt, xmlSAXLocatorPtr loc)
@@ -173,8 +167,6 @@
  * @ctxt:  An XML parser context
  *
  * called when the document start being processed.
- *
- * return values: 
  */
 void
 startDocument(xmlParserCtxtPtr ctxt)
@@ -189,8 +181,6 @@
  * @ctxt:  An XML parser context
  *
  * called when the document end has been detected.
- *
- * return values: 
  */
 void
 endDocument(xmlParserCtxtPtr ctxt)
@@ -207,8 +197,6 @@
  *
  * called when an opening tag has been processed.
  * TODO We currently have a small pblm with the arguments ...
- *
- * return values: 
  */
 void
 startElement(xmlParserCtxtPtr ctxt, const CHAR *name)
@@ -224,8 +212,6 @@
  * @name:  The element name
  *
  * called when the end of an element has been detected.
- *
- * return values: 
  */
 void
 endElement(xmlParserCtxtPtr ctxt, const CHAR *name)
@@ -245,8 +231,6 @@
  * The default handling is to convert the attribute into an
  * DOM subtree and past it in a new xmlAttr element added to
  * the element.
- *
- * return values: 
  */
 void
 attribute(xmlParserCtxtPtr ctxt, const CHAR *name, const CHAR *value)
@@ -265,8 +249,6 @@
  *
  * receiving some chars from the parser.
  * Question: how much at a time ???
- *
- * return values: 
  */
 void
 characters(xmlParserCtxtPtr ctxt, const CHAR *ch, int start, int len)
@@ -304,8 +286,6 @@
  *
  * receiving some ignorable whitespaces from the parser.
  * Question: how much at a time ???
- *
- * return values: 
  */
 void
 ignorableWhitespace(xmlParserCtxtPtr ctxt, const CHAR *ch, int start, int len)
@@ -323,8 +303,6 @@
  * @len: the number of CHAR
  *
  * A processing instruction has been parsed.
- *
- * return values: 
  */
 void
 processingInstruction(xmlParserCtxtPtr ctxt, const CHAR *target,
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 9ec4351..0d13433 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -34,6 +34,13 @@
 docdatadir = $(datadir)/aclocal
 docdata_DATA = xml.html structure.gif DOM.gif
 
+gnome-xml-decl-list.txt : templates
+
+gnome-xml-sections.txt : scan
+	cp gnome-xml-decl-list.txt gnome-xml-sections.txt
+
+rebuild: gnome-xml-sections.txt templates sgml html
+
 #install-data-local:
 #	install -d -m 0755 $(TARGET_DIR)
 #	install -m 0644 xml.html structure.gif DOM.gif $(TARGET_DIR)
diff --git a/encoding.c b/encoding.c
index 295ca39..0db110c 100644
--- a/encoding.c
+++ b/encoding.c
@@ -41,7 +41,7 @@
  *
  * Take a block of ISO Latin 1 chars in and try to convert it to an UTF-8
  * block of chars out.
- * return values: number of byte written, or -1 by lack of space.
+ * Returns the number of byte written, or -1 by lack of space.
  */
 int
 isolat1ToUTF8(unsigned char* out, int outlen, unsigned char* in, int inlen)
@@ -77,7 +77,7 @@
  * Take a block of UTF-8 chars in and try to convert it to an ISO Latin 1
  * block of chars out.
  * TODO: need a fallback mechanism ...
- * return values: the number of byte written, or -1 by lack of space, or -2
+ * Returns the number of byte written, or -1 by lack of space, or -2
  *     if the transcoding failed.
  */
 int
@@ -112,7 +112,7 @@
  *
  * Take a block of UTF-16 ushorts in and try to convert it to an UTF-8
  * block of chars out.
- * return values: number of byte written, or -1 by lack of space.
+ * Returns the number of byte written, or -1 by lack of space.
  */
 int
 UTF16ToUTF8(unsigned char* out, int outlen, unsigned short* in, int inlen)
@@ -161,7 +161,7 @@
  * Take a block of UTF-8 chars in and try to convert it to an UTF-16
  * block of chars out.
  * TODO: need a fallback mechanism ...
- * return values: the number of byte written, or -1 by lack of space, or -2
+ * Returns the number of byte written, or -1 by lack of space, or -2
  *     if the transcoding failed.
  */
 int
diff --git a/entities.c b/entities.c
index ef6aa79..e16dc55 100644
--- a/entities.c
+++ b/entities.c
@@ -154,7 +154,7 @@
  *
  * Check whether this name is an predefined entity.
  *
- * return values: NULL if not, othervise the entity
+ * Returns NULL if not, othervise the entity
  */
 xmlEntityPtr
 xmlGetPredefinedEntity(const CHAR *name) {
@@ -241,7 +241,7 @@
  * Do an entity lookup in the Dtd entity hash table and
  * returns the corresponding entity, if found.
  * 
- * return values: A pointer to the entity structure or NULL if not found.
+ * Returns A pointer to the entity structure or NULL if not found.
  */
 xmlEntityPtr
 xmlGetDtdEntity(xmlDocPtr doc, const CHAR *name) {
@@ -268,7 +268,7 @@
  * returns the corrsponding entity, otherwise a lookup is done
  * in the predefined entities too.
  * 
- * return values: A pointer to the entity structure or NULL if not found.
+ * Returns A pointer to the entity structure or NULL if not found.
  */
 xmlEntityPtr
 xmlGetDocEntity(xmlDocPtr doc, const CHAR *name) {
@@ -317,7 +317,7 @@
  * TODO This routine is not reentrant and this will be changed, the interface
  *      should not be modified though.
  * 
- * return values: A newly allocated string with the substitution done.
+ * Returns A newly allocated string with the substitution done.
  */
 CHAR *
 xmlEncodeEntities(xmlDocPtr doc, const CHAR *input) {
@@ -423,7 +423,7 @@
  *
  * create and initialize an empty entities hash table.
  *
- * return values: the xmlEntitiesTablePtr just created or NULL in case of error.
+ * Returns the xmlEntitiesTablePtr just created or NULL in case of error.
  */
 xmlEntitiesTablePtr
 xmlCreateEntitiesTable(void) {
@@ -474,7 +474,7 @@
  *
  * Build a copy of an entity table.
  * 
- * return values: the new xmlEntitiesTablePtr or NULL in case of error.
+ * Returns the new xmlEntitiesTablePtr or NULL in case of error.
  */
 xmlEntitiesTablePtr
 xmlCopyEntitiesTable(xmlEntitiesTablePtr table) {
diff --git a/entities.h b/entities.h
index 86c425f..99ce163 100644
--- a/entities.h
+++ b/entities.h
@@ -34,7 +34,8 @@
     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;
+} xmlEntity;
+typedef xmlEntity *xmlEntityPtr;
 
 /*
  * ALl entities are stored in a table there is one table per DTD
@@ -47,28 +48,29 @@
     int nb_entities;		/* number of elements stored */
     int max_entities;		/* maximum number of elements */
     xmlEntityPtr table;	        /* the table of entities */
-} xmlEntitiesTable, *xmlEntitiesTablePtr;
+} xmlEntitiesTable;
+typedef xmlEntitiesTable *xmlEntitiesTablePtr;
 
 
 /*
  * External functions :
  */
 
-extern void xmlAddDocEntity(xmlDocPtr doc, const CHAR *name, int type,
+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,
+void xmlAddDtdEntity(xmlDocPtr doc, const CHAR *name, int type,
               const CHAR *ExternalID, const CHAR *SystemID, CHAR *content);
-extern xmlEntityPtr xmlGetPredefinedEntity(const CHAR *name);
-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 xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table);
-extern void xmlFreeEntitiesTable(xmlEntitiesTablePtr table);
-extern void xmlDumpEntitiesTable(xmlEntitiesTablePtr table);
-extern xmlParserInputPtr xmlNewEntityInputStream(xmlParserCtxtPtr ctxt,
+xmlEntityPtr xmlGetPredefinedEntity(const CHAR *name);
+xmlEntityPtr xmlGetDocEntity(xmlDocPtr doc, const CHAR *name);
+xmlEntityPtr xmlGetDtdEntity(xmlDocPtr doc, const CHAR *name);
+CHAR *xmlEncodeEntities(xmlDocPtr doc, const CHAR *input);
+xmlEntitiesTablePtr xmlCreateEntitiesTable(void);
+xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table);
+void xmlFreeEntitiesTable(xmlEntitiesTablePtr table);
+void xmlDumpEntitiesTable(xmlEntitiesTablePtr table);
+xmlParserInputPtr xmlNewEntityInputStream(xmlParserCtxtPtr ctxt,
                                                  xmlEntityPtr entity);
-extern xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table);
+xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table);
 
 #ifdef __cplusplus
 }
diff --git a/error.c b/error.c
index eb93d96..3a479ea 100644
--- a/error.c
+++ b/error.c
@@ -38,12 +38,12 @@
     va_end(ap);
     cur = ctxt->input->cur;
     base = ctxt->input->base;
-    while ((*cur == '\n') || (*cur == '\r')) {
+    while ((cur > base) && ((*cur == '\n') || (*cur == '\r'))) {
 	cur--;
 	base--;
     }
     n = 0;
-    while ((n++ < 60) && (cur >= base) && (*cur != '\n') && (*cur != '\r'))
+    while ((n++ < 60) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
         cur--;
     if ((*cur == '\n') || (*cur == '\r')) cur++;
     base = cur;
@@ -93,7 +93,7 @@
     cur = ctxt->input->cur;
     base = ctxt->input->base;
     n = 0;
-    while ((n++ < 60) && (cur >= base) && (*cur != '\n') && (*cur != '\r'))
+    while ((n++ < 60) && (cur > base) && (*cur != '\n') && (*cur != '\r'))
         cur--;
     if ((*cur != '\n') || (*cur != '\r')) cur++;
     base = cur;
diff --git a/include/libxml/entities.h b/include/libxml/entities.h
index 86c425f..99ce163 100644
--- a/include/libxml/entities.h
+++ b/include/libxml/entities.h
@@ -34,7 +34,8 @@
     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;
+} xmlEntity;
+typedef xmlEntity *xmlEntityPtr;
 
 /*
  * ALl entities are stored in a table there is one table per DTD
@@ -47,28 +48,29 @@
     int nb_entities;		/* number of elements stored */
     int max_entities;		/* maximum number of elements */
     xmlEntityPtr table;	        /* the table of entities */
-} xmlEntitiesTable, *xmlEntitiesTablePtr;
+} xmlEntitiesTable;
+typedef xmlEntitiesTable *xmlEntitiesTablePtr;
 
 
 /*
  * External functions :
  */
 
-extern void xmlAddDocEntity(xmlDocPtr doc, const CHAR *name, int type,
+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,
+void xmlAddDtdEntity(xmlDocPtr doc, const CHAR *name, int type,
               const CHAR *ExternalID, const CHAR *SystemID, CHAR *content);
-extern xmlEntityPtr xmlGetPredefinedEntity(const CHAR *name);
-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 xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table);
-extern void xmlFreeEntitiesTable(xmlEntitiesTablePtr table);
-extern void xmlDumpEntitiesTable(xmlEntitiesTablePtr table);
-extern xmlParserInputPtr xmlNewEntityInputStream(xmlParserCtxtPtr ctxt,
+xmlEntityPtr xmlGetPredefinedEntity(const CHAR *name);
+xmlEntityPtr xmlGetDocEntity(xmlDocPtr doc, const CHAR *name);
+xmlEntityPtr xmlGetDtdEntity(xmlDocPtr doc, const CHAR *name);
+CHAR *xmlEncodeEntities(xmlDocPtr doc, const CHAR *input);
+xmlEntitiesTablePtr xmlCreateEntitiesTable(void);
+xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table);
+void xmlFreeEntitiesTable(xmlEntitiesTablePtr table);
+void xmlDumpEntitiesTable(xmlEntitiesTablePtr table);
+xmlParserInputPtr xmlNewEntityInputStream(xmlParserCtxtPtr ctxt,
                                                  xmlEntityPtr entity);
-extern xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table);
+xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table);
 
 #ifdef __cplusplus
 }
diff --git a/include/libxml/parser.h b/include/libxml/parser.h
index a06d481..ca0835f 100644
--- a/include/libxml/parser.h
+++ b/include/libxml/parser.h
@@ -26,24 +26,28 @@
     const CHAR *cur;                  /* Current char being parsed */
     int line;                         /* Current line */
     int col;                          /* Current column */
-} xmlParserInput, *xmlParserInputPtr;
+} xmlParserInput;
+typedef xmlParserInput *xmlParserInputPtr;
 
-typedef struct xmlParserNodeInfo {
+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;
+} _xmlParserNodeInfo;
+typedef _xmlParserNodeInfo xmlParserNodeInfo;
 
 typedef struct xmlParserNodeInfoSeq {
   unsigned long maximum;
   unsigned long length;
   xmlParserNodeInfo* buffer;
-} xmlParserNodeInfoSeq, *xmlParserNodeInfoSeqPtr;
+} _xmlParserNodeInfoSeq;
+typedef _xmlParserNodeInfoSeq xmlParserNodeInfoSeq;
+typedef xmlParserNodeInfoSeq *xmlParserNodeInfoSeqPtr;
 
-typedef struct xmlParserCtxt {
+typedef struct _xmlParserCtxt {
     struct xmlSAXHandler *sax;        /* The SAX handler */
     xmlDocPtr doc;                    /* the document being built */
     int            wellFormed;        /* is the document well formed */
@@ -62,7 +66,9 @@
 
     int record_info;                  /* Whether node info should be kept */
     xmlParserNodeInfoSeq node_seq;    /* info about each node parsed */
-} xmlParserCtxt, *xmlParserCtxtPtr;
+} _xmlParserCtxt;
+typedef _xmlParserCtxt xmlParserCtxt;
+typedef xmlParserCtxt *xmlParserCtxtPtr;
 
 /*
  * a SAX Locator.
@@ -73,7 +79,9 @@
     const CHAR *(*getSystemId)(xmlParserCtxtPtr ctxt);
     int (*getLineNumber)(xmlParserCtxtPtr ctxt);
     int (*getColumnNumber)(xmlParserCtxtPtr ctxt);
-} xmlSAXLocator, *xmlSAXLocatorPtr;
+} _xmlSAXLocator;
+typedef _xmlSAXLocator xmlSAXLocator;
+typedef xmlSAXLocator *xmlSAXLocatorPtr;
 
 /*
  * a SAX Exception.
@@ -120,7 +128,8 @@
     warningSAXFunc warning;
     errorSAXFunc error;
     fatalErrorSAXFunc fatalError;
-} xmlSAXHandler, *xmlSAXHandlerPtr;
+} xmlSAXHandler;
+typedef xmlSAXHandler *xmlSAXHandlerPtr;
 
 /*
  * Global variables: just the SAX interface tables we are looking for full
@@ -130,61 +139,58 @@
 extern xmlSAXHandler xmlDefaultSAXHandler;
 
 #include "entities.h"
+#include "error.h"
 
 /*
  * CHAR handling
  */
-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);
+CHAR *xmlStrdup(const CHAR *cur);
+CHAR *xmlStrndup(const CHAR *cur, int len);
+CHAR *xmlStrchr(const CHAR *str, CHAR val);
+int xmlStrcmp(const CHAR *str1, const CHAR *str2);
+int xmlStrncmp(const CHAR *str1, const CHAR *str2, int len);
+int xmlStrlen(const CHAR *str);
+CHAR *xmlStrcat(CHAR *cur, const CHAR *add);
+CHAR *xmlStrncat(CHAR *cur, const CHAR *add, int len);
 
 /*
  * Interfaces
  */
-extern xmlDocPtr xmlParseDoc(CHAR *cur);
-extern xmlDocPtr xmlParseMemory(char *buffer, int size);
-extern xmlDocPtr xmlParseFile(const char *filename);
+xmlDocPtr xmlParseDoc(CHAR *cur);
+xmlDocPtr xmlParseMemory(char *buffer, int size);
+xmlDocPtr xmlParseFile(const char *filename);
 
 /*
  * Recovery mode 
  */
-extern xmlDocPtr xmlRecoverDoc(CHAR *cur);
-extern xmlDocPtr xmlRecoverMemory(char *buffer, int size);
-extern xmlDocPtr xmlRecoverFile(const char *filename);
+xmlDocPtr xmlRecoverDoc(CHAR *cur);
+xmlDocPtr xmlRecoverMemory(char *buffer, int size);
+xmlDocPtr xmlRecoverFile(const char *filename);
 
 /*
  * Internal routines
  */
-extern int xmlParseDocument(xmlParserCtxtPtr ctxt);
-extern xmlDocPtr xmlSAXParseDoc(xmlSAXHandlerPtr sax, CHAR *cur, int recovery);
-extern xmlDocPtr xmlSAXParseMemory(xmlSAXHandlerPtr sax, char *buffer,
+int xmlParseDocument(xmlParserCtxtPtr ctxt);
+xmlDocPtr xmlSAXParseDoc(xmlSAXHandlerPtr sax, CHAR *cur, int recovery);
+xmlDocPtr xmlSAXParseMemory(xmlSAXHandlerPtr sax, char *buffer,
                                    int size, int recovery);
-extern xmlDocPtr xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename,
+xmlDocPtr xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename,
                                  int recovery);
-extern void xmlInitParserCtxt(xmlParserCtxtPtr ctx);
-extern void xmlClearParserCtxt(xmlParserCtxtPtr ctx);
-extern void xmlSetupParserForBuffer(xmlParserCtxtPtr ctx, const CHAR* buffer,
+void xmlInitParserCtxt(xmlParserCtxtPtr ctxt);
+void xmlClearParserCtxt(xmlParserCtxtPtr ctxt);
+void xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, 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);
+const xmlParserNodeInfo* xmlParserFindNodeInfo(const xmlParserCtxt* ctxt,
+                                               const xmlNode* node);
+void xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
+void xmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
 unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeq* seq,
                                          const xmlNode* node);
-extern void xmlParserAddNodeInfo(xmlParserCtxtPtr ctx,
-                                 const xmlParserNodeInfo* info);
+void xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt,
+                          const xmlParserNodeInfo* info);
 
-extern void xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...);
-extern void xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...);
-extern void xmlDefaultSAXHandlerInit(void);
+void xmlDefaultSAXHandlerInit(void);
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/libxml/parserInternals.h b/include/libxml/parserInternals.h
new file mode 100644
index 0000000..9cd6a21
--- /dev/null
+++ b/include/libxml/parserInternals.h
@@ -0,0 +1,128 @@
+/*
+ * parserInternals.h : internals routines exported by the parser.
+ *
+ * See Copyright for the status of this software.
+ *
+ * Daniel.Veillard@w3.org
+ */
+
+#ifndef __XML_PARSER_INTERNALS_H__
+#define __XML_PARSER_INTERNALS_H__
+
+#include "parser.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Entities
+ */
+void
+xmlHandleEntity(xmlParserCtxtPtr ctxt, xmlEntityPtr entity);
+
+/*
+ * Namespaces.
+ */
+CHAR *
+xmlNamespaceParseNCName(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlNamespaceParseQName(xmlParserCtxtPtr ctxt, CHAR **prefix);
+CHAR *
+xmlNamespaceParseNSDef(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseQuotedString(xmlParserCtxtPtr ctxt);
+void
+xmlParseNamespace(xmlParserCtxtPtr ctxt);
+
+/*
+ * Generic production rules
+ */
+CHAR *
+xmlParseName(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseNmtoken(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseEntityValue(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseAttValue(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseSystemLiteral(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParsePubidLiteral(xmlParserCtxtPtr ctxt);
+void
+xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata);
+CHAR *
+xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID, int strict);
+xmlNodePtr 
+xmlParseComment(xmlParserCtxtPtr ctxt, int create);
+CHAR *
+xmlParsePITarget(xmlParserCtxtPtr ctxt);
+void
+xmlParsePI(xmlParserCtxtPtr ctxt);
+void
+xmlParseNotationDecl(xmlParserCtxtPtr ctxt);
+void
+xmlParseEntityDecl(xmlParserCtxtPtr ctxt);
+int
+xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, CHAR **value);
+xmlEnumerationPtr
+xmlParseNotationType(xmlParserCtxtPtr ctxt);
+xmlEnumerationPtr
+xmlParseEnumerationType(xmlParserCtxtPtr ctxt);
+int
+xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree);
+int
+xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree);
+void
+xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt);
+xmlElementContentPtr
+xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt);
+xmlElementContentPtr
+xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt);
+int
+xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, CHAR *name,
+                           xmlElementContentPtr *result);
+int
+xmlParseElementDecl(xmlParserCtxtPtr ctxt);
+void
+xmlParseMarkupDecl(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseCharRef(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseEntityRef(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseReference(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParsePEReference(xmlParserCtxtPtr ctxt);
+void
+xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt);
+xmlAttrPtr 
+xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlNodePtr node);
+xmlNodePtr 
+xmlParseStartTag(xmlParserCtxtPtr ctxt);
+void
+xmlParseEndTag(xmlParserCtxtPtr ctxt, xmlNsPtr *nsPtr, CHAR **tagPtr);
+void
+xmlParseCDSect(xmlParserCtxtPtr ctxt);
+void
+xmlParseContent(xmlParserCtxtPtr ctxt);
+xmlNodePtr 
+xmlParseElement(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseVersionNum(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseVersionInfo(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseEncName(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseEncodingDecl(xmlParserCtxtPtr ctxt);
+int
+xmlParseSDDecl(xmlParserCtxtPtr ctxt);
+void
+xmlParseXMLDecl(xmlParserCtxtPtr ctxt);
+void
+xmlParseMisc(xmlParserCtxtPtr ctxt);
+
+
+#endif /* __XML_PARSER_INTERNALS_H__ */
diff --git a/include/libxml/tree.h b/include/libxml/tree.h
index ba77f76..4443836 100644
--- a/include/libxml/tree.h
+++ b/include/libxml/tree.h
@@ -55,41 +55,67 @@
 
 /*
  * a DTD Notation definition
- * TODO !!!!
  */
 
+typedef struct xmlNotation {
+    const CHAR               *name;	/* Notation name */
+    const CHAR               *PublicID;	/* Public identifier, if any */
+    const CHAR               *SystemID;	/* System identifier, if any */
+} xmlNotation;
+typedef xmlNotation *xmlNotationPtr;
+
 /*
  * a DTD Attribute definition
- * TODO !!!!
  */
 
-#define XML_ATTRIBUTE_NONE		1
-#define XML_ATTRIBUTE_REQUIRED		2
-#define XML_ATTRIBUTE_IMPLIED		3
-#define XML_ATTRIBUTE_FIXED		4
+typedef enum {
+    XML_ATTRIBUTE_CDATA = 1,
+    XML_ATTRIBUTE_ID,
+    XML_ATTRIBUTE_IDREF	,
+    XML_ATTRIBUTE_IDREFS,
+    XML_ATTRIBUTE_ENTITY,
+    XML_ATTRIBUTE_ENTITIES,
+    XML_ATTRIBUTE_NMTOKEN,
+    XML_ATTRIBUTE_NMTOKENS,
+    XML_ATTRIBUTE_ENUMERATION,
+    XML_ATTRIBUTE_NOTATION
+} xmlAttributeType;
 
-#define XML_ATTRIBUTE_STRING		1
-#define XML_ATTRIBUTE_ID		2
-#define XML_ATTRIBUTE_IDREF		3
-#define XML_ATTRIBUTE_IDREFS		4
-#define XML_ATTRIBUTE_ENTITY		5
-#define XML_ATTRIBUTE_ENTITIES		6
-#define XML_ATTRIBUTE_NMTOKEN		7
-#define XML_ATTRIBUTE_NMTOKENS		8
-#define XML_ATTRIBUTE_ENUMERATED	9
+typedef enum {
+    XML_ATTRIBUTE_NONE = 1,
+    XML_ATTRIBUTE_REQUIRED,
+    XML_ATTRIBUTE_IMPLIED,
+    XML_ATTRIBUTE_FIXED
+} xmlAttributeDefault;
+
+typedef struct xmlEnumeration {
+    struct xmlEnumeration    *next;	/* next one */
+    const CHAR               *name;	/* Enumeration name */
+} xmlEnumeration;
+typedef xmlEnumeration *xmlEnumerationPtr;
+
+typedef struct xmlAttribute {
+    const CHAR            *elem;	/* Element holding the attribute */
+    const CHAR            *name;	/* Attribute name */
+    xmlAttributeType       type;	/* The type */
+    xmlAttributeDefault    def;		/* the default */
+    const CHAR            *defaultValue;/* or the default value */
+    xmlEnumerationPtr      tree;        /* or the enumeration tree if any */
+} xmlAttribute;
+typedef xmlAttribute *xmlAttributePtr;
 
 /*
  * a DTD Element definition.
  */
 typedef enum {
-    XML_ELEMENT_CONTENT_PCDATA=1,
+    XML_ELEMENT_CONTENT_PCDATA = 1,
     XML_ELEMENT_CONTENT_ELEMENT,
     XML_ELEMENT_CONTENT_SEQ,
     XML_ELEMENT_CONTENT_OR
 } xmlElementContentType;
 
 typedef enum {
-    XML_ELEMENT_CONTENT_ONCE=1,
+    XML_ELEMENT_CONTENT_ONCE = 1,
     XML_ELEMENT_CONTENT_OPT,
     XML_ELEMENT_CONTENT_MULT,
     XML_ELEMENT_CONTENT_PLUS
@@ -101,10 +127,11 @@
     const CHAR               *name;	/* Element name */
     struct xmlElementContent *c1;	/* first child */
     struct xmlElementContent *c2;	/* second child */
-} xmlElementContent, *xmlElementContentPtr;
+} xmlElementContent;
+typedef xmlElementContent *xmlElementContentPtr;
 
 typedef enum {
-    XML_ELEMENT_TYPE_EMPTY=1,
+    XML_ELEMENT_TYPE_EMPTY = 1,
     XML_ELEMENT_TYPE_ANY,
     XML_ELEMENT_TYPE_MIXED,
     XML_ELEMENT_TYPE_ELEMENT
@@ -114,7 +141,8 @@
     const CHAR          *name;		/* Element name */
     xmlElementTypeVal    type;		/* The type */
     xmlElementContentPtr content;	/* the allowed element content */
-} xmlElement, *xmlElementPtr;
+} xmlElement;
+typedef xmlElement *xmlElementPtr;
 
 /*
  * An XML namespace.
@@ -123,7 +151,7 @@
  */
 
 typedef enum {
-    XML_GLOBAL_NAMESPACE=1,	/* old style global namespace */
+    XML_GLOBAL_NAMESPACE = 1,	/* old style global namespace */
     XML_LOCAL_NAMESPACE		/* new style local scoping */
 } xmlNsType;
 
@@ -132,7 +160,8 @@
     xmlNsType      type;	/* global or local */
     const CHAR    *href;	/* URL for the namespace */
     const CHAR    *prefix;	/* prefix for the namespace */
-} xmlNs, *xmlNsPtr;
+} xmlNs;
+typedef xmlNs *xmlNsPtr;
 
 /*
  * An XML DtD, as defined by <!DOCTYPE.
@@ -141,10 +170,13 @@
     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          *notations;   /* Hash table for notations if any */
     void          *elements;    /* Hash table for elements if any */
+    void          *attributes;  /* Hash table for attributes if any */
     void          *entities;    /* Hash table for entities if any */
     /* struct xmlDtd *next;	 * next  link for this document  */
-} xmlDtd, *xmlDtdPtr;
+} xmlDtd;
+typedef xmlDtd *xmlDtdPtr;
 
 /*
  * A attribute of an XML node.
@@ -159,7 +191,8 @@
     struct xmlAttr *next;	/* parent->childs link */
     const CHAR     *name;       /* the name of the property */
     struct xmlNode *val;        /* the value of the property */
-} xmlAttr, *xmlAttrPtr;
+} xmlAttr;
+typedef xmlAttr *xmlAttrPtr;
 
 /*
  * A node in an XML tree.
@@ -181,7 +214,9 @@
     xmlNs          *ns;         /* pointer to the associated namespace */
     xmlNs          *nsDef;      /* namespace definitions on this node */
     CHAR           *content;    /* the content */
-} xmlNode, *xmlNodePtr;
+} _xmlNode;
+typedef _xmlNode xmlNode;
+typedef _xmlNode *xmlNodePtr;
 
 /*
  * An XML document.
@@ -201,7 +236,9 @@
     struct xmlDtd  *extSubset;	/* the document external subset */
     struct xmlNs   *oldNs;	/* Global namespace, the old way */
     struct xmlNode *root;	/* the document tree */
-} xmlDoc, *xmlDocPtr;
+} _xmlDoc;
+typedef _xmlDoc xmlDoc;
+typedef xmlDoc *xmlDocPtr;
 
 /*
  * Variables.
@@ -213,110 +250,110 @@
 /*
  * Creating/freeing new structures
  */
-extern xmlDtdPtr xmlCreateIntSubset(xmlDocPtr doc, const CHAR *name,
+xmlDtdPtr xmlCreateIntSubset(xmlDocPtr doc, const CHAR *name,
                     const CHAR *ExternalID, const CHAR *SystemID);
-extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
+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 xmlNewDocProp(xmlDocPtr doc, const CHAR *name,
+void xmlFreeDtd(xmlDtdPtr cur);
+xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *prefix);
+xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *prefix);
+void xmlFreeNs(xmlNsPtr cur);
+xmlDocPtr xmlNewDoc(const CHAR *version);
+void xmlFreeDoc(xmlDocPtr cur);
+xmlAttrPtr xmlNewDocProp(xmlDocPtr doc, const CHAR *name,
                                 const CHAR *value);
-extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
+xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
                              const CHAR *value);
-extern void xmlFreePropList(xmlAttrPtr cur);
-extern void xmlFreeProp(xmlAttrPtr cur);
-extern xmlAttrPtr xmlCopyProp(xmlAttrPtr cur);
-extern xmlAttrPtr xmlCopyPropList(xmlAttrPtr cur);
-extern xmlDtdPtr xmlCopyDtd(xmlDtdPtr dtd);
-extern xmlDocPtr xmlCopyDoc(xmlDocPtr doc, int recursive);
+void xmlFreePropList(xmlAttrPtr cur);
+void xmlFreeProp(xmlAttrPtr cur);
+xmlAttrPtr xmlCopyProp(xmlAttrPtr cur);
+xmlAttrPtr xmlCopyPropList(xmlAttrPtr cur);
+xmlDtdPtr xmlCopyDtd(xmlDtdPtr dtd);
+xmlDocPtr xmlCopyDoc(xmlDocPtr doc, int recursive);
 
 /*
  * Creating new nodes
  */
-extern xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
+xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
                              const CHAR *name, CHAR *content);
-extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name);
-extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
+xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name);
+xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
                               const CHAR *name, CHAR *content);
-extern xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
-extern xmlNodePtr xmlNewText(const CHAR *content);
-extern xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
-extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
-extern xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
-extern xmlNodePtr xmlNewComment(CHAR *content);
-extern xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name);
-extern xmlNodePtr xmlCopyNode(xmlNodePtr node, int recursive);
-extern xmlNodePtr xmlCopyNodeList(xmlNodePtr node);
+xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
+xmlNodePtr xmlNewText(const CHAR *content);
+xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
+xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
+xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
+xmlNodePtr xmlNewComment(CHAR *content);
+xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name);
+xmlNodePtr xmlCopyNode(xmlNodePtr node, int recursive);
+xmlNodePtr xmlCopyNodeList(xmlNodePtr node);
 
 /*
  * Navigating
  */
-extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
-extern int xmlNodeIsText(xmlNodePtr node);
+xmlNodePtr xmlGetLastChild(xmlNodePtr parent);
+int xmlNodeIsText(xmlNodePtr node);
 
 /*
  * Changing the structure
  */
-extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
-extern void xmlUnlinkNode(xmlNodePtr cur);
+xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
+void xmlUnlinkNode(xmlNodePtr cur);
 
-extern xmlNodePtr xmlTextMerge(xmlNodePtr first, xmlNodePtr second);
-extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
+xmlNodePtr xmlTextMerge(xmlNodePtr first, xmlNodePtr second);
+void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
 
-extern void xmlFreeNodeList(xmlNodePtr cur);
-extern void xmlFreeNode(xmlNodePtr cur);
+void xmlFreeNodeList(xmlNodePtr cur);
+void xmlFreeNode(xmlNodePtr cur);
 
 /*
  * Namespaces
  */
-extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
+xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
                             const CHAR *nameSpace);
-extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
+xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
                                   const CHAR *href);
-extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
-extern xmlNsPtr xmlCopyNamespace(xmlNsPtr cur);
-extern xmlNsPtr xmlCopyNamespaceList(xmlNsPtr cur);
+void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
+xmlNsPtr xmlCopyNamespace(xmlNsPtr cur);
+xmlNsPtr xmlCopyNamespaceList(xmlNsPtr cur);
 
 /*
  * Changing the content.
  */
-extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
+xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
                              const CHAR *value);
-extern CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
-extern xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR *value);
-extern xmlNodePtr xmlStringLenGetNodeList(xmlDocPtr doc, const CHAR *value,
+CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
+xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR *value);
+xmlNodePtr xmlStringLenGetNodeList(xmlDocPtr doc, const CHAR *value,
                                           int len);
-extern CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine);
-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 CHAR *xmlNodeGetContent(xmlNodePtr cur);
+CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine);
+void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
+void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
+void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
+void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
+CHAR *xmlNodeGetContent(xmlNodePtr cur);
 
 /*
  * Internal, don't use
  */
-extern void xmlBufferWriteCHAR(const CHAR *string);
-extern void xmlBufferWriteChar(const char *string);
+void xmlBufferWriteCHAR(const CHAR *string);
+void xmlBufferWriteChar(const char *string);
 
 /*
  * Saving
  */
-extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
-extern void xmlDocDump(FILE *f, xmlDocPtr doc);
+void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
+void xmlDocDump(FILE *f, xmlDocPtr cur);
 int xmlSaveFile(const char *filename, xmlDocPtr cur);
 
 /*
  * Compression
  */
-extern int  xmlGetDocCompressMode (xmlDocPtr doc);
-extern void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
-extern int  xmlGetCompressMode(void);
-extern void xmlSetCompressMode(int mode);
+int  xmlGetDocCompressMode (xmlDocPtr doc);
+void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
+int  xmlGetCompressMode(void);
+void xmlSetCompressMode(int mode);
 
 #ifdef __cplusplus
 }
diff --git a/include/libxml/valid.h b/include/libxml/valid.h
index 6f0023a..14a7228 100644
--- a/include/libxml/valid.h
+++ b/include/libxml/valid.h
@@ -12,6 +12,20 @@
 #include "tree.h"
 
 /*
+ * ALl notation declarations are stored in a table
+ * there is one table per DTD
+ */
+
+#define XML_MIN_NOTATION_TABLE	32
+
+typedef struct xmlNotationTable {
+    int nb_notations;		/* number of notations stored */
+    int max_notations;		/* maximum number of notations */
+    xmlNotationPtr table;	/* the table of attributes */
+} xmlNotationTable;
+typedef xmlNotationTable *xmlNotationTablePtr;
+
+/*
  * ALl element declarations are stored in a table
  * there is one table per DTD
  */
@@ -21,16 +35,54 @@
 typedef struct xmlElementTable {
     int nb_elements;		/* number of elements stored */
     int max_elements;		/* maximum number of elements */
-    xmlElementPtr table;	/* the table of entities */
-} xmlElementTable, *xmlElementTablePtr;
+    xmlElementPtr table;	/* the table of elements */
+} xmlElementTable;
+typedef xmlElementTable *xmlElementTablePtr;
 
-extern xmlElementPtr xmlAddElementDecl(xmlDtdPtr dtd, char *name, int type, 
+/*
+ * ALl attribute declarations are stored in a table
+ * there is one table per DTD
+ */
+
+#define XML_MIN_ATTRIBUTE_TABLE	32
+
+typedef struct xmlAttributeTable {
+    int nb_attributes;		/* number of attributes stored */
+    int max_attributes;		/* maximum number of attributes */
+    xmlAttributePtr table;	/* the table of attributes */
+} xmlAttributeTable;
+typedef xmlAttributeTable *xmlAttributeTablePtr;
+
+/* Notation */
+xmlNotationPtr xmlAddNotationDecl(xmlDtdPtr dtd, CHAR *name,
+	       CHAR *PublicID, CHAR *SystemID);
+xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table);
+void xmlFreeNotationTable(xmlNotationTablePtr table);
+void xmlDumpNotationTable(xmlNotationTablePtr table);
+
+/* Element Content */
+xmlElementContentPtr xmlNewElementContent(CHAR *name, int type);
+xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
+void xmlFreeElementContent(xmlElementContentPtr cur);
+
+/* Element */
+xmlElementPtr xmlAddElementDecl(xmlDtdPtr dtd, CHAR *name, int type, 
                                        xmlElementContentPtr content);
-extern xmlElementContentPtr xmlNewElementContent(CHAR *name, int type);
-extern xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
-extern void xmlFreeElementContent(xmlElementContentPtr cur);
+xmlElementTablePtr xmlCopyElementTable(xmlElementTablePtr table);
+void xmlFreeElementTable(xmlElementTablePtr table);
+void xmlDumpElementTable(xmlElementTablePtr table);
 
-extern xmlElementTablePtr xmlCopyElementTable(xmlElementTablePtr table);
-extern void xmlFreeElementTable(xmlElementTablePtr table);
-extern void xmlDumpElementTable(xmlElementTablePtr table);
+/* Enumeration */
+xmlEnumerationPtr xmlCreateEnumeration(CHAR *name);
+void xmlFreeEnumeration(xmlEnumerationPtr cur);
+xmlEnumerationPtr xmlCopyEnumeration(xmlEnumerationPtr cur);
+
+/* Attribute */
+xmlAttributePtr xmlAddAttributeDecl(xmlDtdPtr dtd, CHAR *elem,
+	       CHAR *name, int type, int def,
+	       CHAR *defaultValue, xmlEnumerationPtr tree);
+xmlAttributeTablePtr xmlCopyAttributeTable(xmlAttributeTablePtr table);
+void xmlFreeAttributeTable(xmlAttributeTablePtr table);
+void xmlDumpAttributeTable(xmlAttributeTablePtr table);
+
 #endif /* __XML_VALID_H__ */
diff --git a/parser.c b/parser.c
index 671bf73..bd65d70 100644
--- a/parser.c
+++ b/parser.c
@@ -31,6 +31,7 @@
 #include "parser.h"
 #include "entities.h"
 #include "valid.h"
+#include "parserInternals.h"
 
 /************************************************************************
  *									*
@@ -122,7 +123,8 @@
  *          pop it and return the next char.
  *
  * TODO A deallocation of the popped Input structure is needed
- * return values: the current CHAR in the parser context
+ *
+ * Returns the current CHAR in the parser context
  */
 CHAR
 xmlPopInput(xmlParserCtxtPtr ctxt) {
@@ -151,7 +153,7 @@
  * @entity:  an Entity pointer
  *
  * Create a new input stream based on a memory buffer.
- * return vakues: the new input stream
+ * Returns the new input stream
  */
 xmlParserInputPtr
 xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {
@@ -189,7 +191,7 @@
  * @entity:  an Entity pointer
  *
  * Create a new input stream based on a memory buffer.
- * return vakues: the new input stream
+ * Returns the new input stream
  */
 xmlParserInputPtr
 xmlNewStringInputStream(xmlParserCtxtPtr ctxt, CHAR *string) {
@@ -708,9 +710,9 @@
  * @len:  the len of @cur
  *
  * a strndup for array of CHAR's
- * return values: a new CHAR * or NULL
+ *
+ * Returns a new CHAR * or NULL
  */
-
 CHAR *
 xmlStrndup(const CHAR *cur, int len) {
     CHAR *ret = malloc((len + 1) * sizeof(CHAR));
@@ -730,9 +732,9 @@
  * @cur:  the input CHAR *
  *
  * a strdup for array of CHAR's
- * return values: a new CHAR * or NULL
+ *
+ * Returns a new CHAR * or NULL
  */
-
 CHAR *
 xmlStrdup(const CHAR *cur) {
     const CHAR *p = cur;
@@ -747,7 +749,8 @@
  * @len:  the len of @cur
  *
  * a strndup for char's to CHAR's
- * return values: a new CHAR * or NULL
+ *
+ * Returns a new CHAR * or NULL
  */
 
 CHAR *
@@ -772,7 +775,8 @@
  * @len:  the len of @cur
  *
  * a strdup for char's to CHAR's
- * return values: a new CHAR * or NULL
+ *
+ * Returns a new CHAR * or NULL
  */
 
 CHAR *
@@ -789,7 +793,8 @@
  * @str2:  the second CHAR *
  *
  * a strcmp for CHAR's
- * return values: the integer result of the comparison
+ *
+ * Returns the integer result of the comparison
  */
 
 int
@@ -810,7 +815,8 @@
  * @len:  the max comparison length
  *
  * a strncmp for CHAR's
- * return values: the integer result of the comparison
+ *
+ * Returns the integer result of the comparison
  */
 
 int
@@ -833,7 +839,8 @@
  * @val:  the CHAR to search
  *
  * a strchr for CHAR's
- * return values: the CHAR * for the first occurence or NULL.
+ *
+ * Returns the CHAR * for the first occurence or NULL.
  */
 
 CHAR *
@@ -850,7 +857,8 @@
  * @str:  the CHAR * array
  *
  * lenght of a CHAR's string
- * return values: the number of CHAR contained in the ARRAY.
+ *
+ * Returns the number of CHAR contained in the ARRAY.
  */
 
 int
@@ -867,12 +875,13 @@
 
 /**
  * xmlStrncat:
- * @first:  the original CHAR * array
+ * @cur:  the original CHAR * array
  * @add:  the CHAR * array added
  * @len:  the length of @add
  *
  * a strncat for array of CHAR's
- * return values: a new CHAR * containing the concatenated string.
+ *
+ * Returns a new CHAR * containing the concatenated string.
  */
 
 CHAR *
@@ -899,13 +908,13 @@
 
 /**
  * xmlStrcat:
- * @first:  the original CHAR * array
+ * @cur:  the original CHAR * array
  * @add:  the CHAR * array added
  *
  * a strcat for array of CHAR's
- * return values: a new CHAR * containing the concatenated string.
+ *
+ * Returns a new CHAR * containing the concatenated string.
  */
-
 CHAR *
 xmlStrcat(CHAR *cur, const CHAR *add) {
     const CHAR *p = add;
@@ -933,7 +942,8 @@
  * Is this a sequence of blank chars that one can ignore ?
  *
  * TODO: to be corrected accodingly to DTD information if available
- * return values: 1 if ignorable 0 otherwise.
+ *
+ * Returns 1 if ignorable 0 otherwise.
  */
 
 static int areBlanks(xmlParserCtxtPtr ctxt, const CHAR *str, int len) {
@@ -1017,7 +1027,8 @@
  *
  * [NS 4] NCNameChar ::= Letter | Digit | '.' | '-' | '_' |
  *                       CombiningChar | Extender
- * return values: the namespace name or NULL
+ *
+ * Returns the namespace name or NULL
  */
 
 CHAR *
@@ -1052,7 +1063,8 @@
  * [NS 6] Prefix ::= NCName
  *
  * [NS 7] LocalPart ::= NCName
- * return values: the function returns the local part, and prefix is updated
+ *
+ * Returns the function returns the local part, and prefix is updated
  *   to get the Prefix if any.
  */
 
@@ -1080,7 +1092,8 @@
  * [NS 1] NSDef ::= PrefixDef Eq SystemLiteral
  *
  * [NS 2] PrefixDef ::= 'xmlns' (':' NCName)?
- * return values: the namespace name
+ *
+ * Returns the namespace name
  */
 
 CHAR *
@@ -1104,7 +1117,8 @@
  * @ctxt:  an XML parser context
  *
  * [OLD] Parse and return a string between quotes or doublequotes
- * return values: the string parser or NULL.
+ *
+ * Returns the string parser or NULL.
  */
 CHAR *
 xmlParseQuotedString(xmlParserCtxtPtr ctxt) {
@@ -1260,7 +1274,8 @@
  * [5] Name ::= (Letter | '_' | ':') (NameChar)*
  *
  * [6] Names ::= Name (S Name)*
- * return values: the Name parsed or NULL
+ *
+ * Returns the Name parsed or NULL
  */
 
 CHAR *
@@ -1293,7 +1308,8 @@
  * [7] Nmtoken ::= (NameChar)+
  *
  * [8] Nmtokens ::= Nmtoken (S Nmtoken)*
- * return values: the Nmtoken parsed or NULL
+ *
+ * Returns the Nmtoken parsed or NULL
  */
 
 CHAR *
@@ -1323,7 +1339,8 @@
  *
  * [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' |
  *	               "'" ([^%&'] | PEReference | Reference)* "'"
- * return values: the EntityValue parsed or NULL
+ *
+ * Returns the EntityValue parsed or NULL
  */
 
 CHAR *
@@ -1417,7 +1434,8 @@
  *
  * [10] AttValue ::= '"' ([^<&"] | Reference)* '"' |
  *                   "'" ([^<&'] | Reference)* "'"
- * return values: the AttValue parsed or NULL.
+ *
+ * Returns the AttValue parsed or NULL.
  */
 
 CHAR *
@@ -1536,7 +1554,8 @@
  * parse an XML Literal
  *
  * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
- * return values: the SystemLiteral parsed or NULL
+ *
+ * Returns the SystemLiteral parsed or NULL
  */
 
 CHAR *
@@ -1584,7 +1603,10 @@
  * @ctxt:  an XML parser context
  *
  * parse an XML public literal
- * return values: the PubidLiteral parsed or NULL.
+ *
+ * [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
+ *
+ * Returns the PubidLiteral parsed or NULL.
  */
 
 CHAR *
@@ -1637,7 +1659,6 @@
  * if we are within a CDATA section ']]>' marks an end of section.
  *
  * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
- * return values: 
  */
 
 void
@@ -1676,17 +1697,26 @@
  * xmlParseExternalID:
  * @ctxt:  an XML parser context
  * @publicID:  a CHAR** receiving PubidLiteral
+ * @strict: indicate whether we should restrict parsing to only
+ *          production [75], see NOTE below
  *
- * Parse an External ID
+ * Parse an External ID or a Public ID
+ *
+ * NOTE: Productions [75] and [83] interract badly since [75] can generate
+ *       'PUBLIC' S PubidLiteral S SystemLiteral
  *
  * [75] ExternalID ::= 'SYSTEM' S SystemLiteral
  *                   | 'PUBLIC' S PubidLiteral S SystemLiteral
- * return values: the function returns SystemLiteral and in the second
- *                case publicID receives PubidLiteral
+ *
+ * [83] PublicID ::= 'PUBLIC' S PubidLiteral
+ *
+ * Returns the function returns SystemLiteral and in the second
+ *                case publicID receives PubidLiteral, is strict is off
+ *                it is possible to return NULL and have publicID set.
  */
 
 CHAR *
-xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID) {
+xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID, int strict) {
     CHAR *URI = NULL;
 
     if ((CUR == 'S') && (NXT(1) == 'Y') &&
@@ -1725,11 +1755,27 @@
 	          "xmlParseExternalID: PUBLIC, no Public Identifier\n");
 	    ctxt->wellFormed = 0;
 	}
-	if (!IS_BLANK(CUR)) {
-	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
-		ctxt->sax->error(ctxt,
-		    "Space required after the Public Identifier\n");
-	    ctxt->wellFormed = 0;
+	if (strict) {
+	    /*
+	     * We don't handle [83] so "S SystemLiteral" is required.
+	     */
+	    if (!IS_BLANK(CUR)) {
+		if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+		    ctxt->sax->error(ctxt,
+			"Space required after the Public Identifier\n");
+		ctxt->wellFormed = 0;
+	    }
+	} else {
+	    /*
+	     * We handle [83] so we return immediately, if 
+	     * "S SystemLiteral" is not detected. From a purely parsing
+	     * point of view that's a nice mess.
+	     */
+	    const CHAR *ptr = CUR_PTR;
+	    if (!IS_BLANK(*ptr)) return(NULL);
+	    
+	    while (IS_BLANK(*ptr)) ptr++;
+	    if ((*ptr != '\'') || (*ptr != '"')) return(NULL);
 	}
         SKIP_BLANKS;
 	URI = xmlParseSystemLiteral(ctxt);
@@ -1745,7 +1791,8 @@
 
 /**
  * xmlParseComment:
- * @create:  should we create a node
+ * @ctxt:  an XML parser context
+ * @create: should we create a node, or just skip the content
  *
  * Skip an XML (SGML) comment <!-- .... -->
  *  This may or may not create a node (depending on the context)
@@ -1756,9 +1803,11 @@
  *
  * TODO: this should call a SAX function which will handle (or not) the
  *       creation of the comment !
- * return values: 
+ *
+ * Returns the comment node, or NULL
  */
-xmlNodePtr xmlParseComment(xmlParserCtxtPtr ctxt, int create) {
+xmlNodePtr
+xmlParseComment(xmlParserCtxtPtr ctxt, int create) {
     xmlNodePtr ret = NULL;
     const CHAR *q, *start;
     const CHAR *r;
@@ -1808,7 +1857,8 @@
  * parse the name of a PI
  *
  * [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
- * return values: the PITarget name or NULL
+ *
+ * Returns the PITarget name or NULL
  */
 
 CHAR *
@@ -1834,7 +1884,8 @@
  * parse an XML Processing Instruction.
  *
  * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
- * return values: the PI name or NULL
+ *
+ * The processing is transfered to SAX once parsed.
  */
 
 void
@@ -1932,47 +1983,68 @@
  *
  * [82] NotationDecl ::= '<!NOTATION' S Name S (ExternalID |  PublicID) S? '>'
  *
- * [83] PublicID ::= 'PUBLIC' S PubidLiteral
- *
- * NOTE: Actually [75] and [83] interract badly since [75] can generate
- *       'PUBLIC' S PubidLiteral S SystemLiteral
- *
  * Hence there is actually 3 choices:
  *     'PUBLIC' S PubidLiteral
  *     'PUBLIC' S PubidLiteral S SystemLiteral
  * and 'SYSTEM' S SystemLiteral
  *
- * TODO: no handling of the values parsed !
+ * See the NOTE on xmlParseExternalID().
  */
 
 void
 xmlParseNotationDecl(xmlParserCtxtPtr ctxt) {
     CHAR *name;
+    CHAR *Pubid;
+    CHAR *Systemid;
     
     if ((CUR == '<') && (NXT(1) == '!') &&
         (NXT(2) == 'N') && (NXT(3) == 'O') &&
         (NXT(4) == 'T') && (NXT(5) == 'A') &&
         (NXT(6) == 'T') && (NXT(7) == 'I') &&
-        (NXT(8) == 'O') && (NXT(9) == 'N') &&
-        (IS_BLANK(NXT(10)))) {
+        (NXT(8) == 'O') && (NXT(9) == 'N')) {
 	SKIP(10);
-        SKIP_BLANKS;
-
-        name = xmlParseName(ctxt);
-	if (name == NULL) {
+	if (!IS_BLANK(CUR)) {
 	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
-	        ctxt->sax->error(ctxt,
-	        "xmlParseAttributeListDecl: no name for Element\n");
+		ctxt->sax->error(ctxt, "Space required after '<!NOTATION'\n");
 	    ctxt->wellFormed = 0;
 	    return;
 	}
 	SKIP_BLANKS;
+
+        name = xmlParseName(ctxt);
+	if (name == NULL) {
+	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+	        ctxt->sax->error(ctxt, "NOTATION: Name expected here\n");
+	    ctxt->wellFormed = 0;
+	    return;
+	}
+	if (!IS_BLANK(CUR)) {
+	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+		ctxt->sax->error(ctxt, 
+		     "Space required after the NOTATION name'\n");
+	    ctxt->wellFormed = 0;
+	    return;
+	}
+	SKIP_BLANKS;
+
 	/*
-	 * TODO !!!
+	 * Parse the IDs.
 	 */
-	while ((IS_CHAR(CUR)) && (CUR != '>'))
+	Systemid = xmlParseExternalID(ctxt, &Pubid, 1);
+	SKIP_BLANKS;
+
+	if (CUR == '>') {
 	    NEXT;
+	    xmlAddNotationDecl(ctxt->doc->intSubset, name, Pubid, Systemid);
+	} else {
+	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+		ctxt->sax->error(ctxt,
+		       "'>' required to close NOTATION declaration\n");
+	    ctxt->wellFormed = 0;
+	}
 	free(name);
+	if (Systemid != NULL) free(Systemid);
+	if (Pubid != NULL) free(Pubid);
     }
 }
 
@@ -2042,7 +2114,7 @@
         SKIP_BLANKS;
 
 	/*
-	 * TODO handle the various case of definitions...
+	 * handle the various case of definitions...
 	 */
 	if (isParameter) {
 	    if ((CUR == '"') || (CUR == '\''))
@@ -2053,7 +2125,7 @@
 				    NULL, NULL, value);
 		}
 	    else {
-	        URI = xmlParseExternalID(ctxt, &literal);
+	        URI = xmlParseExternalID(ctxt, &literal, 1);
 		if (URI) {
 		    xmlAddDocEntity(ctxt->doc, name,
 		                    XML_EXTERNAL_PARAMETER_ENTITY,
@@ -2067,7 +2139,7 @@
 				XML_INTERNAL_GENERAL_ENTITY,
 				NULL, NULL, value);
 	    } else {
-	        URI = xmlParseExternalID(ctxt, &literal);
+	        URI = xmlParseExternalID(ctxt, &literal, 1);
 		if ((CUR != '>') && (!IS_BLANK(CUR))) {
 		    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
 			ctxt->sax->error(ctxt,
@@ -2172,36 +2244,158 @@
 }
 
 /**
+ * xmlParseNotationType:
+ * @ctxt:  an XML parser context
+ *
+ * parse an Notation attribute type.
+ *
+ * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
+ *
+ * Note: the leading 'NOTATION' S part has already being parsed...
+ *
+ * Returns: the notation attribute tree built while parsing
+ */
+
+xmlEnumerationPtr
+xmlParseNotationType(xmlParserCtxtPtr ctxt) {
+    CHAR *name;
+    xmlEnumerationPtr ret = NULL, last = NULL, cur;
+
+    if (CUR != '(') {
+	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+	    ctxt->sax->error(ctxt, "'(' required to start 'NOTATION'\n");
+	ctxt->wellFormed = 0;
+	return(NULL);
+    }
+    do {
+        NEXT;
+	SKIP_BLANKS;
+        name = xmlParseName(ctxt);
+	if (name == NULL) {
+	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+		ctxt->sax->error(ctxt, 
+		                 "Name expected in NOTATION declaration\n");
+	    ctxt->wellFormed = 0;
+	    return(ret);
+	}
+	cur = xmlCreateEnumeration(name);
+	free(name);
+	if (cur == NULL) return(ret);
+	if (last == NULL) ret = last = cur;
+	else {
+	    last->next = cur;
+	    last = cur;
+	}
+	SKIP_BLANKS;
+    } while (CUR == '|');
+    if (CUR != ')') {
+	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+	    ctxt->sax->error(ctxt,
+	                     "')' required to finish NOTATION declaration\n");
+	ctxt->wellFormed = 0;
+	return(ret);
+    }
+    NEXT;
+    return(ret);
+}
+
+/**
+ * xmlParseEnumerationType:
+ * @ctxt:  an XML parser context
+ *
+ * parse an Enumeration attribute type.
+ *
+ * [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
+ *
+ * Returns: the enumeration attribute tree built while parsing
+ */
+
+xmlEnumerationPtr
+xmlParseEnumerationType(xmlParserCtxtPtr ctxt) {
+    CHAR *name;
+    xmlEnumerationPtr ret = NULL, last = NULL, cur;
+
+    if (CUR != '(') {
+	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+	    ctxt->sax->error(ctxt,
+	                     "'(' required to start ATTLIST enumeration\n");
+	ctxt->wellFormed = 0;
+	return(NULL);
+    }
+    do {
+        NEXT;
+	SKIP_BLANKS;
+        name = xmlParseNmtoken(ctxt);
+	if (name == NULL) {
+	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+		ctxt->sax->error(ctxt, 
+		                 "NmToken expected in ATTLIST enumeration\n");
+	    ctxt->wellFormed = 0;
+	    return(ret);
+	}
+	cur = xmlCreateEnumeration(name);
+	free(name);
+	if (cur == NULL) return(ret);
+	if (last == NULL) ret = last = cur;
+	else {
+	    last->next = cur;
+	    last = cur;
+	}
+	SKIP_BLANKS;
+    } while (CUR == '|');
+    if (CUR != ')') {
+	if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+	    ctxt->sax->error(ctxt,
+	                     "')' required to finish ATTLIST enumeration\n");
+	ctxt->wellFormed = 0;
+	return(ret);
+    }
+    NEXT;
+    return(ret);
+}
+
+/**
  * xmlParseEnumeratedType:
  * @ctxt:  an XML parser context
- * @name:  ???
- * @:  
+ * @tree:  the enumeration tree built while parsing
  *
- * parse and Enumerated attribute type.
+ * parse an Enumerated attribute type.
  *
  * [57] EnumeratedType ::= NotationType | Enumeration
  *
  * [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
  *
- * [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
  *
- * TODO: not implemented !!!
+ * Returns: XML_ATTRIBUTE_ENUMERATION or XML_ATTRIBUTE_NOTATION
  */
 
-void
-xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, CHAR *name) {
-    /*
-     * TODO !!!
-     */
-    fprintf(stderr, "Production [57] EnumeratedType not yet supported\n");
-    while ((IS_CHAR(CUR)) && (CUR != '>'))
-        NEXT;
+int
+xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) {
+    if ((CUR == 'N') && (NXT(1) == 'O') &&
+        (NXT(2) == 'T') && (NXT(3) == 'A') &&
+        (NXT(4) == 'T') && (NXT(5) == 'I') &&
+	(NXT(6) == 'O') && (NXT(7) == 'N')) {
+	SKIP(8);
+	if (!IS_BLANK(CUR)) {
+	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+	        ctxt->sax->error(ctxt, "Space required after 'NOTATION'\n");
+	    ctxt->wellFormed = 0;
+	    return(0);
+	}
+        SKIP_BLANKS;
+	*tree = xmlParseNotationType(ctxt);
+	if (*tree == NULL) return(0);
+	return(XML_ATTRIBUTE_NOTATION);
+    }
+    *tree = xmlParseEnumerationType(ctxt);
+    if (*tree == NULL) return(0);
+    return(XML_ATTRIBUTE_ENUMERATION);
 }
 
 /**
  * xmlParseAttributeType:
  * @ctxt:  an XML parser context
- * @name:  ???
+ * @tree:  the enumeration tree built while parsing
  *
  * parse the Attribute list def for an element
  *
@@ -2212,24 +2406,23 @@
  * [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' |
  *                        'ENTITIES' | 'NMTOKEN' | 'NMTOKENS'
  *
- * Returns: the attribute type
+ * Returns the attribute type
  */
 int 
-xmlParseAttributeType(xmlParserCtxtPtr ctxt, CHAR *name) {
-    /* TODO !!! */
+xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree) {
     if ((CUR == 'C') && (NXT(1) == 'D') &&
         (NXT(2) == 'A') && (NXT(3) == 'T') &&
         (NXT(4) == 'A')) {
 	SKIP(5);
-	return(XML_ATTRIBUTE_STRING);
-     } else if ((CUR == 'I') && (NXT(1) == 'D')) {
-        SKIP(2);
-	return(XML_ATTRIBUTE_ID);
+	return(XML_ATTRIBUTE_CDATA);
      } else if ((CUR == 'I') && (NXT(1) == 'D') &&
         (NXT(2) == 'R') && (NXT(3) == 'E') &&
         (NXT(4) == 'F')) {
 	SKIP(5);
 	return(XML_ATTRIBUTE_IDREF);
+     } else if ((CUR == 'I') && (NXT(1) == 'D')) {
+        SKIP(2);
+	return(XML_ATTRIBUTE_ID);
      } else if ((CUR == 'I') && (NXT(1) == 'D') &&
         (NXT(2) == 'R') && (NXT(3) == 'E') &&
         (NXT(4) == 'F') && (NXT(5) == 'S')) {
@@ -2249,17 +2442,17 @@
      } else if ((CUR == 'N') && (NXT(1) == 'M') &&
         (NXT(2) == 'T') && (NXT(3) == 'O') &&
         (NXT(4) == 'K') && (NXT(5) == 'E') &&
-        (NXT(6) == 'N')) {
-	SKIP(7);
-	return(XML_ATTRIBUTE_NMTOKEN);
+        (NXT(6) == 'N') && (NXT(7) == 'S')) {
+	SKIP(8);
+	return(XML_ATTRIBUTE_NMTOKENS);
      } else if ((CUR == 'N') && (NXT(1) == 'M') &&
         (NXT(2) == 'T') && (NXT(3) == 'O') &&
         (NXT(4) == 'K') && (NXT(5) == 'E') &&
-        (NXT(6) == 'N') && (NXT(7) == 'S')) {
-	return(XML_ATTRIBUTE_NMTOKENS);
+        (NXT(6) == 'N')) {
+	SKIP(7);
+	return(XML_ATTRIBUTE_NMTOKEN);
      }
-     xmlParseEnumeratedType(ctxt, name);
-     return(XML_ATTRIBUTE_ENUMERATED);
+     return(xmlParseEnumeratedType(ctxt, tree));
 }
 
 /**
@@ -2272,14 +2465,13 @@
  *
  * [53] AttDef ::= S Name S AttType S DefaultDecl
  *
- * TODO: not implemented !!!
  */
 void
 xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
     CHAR *elemName;
     CHAR *attrName;
+    xmlEnumerationPtr tree = NULL;
 
-    /* TODO !!! */
     if ((CUR == '<') && (NXT(1) == '!') &&
         (NXT(2) == 'A') && (NXT(3) == 'T') &&
         (NXT(4) == 'T') && (NXT(5) == 'L') &&
@@ -2322,7 +2514,7 @@
 	    }
 	    SKIP_BLANKS;
 
-	    type = xmlParseAttributeType(ctxt, attrName);
+	    type = xmlParseAttributeType(ctxt, &tree);
 	    if (type <= 0) break;
 
 	    if (!IS_BLANK(CUR)) {
@@ -2353,6 +2545,8 @@
 		    "xmlParseAttributeListDecl: detected internal error\n");
 		break;
 	    }
+	    xmlAddAttributeDecl(ctxt->doc->intSubset, elemName, attrName,
+	                        type, def, defaultValue, tree);
 	    if (attrName != NULL)
 		free(attrName);
 	    if (defaultValue != NULL)
@@ -2416,6 +2610,7 @@
 		n->c1 = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT);
 	        cur->c2 = n;
 		cur = n;
+		free(elem);
 	    }
 	    SKIP_BLANKS;
 	    elem = xmlParseName(ctxt);
@@ -2430,12 +2625,15 @@
 	    SKIP_BLANKS;
 	}
 	if ((CUR == ')') && (NXT(1) == '*')) {
-	    if (elem != NULL)
+	    if (elem != NULL) {
 		cur->c2 = xmlNewElementContent(elem,
 		                               XML_ELEMENT_CONTENT_ELEMENT);
+	        free(elem);
+            }
 	    ret->ocur = XML_ELEMENT_CONTENT_MULT;
 	    SKIP(2);
 	} else {
+	    if (elem != NULL) free(elem);
 	    if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
 		ctxt->sax->error(ctxt, 
 		    "xmlParseElementMixedContentDecl : '|' or ')*' expected\n");
@@ -2507,6 +2705,7 @@
 	} else {
 	    ret->ocur = XML_ELEMENT_CONTENT_ONCE;
 	}
+	free(elem);
     }
     SKIP_BLANKS;
     while (CUR != ')') {
@@ -2600,6 +2799,7 @@
 		return(NULL);
 	    }
 	    last = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT);
+	    free(elem);
 	}
 	if (CUR == '?') {
 	    ret->ocur = XML_ELEMENT_CONTENT_OPT;
@@ -2699,6 +2899,8 @@
  * [45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'
  *
  * TODO There is a check [ VC: Unique Element Type Declaration ]
+ *
+ * Returns the type of the element, or -1 in case of error
  */
 int
 xmlParseElementDecl(xmlParserCtxtPtr ctxt) {
@@ -2805,7 +3007,8 @@
  *
  * [66] CharRef ::= '&#' [0-9]+ ';' |
  *                  '&#x' [0-9a-fA-F]+ ';'
- * return values: the value parsed
+ *
+ * Returns the value parsed
  */
 CHAR *
 xmlParseCharRef(xmlParserCtxtPtr ctxt) {
@@ -2879,7 +3082,8 @@
  * parse ENTITY references declarations
  *
  * [68] EntityRef ::= '&' Name ';'
- * return values: the entity ref string or NULL if directly as input stream.
+ *
+ * Returns the entity ref string or NULL if directly as input stream.
  */
 CHAR *
 xmlParseEntityRef(xmlParserCtxtPtr ctxt) {
@@ -2987,7 +3191,8 @@
  * parse Reference declarations
  *
  * [67] Reference ::= EntityRef | CharRef
- * return values: the entity string or NULL if handled directly by pushing
+ *
+ * Returns the entity string or NULL if handled directly by pushing
  *      the entity value as the input.
  */
 CHAR *
@@ -3014,7 +3219,8 @@
  * parse PEReference declarations
  *
  * [69] PEReference ::= '%' Name ';'
- * return values: the entity content or NULL if handled directly.
+ *
+ * Returns the entity content or NULL if handled directly.
  */
 CHAR *
 xmlParsePEReference(xmlParserCtxtPtr ctxt) {
@@ -3097,7 +3303,7 @@
     /*
      * Check for SystemID and ExternalID
      */
-    URI = xmlParseExternalID(ctxt, &ExternalID);
+    URI = xmlParseExternalID(ctxt, &ExternalID, 1);
     SKIP_BLANKS;
 
     dtd = xmlCreateIntSubset(ctxt->doc, name, ExternalID, URI);
@@ -3167,9 +3373,12 @@
  *
  * Also the case QName == xmlns:??? is handled independently as a namespace
  * definition.
+ *
+ * Returns the attribute just parsed of NULL in case of error.
  */
 
-xmlAttrPtr xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlNodePtr node) {
+xmlAttrPtr
+xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlNodePtr node) {
     CHAR *name, *val;
     CHAR *ns;
     CHAR *value = NULL;
@@ -3264,10 +3473,11 @@
  *
  * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>'
  *
- * return values: the XML new node or NULL.
+ * Returns the XML new node or NULL.
  */
 
-xmlNodePtr xmlParseStartTag(xmlParserCtxtPtr ctxt) {
+xmlNodePtr
+xmlParseStartTag(xmlParserCtxtPtr ctxt) {
     CHAR *namespace, *name;
     xmlNsPtr ns = NULL;
     xmlNodePtr ret = NULL;
@@ -3368,7 +3578,7 @@
  *
  * [9] ETag ::= '</' QName S? '>'
  *    
- * return values: tagPtr receive the tag name just read
+ * tagPtr receive the tag name just read
  */
 
 void
@@ -3576,11 +3786,13 @@
  * [39] element ::= EmptyElemTag | STag content ETag
  *
  * [41] Attribute ::= Name Eq AttValue
- * return values: the XML new node or NULL
+ *
+ * Returns the XML new node or NULL
  */
 
 
-xmlNodePtr xmlParseElement(xmlParserCtxtPtr ctxt) {
+xmlNodePtr
+xmlParseElement(xmlParserCtxtPtr ctxt) {
     xmlNodePtr ret;
     const CHAR *openTag = CUR_PTR;
     xmlParserNodeInfo node_info;
@@ -3702,7 +3914,8 @@
  * parse the XML version value.
  *
  * [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+
- * return values: the string giving the XML version number, or NULL
+ *
+ * Returns the string giving the XML version number, or NULL
  */
 CHAR *
 xmlParseVersionNum(xmlParserCtxtPtr ctxt) {
@@ -3729,7 +3942,7 @@
  * 
  * [25] Eq ::= S? '=' S?
  *
- * return values: the version string, e.g. "1.0"
+ * Returns the version string, e.g. "1.0"
  */
 
 CHAR *
@@ -3789,7 +4002,7 @@
  *
  * [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
  *
- * return values: the encoding name value or NULL
+ * Returns the encoding name value or NULL
  */
 CHAR *
 xmlParseEncName(xmlParserCtxtPtr ctxt) {
@@ -3823,7 +4036,7 @@
  *
  * TODO: this should setup the conversion filters.
  *
- * return values: the encoding value or NULL
+ * Returns the encoding value or NULL
  */
 
 CHAR *
@@ -3884,7 +4097,8 @@
  *
  * [32] SDDecl ::= S 'standalone' Eq
  *                 (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no')'"')) 
- * return values: 1 if standalone, 0 otherwise
+ *
+ * Returns 1 if standalone, 0 otherwise
  */
 
 int
@@ -4073,7 +4287,7 @@
  *
  * [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
  *
- * return values: 0, -1 in case of error. the parser context is augmented
+ * Returns 0, -1 in case of error. the parser context is augmented
  *                as a result of the parsing.
  */
 
@@ -4193,10 +4407,11 @@
  * It use the given SAX function block to handle the parsing callback.
  * If sax is NULL, fallback to the default DOM tree building routines.
  * 
- * return values: the resulting document tree
+ * Returns the resulting document tree
  */
 
-xmlDocPtr xmlSAXParseDoc(xmlSAXHandlerPtr sax, CHAR *cur, int recovery) {
+xmlDocPtr
+xmlSAXParseDoc(xmlSAXHandlerPtr sax, CHAR *cur, int recovery) {
     xmlDocPtr ret;
     xmlParserCtxtPtr ctxt;
     xmlParserInputPtr input;
@@ -4249,10 +4464,11 @@
  *
  * parse an XML in-memory document and build a tree.
  * 
- * return values: the resulting document tree
+ * Returns the resulting document tree
  */
 
-xmlDocPtr xmlParseDoc(CHAR *cur) {
+xmlDocPtr
+xmlParseDoc(CHAR *cur) {
     return(xmlSAXParseDoc(NULL, cur, 0));
 }
 
@@ -4263,10 +4479,11 @@
  * parse an XML in-memory document and build a tree.
  * In the case the document is not Well Formed, a tree is built anyway
  * 
- * return values: the resulting document tree
+ * Returns the resulting document tree
  */
 
-xmlDocPtr xmlRecoverDoc(CHAR *cur) {
+xmlDocPtr
+xmlRecoverDoc(CHAR *cur) {
     return(xmlSAXParseDoc(NULL, cur, 1));
 }
 
@@ -4282,7 +4499,7 @@
  * It use the given SAX function block to handle the parsing callback.
  * If sax is NULL, fallback to the default DOM tree building routines.
  *
- * return values: the resulting document tree
+ * Returns the resulting document tree
  */
 
 xmlDocPtr xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename,
@@ -4412,7 +4629,7 @@
  * parse an XML file and build a tree. Automatic support for ZLIB/Compress
  * compressed document is provided by default if found at compile-time.
  *
- * return values: the resulting document tree
+ * Returns the resulting document tree
  */
 
 xmlDocPtr xmlParseFile(const char *filename) {
@@ -4427,7 +4644,7 @@
  * compressed document is provided by default if found at compile-time.
  * In the case the document is not Well Formed, a tree is built anyway
  *
- * return values: the resulting document tree
+ * Returns the resulting document tree
  */
 
 xmlDocPtr xmlRecoverFile(const char *filename) {
@@ -4437,7 +4654,7 @@
 /**
  * xmlSAXParseMemory :
  * @sax:  the SAX handler block
- * @cur:  an pointer to a char array
+ * @buffer:  an pointer to a char array
  * @size:  the siwe of the array
  * @recovery:  work in recovery mode, i.e. tries to read no Well Formed
  *             documents
@@ -4448,10 +4665,10 @@
  * 
  * TODO : plug some encoding conversion routines here. !!!
  *
- * return values: the resulting document tree
+ * Returns the resulting document tree
  */
-
-xmlDocPtr xmlSAXParseMemory(xmlSAXHandlerPtr sax, char *buffer, int size,
+xmlDocPtr
+xmlSAXParseMemory(xmlSAXHandlerPtr sax, char *buffer, int size,
                             int recovery) {
     xmlDocPtr ret;
     xmlParserCtxtPtr ctxt;
@@ -4507,12 +4724,12 @@
 
 /**
  * xmlParseMemory :
- * @cur:  an pointer to a char array
+ * @buffer:  an pointer to a char array
  * @size:  the size of the array
  *
  * parse an XML in-memory block and build a tree.
  * 
- * return values: the resulting document tree
+ * Returns the resulting document tree
  */
 
 xmlDocPtr xmlParseMemory(char *buffer, int size) {
@@ -4521,13 +4738,13 @@
 
 /**
  * xmlRecoverMemory :
- * @cur:  an pointer to a char array
+ * @buffer:  an pointer to a char array
  * @size:  the size of the array
  *
  * parse an XML in-memory block and build a tree.
  * In the case the document is not Well Formed, a tree is built anyway
  * 
- * return values: the resulting document tree
+ * Returns the resulting document tree
  */
 
 xmlDocPtr xmlRecoverMemory(char *buffer, int size) {
@@ -4588,7 +4805,6 @@
  * contents from the parser context. The buffer parameter must not be
  * NULL, but the filename parameter can be
  */
-
 void
 xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const CHAR* buffer,
                              const char* filename)
@@ -4623,7 +4839,7 @@
  *
  * Find the parser node info struct for a given node
  * 
- * return values: an xmlParserNodeInfo block pointer or NULL
+ * Returns an xmlParserNodeInfo block pointer or NULL
  */
 const xmlParserNodeInfo* xmlParserFindNodeInfo(const xmlParserCtxt* ctx,
                                                const xmlNode* node)
@@ -4678,7 +4894,7 @@
  * xmlParserFindNodeInfoIndex : Find the index that the info record for
  *   the given node is or should be at in a sorted sequence
  *
- * return values: a long indicating the position of the record
+ * Returns a long indicating the position of the record
  */
 unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeq* seq,
                                          const xmlNode* node)
@@ -4711,13 +4927,13 @@
 /**
  * xmlParserAddNodeInfo:
  * @ctxt:  an XML parser context
- * @seq:  a node info sequence pointer
+ * @info:  a node info sequence pointer
  *
  * Insert node info record into the sorted sequence
  */
 void
 xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt, 
-                          const xmlParserNodeInfo* info)
+                     const xmlParserNodeInfo* info)
 {
   unsigned long pos;
   static unsigned int block_size = 5;
diff --git a/parser.h b/parser.h
index a06d481..ca0835f 100644
--- a/parser.h
+++ b/parser.h
@@ -26,24 +26,28 @@
     const CHAR *cur;                  /* Current char being parsed */
     int line;                         /* Current line */
     int col;                          /* Current column */
-} xmlParserInput, *xmlParserInputPtr;
+} xmlParserInput;
+typedef xmlParserInput *xmlParserInputPtr;
 
-typedef struct xmlParserNodeInfo {
+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;
+} _xmlParserNodeInfo;
+typedef _xmlParserNodeInfo xmlParserNodeInfo;
 
 typedef struct xmlParserNodeInfoSeq {
   unsigned long maximum;
   unsigned long length;
   xmlParserNodeInfo* buffer;
-} xmlParserNodeInfoSeq, *xmlParserNodeInfoSeqPtr;
+} _xmlParserNodeInfoSeq;
+typedef _xmlParserNodeInfoSeq xmlParserNodeInfoSeq;
+typedef xmlParserNodeInfoSeq *xmlParserNodeInfoSeqPtr;
 
-typedef struct xmlParserCtxt {
+typedef struct _xmlParserCtxt {
     struct xmlSAXHandler *sax;        /* The SAX handler */
     xmlDocPtr doc;                    /* the document being built */
     int            wellFormed;        /* is the document well formed */
@@ -62,7 +66,9 @@
 
     int record_info;                  /* Whether node info should be kept */
     xmlParserNodeInfoSeq node_seq;    /* info about each node parsed */
-} xmlParserCtxt, *xmlParserCtxtPtr;
+} _xmlParserCtxt;
+typedef _xmlParserCtxt xmlParserCtxt;
+typedef xmlParserCtxt *xmlParserCtxtPtr;
 
 /*
  * a SAX Locator.
@@ -73,7 +79,9 @@
     const CHAR *(*getSystemId)(xmlParserCtxtPtr ctxt);
     int (*getLineNumber)(xmlParserCtxtPtr ctxt);
     int (*getColumnNumber)(xmlParserCtxtPtr ctxt);
-} xmlSAXLocator, *xmlSAXLocatorPtr;
+} _xmlSAXLocator;
+typedef _xmlSAXLocator xmlSAXLocator;
+typedef xmlSAXLocator *xmlSAXLocatorPtr;
 
 /*
  * a SAX Exception.
@@ -120,7 +128,8 @@
     warningSAXFunc warning;
     errorSAXFunc error;
     fatalErrorSAXFunc fatalError;
-} xmlSAXHandler, *xmlSAXHandlerPtr;
+} xmlSAXHandler;
+typedef xmlSAXHandler *xmlSAXHandlerPtr;
 
 /*
  * Global variables: just the SAX interface tables we are looking for full
@@ -130,61 +139,58 @@
 extern xmlSAXHandler xmlDefaultSAXHandler;
 
 #include "entities.h"
+#include "error.h"
 
 /*
  * CHAR handling
  */
-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);
+CHAR *xmlStrdup(const CHAR *cur);
+CHAR *xmlStrndup(const CHAR *cur, int len);
+CHAR *xmlStrchr(const CHAR *str, CHAR val);
+int xmlStrcmp(const CHAR *str1, const CHAR *str2);
+int xmlStrncmp(const CHAR *str1, const CHAR *str2, int len);
+int xmlStrlen(const CHAR *str);
+CHAR *xmlStrcat(CHAR *cur, const CHAR *add);
+CHAR *xmlStrncat(CHAR *cur, const CHAR *add, int len);
 
 /*
  * Interfaces
  */
-extern xmlDocPtr xmlParseDoc(CHAR *cur);
-extern xmlDocPtr xmlParseMemory(char *buffer, int size);
-extern xmlDocPtr xmlParseFile(const char *filename);
+xmlDocPtr xmlParseDoc(CHAR *cur);
+xmlDocPtr xmlParseMemory(char *buffer, int size);
+xmlDocPtr xmlParseFile(const char *filename);
 
 /*
  * Recovery mode 
  */
-extern xmlDocPtr xmlRecoverDoc(CHAR *cur);
-extern xmlDocPtr xmlRecoverMemory(char *buffer, int size);
-extern xmlDocPtr xmlRecoverFile(const char *filename);
+xmlDocPtr xmlRecoverDoc(CHAR *cur);
+xmlDocPtr xmlRecoverMemory(char *buffer, int size);
+xmlDocPtr xmlRecoverFile(const char *filename);
 
 /*
  * Internal routines
  */
-extern int xmlParseDocument(xmlParserCtxtPtr ctxt);
-extern xmlDocPtr xmlSAXParseDoc(xmlSAXHandlerPtr sax, CHAR *cur, int recovery);
-extern xmlDocPtr xmlSAXParseMemory(xmlSAXHandlerPtr sax, char *buffer,
+int xmlParseDocument(xmlParserCtxtPtr ctxt);
+xmlDocPtr xmlSAXParseDoc(xmlSAXHandlerPtr sax, CHAR *cur, int recovery);
+xmlDocPtr xmlSAXParseMemory(xmlSAXHandlerPtr sax, char *buffer,
                                    int size, int recovery);
-extern xmlDocPtr xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename,
+xmlDocPtr xmlSAXParseFile(xmlSAXHandlerPtr sax, const char *filename,
                                  int recovery);
-extern void xmlInitParserCtxt(xmlParserCtxtPtr ctx);
-extern void xmlClearParserCtxt(xmlParserCtxtPtr ctx);
-extern void xmlSetupParserForBuffer(xmlParserCtxtPtr ctx, const CHAR* buffer,
+void xmlInitParserCtxt(xmlParserCtxtPtr ctxt);
+void xmlClearParserCtxt(xmlParserCtxtPtr ctxt);
+void xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, 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);
+const xmlParserNodeInfo* xmlParserFindNodeInfo(const xmlParserCtxt* ctxt,
+                                               const xmlNode* node);
+void xmlInitNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
+void xmlClearNodeInfoSeq(xmlParserNodeInfoSeqPtr seq);
 unsigned long xmlParserFindNodeInfoIndex(const xmlParserNodeInfoSeq* seq,
                                          const xmlNode* node);
-extern void xmlParserAddNodeInfo(xmlParserCtxtPtr ctx,
-                                 const xmlParserNodeInfo* info);
+void xmlParserAddNodeInfo(xmlParserCtxtPtr ctxt,
+                          const xmlParserNodeInfo* info);
 
-extern void xmlParserWarning(xmlParserCtxtPtr ctxt, const char *msg, ...);
-extern void xmlParserError(xmlParserCtxtPtr ctxt, const char *msg, ...);
-extern void xmlDefaultSAXHandlerInit(void);
+void xmlDefaultSAXHandlerInit(void);
 #ifdef __cplusplus
 }
 #endif
diff --git a/parserInternals.h b/parserInternals.h
new file mode 100644
index 0000000..9cd6a21
--- /dev/null
+++ b/parserInternals.h
@@ -0,0 +1,128 @@
+/*
+ * parserInternals.h : internals routines exported by the parser.
+ *
+ * See Copyright for the status of this software.
+ *
+ * Daniel.Veillard@w3.org
+ */
+
+#ifndef __XML_PARSER_INTERNALS_H__
+#define __XML_PARSER_INTERNALS_H__
+
+#include "parser.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Entities
+ */
+void
+xmlHandleEntity(xmlParserCtxtPtr ctxt, xmlEntityPtr entity);
+
+/*
+ * Namespaces.
+ */
+CHAR *
+xmlNamespaceParseNCName(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlNamespaceParseQName(xmlParserCtxtPtr ctxt, CHAR **prefix);
+CHAR *
+xmlNamespaceParseNSDef(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseQuotedString(xmlParserCtxtPtr ctxt);
+void
+xmlParseNamespace(xmlParserCtxtPtr ctxt);
+
+/*
+ * Generic production rules
+ */
+CHAR *
+xmlParseName(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseNmtoken(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseEntityValue(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseAttValue(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseSystemLiteral(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParsePubidLiteral(xmlParserCtxtPtr ctxt);
+void
+xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata);
+CHAR *
+xmlParseExternalID(xmlParserCtxtPtr ctxt, CHAR **publicID, int strict);
+xmlNodePtr 
+xmlParseComment(xmlParserCtxtPtr ctxt, int create);
+CHAR *
+xmlParsePITarget(xmlParserCtxtPtr ctxt);
+void
+xmlParsePI(xmlParserCtxtPtr ctxt);
+void
+xmlParseNotationDecl(xmlParserCtxtPtr ctxt);
+void
+xmlParseEntityDecl(xmlParserCtxtPtr ctxt);
+int
+xmlParseDefaultDecl(xmlParserCtxtPtr ctxt, CHAR **value);
+xmlEnumerationPtr
+xmlParseNotationType(xmlParserCtxtPtr ctxt);
+xmlEnumerationPtr
+xmlParseEnumerationType(xmlParserCtxtPtr ctxt);
+int
+xmlParseEnumeratedType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree);
+int
+xmlParseAttributeType(xmlParserCtxtPtr ctxt, xmlEnumerationPtr *tree);
+void
+xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt);
+xmlElementContentPtr
+xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt);
+xmlElementContentPtr
+xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt);
+int
+xmlParseElementContentDecl(xmlParserCtxtPtr ctxt, CHAR *name,
+                           xmlElementContentPtr *result);
+int
+xmlParseElementDecl(xmlParserCtxtPtr ctxt);
+void
+xmlParseMarkupDecl(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseCharRef(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseEntityRef(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseReference(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParsePEReference(xmlParserCtxtPtr ctxt);
+void
+xmlParseDocTypeDecl(xmlParserCtxtPtr ctxt);
+xmlAttrPtr 
+xmlParseAttribute(xmlParserCtxtPtr ctxt, xmlNodePtr node);
+xmlNodePtr 
+xmlParseStartTag(xmlParserCtxtPtr ctxt);
+void
+xmlParseEndTag(xmlParserCtxtPtr ctxt, xmlNsPtr *nsPtr, CHAR **tagPtr);
+void
+xmlParseCDSect(xmlParserCtxtPtr ctxt);
+void
+xmlParseContent(xmlParserCtxtPtr ctxt);
+xmlNodePtr 
+xmlParseElement(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseVersionNum(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseVersionInfo(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseEncName(xmlParserCtxtPtr ctxt);
+CHAR *
+xmlParseEncodingDecl(xmlParserCtxtPtr ctxt);
+int
+xmlParseSDDecl(xmlParserCtxtPtr ctxt);
+void
+xmlParseXMLDecl(xmlParserCtxtPtr ctxt);
+void
+xmlParseMisc(xmlParserCtxtPtr ctxt);
+
+
+#endif /* __XML_PARSER_INTERNALS_H__ */
diff --git a/tree.c b/tree.c
index d963d2d..a331fe1 100644
--- a/tree.c
+++ b/tree.c
@@ -35,7 +35,7 @@
     } else {								\
         while (ulccur->next != NULL) ulccur = ulccur->next;		\
 	(n)->last = ulccur;						\
-}   }
+}}
 
 /************************************************************************
  *									*
@@ -77,7 +77,7 @@
  * @prefix:  the prefix for the namespace
  *
  * Creation of a new Namespace.
- * return values: returns a new namespace pointer
+ * Returns returns a new namespace pointer
  */
 xmlNsPtr
 xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *prefix) {
@@ -132,7 +132,7 @@
  * @prefix:  the prefix for the namespace
  *
  * Creation of a Namespace, the old way using PI and without scoping, to AVOID.
- * return values: returns a new namespace pointer
+ * Returns returns a new namespace pointer
  */
 xmlNsPtr
 xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *prefix) {
@@ -237,7 +237,7 @@
  * @SystemID:  the system ID
  *
  * Creation of a new DTD.
- * return values: a pointer to the new DTD structure
+ * Returns a pointer to the new DTD structure
  */
 xmlDtdPtr
 xmlNewDtd(xmlDocPtr doc, const CHAR *name,
@@ -271,7 +271,9 @@
 	cur->SystemID = xmlStrdup(SystemID); 
     else
         cur->SystemID = NULL;
+    cur->notations = NULL;
     cur->elements = NULL;
+    cur->attributes = NULL;
     cur->entities = NULL;
     if (doc != NULL)
 	doc->extSubset = cur;
@@ -286,8 +288,8 @@
  * @ExternalID:  the external ID
  * @SystemID:  the system ID
  *
- * Creatte the internal subset of a document
- * return values: a pointer to the new DTD structure
+ * Create the internal subset of a document
+ * Returns a pointer to the new DTD structure
  */
 xmlDtdPtr
 xmlCreateIntSubset(xmlDocPtr doc, const CHAR *name,
@@ -322,7 +324,9 @@
 	cur->SystemID = xmlStrdup(SystemID); 
     else
         cur->SystemID = NULL;
+    cur->notations = NULL;
     cur->elements = NULL;
+    cur->attributes = NULL;
     cur->entities = NULL;
     if (doc != NULL)
 	doc->intSubset = cur;
@@ -345,8 +349,12 @@
     if (cur->name != NULL) free((char *) cur->name);
     if (cur->SystemID != NULL) free((char *) cur->SystemID);
     if (cur->ExternalID != NULL) free((char *) cur->ExternalID);
+    if (cur->notations != NULL)
+        xmlFreeNotationTable((xmlNotationTablePtr) cur->notations);
     if (cur->elements != NULL)
         xmlFreeElementTable((xmlElementTablePtr) cur->elements);
+    if (cur->attributes != NULL)
+        xmlFreeAttributeTable((xmlAttributeTablePtr) cur->attributes);
     if (cur->entities != NULL)
         xmlFreeEntitiesTable((xmlEntitiesTablePtr) cur->entities);
     memset(cur, -1, sizeof(xmlDtd));
@@ -357,7 +365,7 @@
  * xmlNewDoc:
  * @version:  CHAR string giving the version of XML "1.0"
  *
- * Create a new document
+ * Returns a new document
  */
 xmlDocPtr
 xmlNewDoc(const CHAR *version) {
@@ -424,11 +432,11 @@
  * xmlStringLenGetNodeList:
  * @doc:  the document
  * @value:  the value of the text
- * @int len:  the length of the string value
+ * @len:  the length of the string value
  *
  * Parse the value string and build the node list associated. Should
  * produce a flat tree with only TEXTs and ENTITY_REFs.
- * return values: a pointer to the first child
+ * Returns a pointer to the first child
  */
 xmlNodePtr
 xmlStringLenGetNodeList(xmlDocPtr doc, const CHAR *value, int len) {
@@ -539,7 +547,7 @@
  *
  * Parse the value string and build the node list associated. Should
  * produce a flat tree with only TEXTs and ENTITY_REFs.
- * return values: a pointer to the first child
+ * Returns a pointer to the first child
  */
 xmlNodePtr
 xmlStringGetNodeList(xmlDocPtr doc, const CHAR *value) {
@@ -651,7 +659,7 @@
  *
  * Returns the string equivalent to the text contained in the Node list
  * made of TEXTs and ENTITY_REFs
- * return values: a pointer to the string copy, the calller must free it.
+ * Returns a pointer to the string copy, the calller must free it.
  */
 CHAR *
 xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine) {
@@ -701,7 +709,7 @@
  * @value:  the value of the attribute
  *
  * Create a new property carried by a node.
- * return values: a pointer to the attribute
+ * Returns a pointer to the attribute
  */
 xmlAttrPtr
 xmlNewProp(xmlNodePtr node, const CHAR *name, const CHAR *value) {
@@ -757,7 +765,7 @@
  * @value:  the value of the attribute
  *
  * Create a new property carried by a document.
- * return values: a pointer to the attribute
+ * Returns a pointer to the attribute
  */
 xmlAttrPtr
 xmlNewDocProp(xmlDocPtr doc, const CHAR *name, const CHAR *value) {
@@ -835,12 +843,11 @@
  * xmlNewNode:
  * @ns:  namespace if any
  * @name:  the node name
- * @content:  the text content if any
  *
  * Creation of a new node element. @ns and @content are optionnal (NULL).
  * If content is non NULL, a child list containing the TEXTs and
  * ENTITY_REFs node will be created.
- * return values: a pointer to the new node object.
+ * Returns a pointer to the new node object.
  */
 xmlNodePtr
 xmlNewNode(xmlNsPtr ns, const CHAR *name) {
@@ -888,7 +895,7 @@
  *
  * Creation of a new node element within a document. @ns and @content
  * are optionnal (NULL).
- * return values: a pointer to the new node object.
+ * Returns a pointer to the new node object.
  */
 xmlNodePtr
 xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
@@ -900,7 +907,7 @@
         cur->doc = doc;
 	if (content != NULL) {
 	    cur->childs = xmlStringGetNodeList(doc, content);
-	    UPDATE_LAST_CHILD(cur);
+	    UPDATE_LAST_CHILD(cur)
 	}
     }
     return(cur);
@@ -912,7 +919,7 @@
  * @content:  the text content
  *
  * Creation of a new text node.
- * return values: a pointer to the new node object.
+ * Returns a pointer to the new node object.
  */
 xmlNodePtr
 xmlNewText(const CHAR *content) {
@@ -952,7 +959,7 @@
  * @name:  the reference name, or the reference string with & and ;
  *
  * Creation of a new reference node.
- * return values: a pointer to the new node object.
+ * Returns a pointer to the new node object.
  */
 xmlNodePtr
 xmlNewReference(xmlDocPtr doc, const CHAR *name) {
@@ -1003,7 +1010,7 @@
  * @content:  the text content
  *
  * Creation of a new text node within a document.
- * return values: a pointer to the new node object.
+ * Returns a pointer to the new node object.
  */
 xmlNodePtr
 xmlNewDocText(xmlDocPtr doc, const CHAR *content) {
@@ -1020,7 +1027,7 @@
  * @len:  the text len.
  *
  * Creation of a new text node with an extra parameter for the content's lenght
- * return values: a pointer to the new node object.
+ * Returns a pointer to the new node object.
  */
 xmlNodePtr
 xmlNewTextLen(const CHAR *content, int len) {
@@ -1062,7 +1069,7 @@
  *
  * Creation of a new text node with an extra content lenght parameter. The
  * text node pertain to a given document.
- * return values: a pointer to the new node object.
+ * Returns a pointer to the new node object.
  */
 xmlNodePtr
 xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len) {
@@ -1078,7 +1085,7 @@
  * @content:  the comment content
  *
  * Creation of a new node containing a comment.
- * return values: a pointer to the new node object.
+ * Returns a pointer to the new node object.
  */
 xmlNodePtr
 xmlNewComment(CHAR *content) {
@@ -1113,12 +1120,12 @@
 }
 
 /**
- * xmlNewComment:
+ * xmlNewDocComment:
  * @doc:  the document
  * @content:  the comment content
  *
  * Creation of a new node containing a commentwithin a document.
- * return values: a pointer to the new node object.
+ * Returns a pointer to the new node object.
  */
 xmlNodePtr
 xmlNewDocComment(xmlDocPtr doc, CHAR *content) {
@@ -1140,7 +1147,7 @@
  * Creation of a new child element, added at the end of @parent childs list.
  * @ns and @content parameters are optionnal (NULL). If content is non NULL,
  * a child list containing the TEXTs and ENTITY_REFs node will be created.
- * return values: a pointer to the new node object.
+ * Returns a pointer to the new node object.
  */
 xmlNodePtr
 xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
@@ -1191,7 +1198,7 @@
  * @cur:  the child node
  *
  * Add a new child element, to @parent, at the end of the child list.
- * return values: the child or NULL in case of error.
+ * Returns the child or NULL in case of error.
  */
 xmlNodePtr
 xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) {
@@ -1231,7 +1238,7 @@
 	    if (text->next != NULL)
 		text->next->prev = text;
 	    parent->childs = text;
-	    UPDATE_LAST_CHILD(parent);
+	    UPDATE_LAST_CHILD(parent)
 	    free(parent->content);
 	    parent->content = NULL;
 	}
@@ -1254,7 +1261,7 @@
  * @parent:  the parent node
  *
  * Search the last child of a node.
- * return values: the last child or NULL if none.
+ * Returns the last child or NULL if none.
  */
 xmlNodePtr
 xmlGetLastChild(xmlNodePtr parent) {
@@ -1534,7 +1541,7 @@
     }
     if (node->childs != NULL)
         ret->childs = xmlStaticCopyNodeList(node->childs, doc, ret);
-    UPDATE_LAST_CHILD(ret);
+    UPDATE_LAST_CHILD(ret)
     return(ret);
 }
 
@@ -1636,6 +1643,15 @@
     if (dtd->entities != NULL)
         ret->entities = (void *) xmlCopyEntitiesTable(
 	                    (xmlEntitiesTablePtr) dtd->entities);
+    if (dtd->notations != NULL)
+        ret->notations = (void *) xmlCopyNotationTable(
+	                    (xmlNotationTablePtr) dtd->notations);
+    if (dtd->elements != NULL)
+        ret->elements = (void *) xmlCopyElementTable(
+	                    (xmlElementTablePtr) dtd->elements);
+    if (dtd->attributes != NULL)
+        ret->attributes = (void *) xmlCopyAttributeTable(
+	                    (xmlAttributeTablePtr) dtd->attributes);
     /*
      * TODO: support for Element definitions.
      */
@@ -1690,7 +1706,7 @@
  * directly by this node if it's a TEXT node or the aggregate string
  * of the values carried by this node child's (TEXT and ENTITY_REF).
  * Entity references are substitued.
- * Return value: a new CHAR * or NULL if no content is available.
+ * Returns a new CHAR * or NULL if no content is available.
  */
 CHAR *
 xmlNodeGetContent(xmlNodePtr cur) {
@@ -1740,7 +1756,7 @@
 	    }
 	    if (cur->childs != NULL) xmlFreeNode(cur->childs);
 	    cur->childs = xmlStringGetNodeList(cur->doc, content);
-	    UPDATE_LAST_CHILD(cur);
+	    UPDATE_LAST_CHILD(cur)
 	    break;
         case XML_ATTRIBUTE_NODE:
 	    break;
@@ -1788,7 +1804,7 @@
 	    }
 	    if (cur->childs != NULL) xmlFreeNode(cur->childs);
 	    cur->childs = xmlStringLenGetNodeList(cur->doc, content, len);
-	    UPDATE_LAST_CHILD(cur);
+	    UPDATE_LAST_CHILD(cur)
 	    break;
         case XML_ATTRIBUTE_NODE:
 	    break;
@@ -1845,7 +1861,7 @@
 	    } else {
 	        if (cur->content != NULL) {
 		    cur->childs = xmlStringGetNodeList(cur->doc, cur->content);
-		    UPDATE_LAST_CHILD(cur);
+		    UPDATE_LAST_CHILD(cur)
 		    free(cur->content);
 		    cur->content = NULL;
 		    last = cur->last;
@@ -1906,7 +1922,7 @@
  * @second:  the second text node being merged
  * 
  * Merge two text nodes into one
- * Return values: the first text node augmented
+ * Returns the first text node augmented
  */
 xmlNodePtr
 xmlTextMerge(xmlNodePtr first, xmlNodePtr second) {
@@ -1930,7 +1946,7 @@
  * recurse on the parents until it finds the defined namespace
  * or return NULL otherwise.
  * @nameSpace can be NULL, this is a search for the default namespace.
- * return values: the namespace pointer or NULL.
+ * Returns the namespace pointer or NULL.
  */
 xmlNsPtr
 xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const CHAR *nameSpace) {
@@ -1968,7 +1984,7 @@
  *
  * Search a Ns aliasing a given URI. Recurse on the parents until it finds
  * the defined namespace or return NULL otherwise.
- * return values: the namespace pointer or NULL.
+ * Returns the namespace pointer or NULL.
  */
 xmlNsPtr
 xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const CHAR *href) {
@@ -2003,7 +2019,7 @@
  *
  * Search and get the value of an attribute associated to a node
  * This does the entity substitution.
- * return values: the attribute value or NULL if not found.
+ * Returns the attribute value or NULL if not found.
  */
 CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name) {
     xmlAttrPtr prop = node->properties;
@@ -2028,7 +2044,7 @@
  * @value:  the attribute value
  *
  * Set (or reset) an attribute carried by a node.
- * return values: the attribute pointer.
+ * Returns the attribute pointer.
  */
 xmlAttrPtr
 xmlSetProp(xmlNodePtr node, const CHAR *name, const CHAR *value) {
@@ -2054,7 +2070,7 @@
  * @node:  the node
  * 
  * Is this node a Text node ?
- * return values: 1 yes, 0 no
+ * Returns 1 yes, 0 no
  */
 int
 xmlNodeIsText(xmlNodePtr node) {
@@ -2065,7 +2081,7 @@
 }
 
 /**
- * xmlNodeIsText:
+ * xmlTextConcat:
  * @node:  the node
  * @content:  the content
  * @len:  @content lenght
@@ -2274,15 +2290,20 @@
 	xmlBufferWriteCHAR(cur->SystemID);
 	xmlBufferWriteChar("\"");
     }
-    if ((cur->entities == NULL) && (cur->elements == NULL)) {
+    if ((cur->entities == NULL) && (cur->elements == NULL) &&
+        (cur->attributes == NULL) && (cur->notations == NULL)) {
 	xmlBufferWriteChar(">\n");
 	return;
     }
     xmlBufferWriteChar(" [\n");
     if (cur->entities != NULL)
 	xmlDumpEntitiesTable((xmlEntitiesTablePtr) cur->entities);
+    if (cur->notations != NULL)
+	xmlDumpNotationTable((xmlNotationTablePtr) cur->notations);
     if (cur->elements != NULL)
 	xmlDumpElementTable((xmlElementTablePtr) cur->elements);
+    if (cur->attributes != NULL)
+	xmlDumpAttributeTable((xmlAttributeTablePtr) cur->attributes);
     xmlBufferWriteChar("]");
 
     /* TODO !!! a lot more things to dump ... */
@@ -2513,7 +2534,7 @@
  * @doc:  the document
  *
  * get the compression ratio for a document, ZLIB based
- * return values: 0 (uncompressed) to 9 (max compression)
+ * Returns 0 (uncompressed) to 9 (max compression)
  */
 int
  xmlGetDocCompressMode (xmlDocPtr doc) {
@@ -2541,7 +2562,7 @@
  * xmlGetCompressMode:
  *
  * get the default compression mode used, ZLIB based.
- * return values: 0 (uncompressed) to 9 (max compression)
+ * Returns 0 (uncompressed) to 9 (max compression)
  */
 int
  xmlGetCompressMode(void) {
diff --git a/tree.h b/tree.h
index ba77f76..4443836 100644
--- a/tree.h
+++ b/tree.h
@@ -55,41 +55,67 @@
 
 /*
  * a DTD Notation definition
- * TODO !!!!
  */
 
+typedef struct xmlNotation {
+    const CHAR               *name;	/* Notation name */
+    const CHAR               *PublicID;	/* Public identifier, if any */
+    const CHAR               *SystemID;	/* System identifier, if any */
+} xmlNotation;
+typedef xmlNotation *xmlNotationPtr;
+
 /*
  * a DTD Attribute definition
- * TODO !!!!
  */
 
-#define XML_ATTRIBUTE_NONE		1
-#define XML_ATTRIBUTE_REQUIRED		2
-#define XML_ATTRIBUTE_IMPLIED		3
-#define XML_ATTRIBUTE_FIXED		4
+typedef enum {
+    XML_ATTRIBUTE_CDATA = 1,
+    XML_ATTRIBUTE_ID,
+    XML_ATTRIBUTE_IDREF	,
+    XML_ATTRIBUTE_IDREFS,
+    XML_ATTRIBUTE_ENTITY,
+    XML_ATTRIBUTE_ENTITIES,
+    XML_ATTRIBUTE_NMTOKEN,
+    XML_ATTRIBUTE_NMTOKENS,
+    XML_ATTRIBUTE_ENUMERATION,
+    XML_ATTRIBUTE_NOTATION
+} xmlAttributeType;
 
-#define XML_ATTRIBUTE_STRING		1
-#define XML_ATTRIBUTE_ID		2
-#define XML_ATTRIBUTE_IDREF		3
-#define XML_ATTRIBUTE_IDREFS		4
-#define XML_ATTRIBUTE_ENTITY		5
-#define XML_ATTRIBUTE_ENTITIES		6
-#define XML_ATTRIBUTE_NMTOKEN		7
-#define XML_ATTRIBUTE_NMTOKENS		8
-#define XML_ATTRIBUTE_ENUMERATED	9
+typedef enum {
+    XML_ATTRIBUTE_NONE = 1,
+    XML_ATTRIBUTE_REQUIRED,
+    XML_ATTRIBUTE_IMPLIED,
+    XML_ATTRIBUTE_FIXED
+} xmlAttributeDefault;
+
+typedef struct xmlEnumeration {
+    struct xmlEnumeration    *next;	/* next one */
+    const CHAR               *name;	/* Enumeration name */
+} xmlEnumeration;
+typedef xmlEnumeration *xmlEnumerationPtr;
+
+typedef struct xmlAttribute {
+    const CHAR            *elem;	/* Element holding the attribute */
+    const CHAR            *name;	/* Attribute name */
+    xmlAttributeType       type;	/* The type */
+    xmlAttributeDefault    def;		/* the default */
+    const CHAR            *defaultValue;/* or the default value */
+    xmlEnumerationPtr      tree;        /* or the enumeration tree if any */
+} xmlAttribute;
+typedef xmlAttribute *xmlAttributePtr;
 
 /*
  * a DTD Element definition.
  */
 typedef enum {
-    XML_ELEMENT_CONTENT_PCDATA=1,
+    XML_ELEMENT_CONTENT_PCDATA = 1,
     XML_ELEMENT_CONTENT_ELEMENT,
     XML_ELEMENT_CONTENT_SEQ,
     XML_ELEMENT_CONTENT_OR
 } xmlElementContentType;
 
 typedef enum {
-    XML_ELEMENT_CONTENT_ONCE=1,
+    XML_ELEMENT_CONTENT_ONCE = 1,
     XML_ELEMENT_CONTENT_OPT,
     XML_ELEMENT_CONTENT_MULT,
     XML_ELEMENT_CONTENT_PLUS
@@ -101,10 +127,11 @@
     const CHAR               *name;	/* Element name */
     struct xmlElementContent *c1;	/* first child */
     struct xmlElementContent *c2;	/* second child */
-} xmlElementContent, *xmlElementContentPtr;
+} xmlElementContent;
+typedef xmlElementContent *xmlElementContentPtr;
 
 typedef enum {
-    XML_ELEMENT_TYPE_EMPTY=1,
+    XML_ELEMENT_TYPE_EMPTY = 1,
     XML_ELEMENT_TYPE_ANY,
     XML_ELEMENT_TYPE_MIXED,
     XML_ELEMENT_TYPE_ELEMENT
@@ -114,7 +141,8 @@
     const CHAR          *name;		/* Element name */
     xmlElementTypeVal    type;		/* The type */
     xmlElementContentPtr content;	/* the allowed element content */
-} xmlElement, *xmlElementPtr;
+} xmlElement;
+typedef xmlElement *xmlElementPtr;
 
 /*
  * An XML namespace.
@@ -123,7 +151,7 @@
  */
 
 typedef enum {
-    XML_GLOBAL_NAMESPACE=1,	/* old style global namespace */
+    XML_GLOBAL_NAMESPACE = 1,	/* old style global namespace */
     XML_LOCAL_NAMESPACE		/* new style local scoping */
 } xmlNsType;
 
@@ -132,7 +160,8 @@
     xmlNsType      type;	/* global or local */
     const CHAR    *href;	/* URL for the namespace */
     const CHAR    *prefix;	/* prefix for the namespace */
-} xmlNs, *xmlNsPtr;
+} xmlNs;
+typedef xmlNs *xmlNsPtr;
 
 /*
  * An XML DtD, as defined by <!DOCTYPE.
@@ -141,10 +170,13 @@
     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          *notations;   /* Hash table for notations if any */
     void          *elements;    /* Hash table for elements if any */
+    void          *attributes;  /* Hash table for attributes if any */
     void          *entities;    /* Hash table for entities if any */
     /* struct xmlDtd *next;	 * next  link for this document  */
-} xmlDtd, *xmlDtdPtr;
+} xmlDtd;
+typedef xmlDtd *xmlDtdPtr;
 
 /*
  * A attribute of an XML node.
@@ -159,7 +191,8 @@
     struct xmlAttr *next;	/* parent->childs link */
     const CHAR     *name;       /* the name of the property */
     struct xmlNode *val;        /* the value of the property */
-} xmlAttr, *xmlAttrPtr;
+} xmlAttr;
+typedef xmlAttr *xmlAttrPtr;
 
 /*
  * A node in an XML tree.
@@ -181,7 +214,9 @@
     xmlNs          *ns;         /* pointer to the associated namespace */
     xmlNs          *nsDef;      /* namespace definitions on this node */
     CHAR           *content;    /* the content */
-} xmlNode, *xmlNodePtr;
+} _xmlNode;
+typedef _xmlNode xmlNode;
+typedef _xmlNode *xmlNodePtr;
 
 /*
  * An XML document.
@@ -201,7 +236,9 @@
     struct xmlDtd  *extSubset;	/* the document external subset */
     struct xmlNs   *oldNs;	/* Global namespace, the old way */
     struct xmlNode *root;	/* the document tree */
-} xmlDoc, *xmlDocPtr;
+} _xmlDoc;
+typedef _xmlDoc xmlDoc;
+typedef xmlDoc *xmlDocPtr;
 
 /*
  * Variables.
@@ -213,110 +250,110 @@
 /*
  * Creating/freeing new structures
  */
-extern xmlDtdPtr xmlCreateIntSubset(xmlDocPtr doc, const CHAR *name,
+xmlDtdPtr xmlCreateIntSubset(xmlDocPtr doc, const CHAR *name,
                     const CHAR *ExternalID, const CHAR *SystemID);
-extern xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
+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 xmlNewDocProp(xmlDocPtr doc, const CHAR *name,
+void xmlFreeDtd(xmlDtdPtr cur);
+xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *prefix);
+xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *prefix);
+void xmlFreeNs(xmlNsPtr cur);
+xmlDocPtr xmlNewDoc(const CHAR *version);
+void xmlFreeDoc(xmlDocPtr cur);
+xmlAttrPtr xmlNewDocProp(xmlDocPtr doc, const CHAR *name,
                                 const CHAR *value);
-extern xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
+xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name,
                              const CHAR *value);
-extern void xmlFreePropList(xmlAttrPtr cur);
-extern void xmlFreeProp(xmlAttrPtr cur);
-extern xmlAttrPtr xmlCopyProp(xmlAttrPtr cur);
-extern xmlAttrPtr xmlCopyPropList(xmlAttrPtr cur);
-extern xmlDtdPtr xmlCopyDtd(xmlDtdPtr dtd);
-extern xmlDocPtr xmlCopyDoc(xmlDocPtr doc, int recursive);
+void xmlFreePropList(xmlAttrPtr cur);
+void xmlFreeProp(xmlAttrPtr cur);
+xmlAttrPtr xmlCopyProp(xmlAttrPtr cur);
+xmlAttrPtr xmlCopyPropList(xmlAttrPtr cur);
+xmlDtdPtr xmlCopyDtd(xmlDtdPtr dtd);
+xmlDocPtr xmlCopyDoc(xmlDocPtr doc, int recursive);
 
 /*
  * Creating new nodes
  */
-extern xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
+xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
                              const CHAR *name, CHAR *content);
-extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name);
-extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
+xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name);
+xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
                               const CHAR *name, CHAR *content);
-extern xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
-extern xmlNodePtr xmlNewText(const CHAR *content);
-extern xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
-extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
-extern xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
-extern xmlNodePtr xmlNewComment(CHAR *content);
-extern xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name);
-extern xmlNodePtr xmlCopyNode(xmlNodePtr node, int recursive);
-extern xmlNodePtr xmlCopyNodeList(xmlNodePtr node);
+xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
+xmlNodePtr xmlNewText(const CHAR *content);
+xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
+xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
+xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
+xmlNodePtr xmlNewComment(CHAR *content);
+xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name);
+xmlNodePtr xmlCopyNode(xmlNodePtr node, int recursive);
+xmlNodePtr xmlCopyNodeList(xmlNodePtr node);
 
 /*
  * Navigating
  */
-extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
-extern int xmlNodeIsText(xmlNodePtr node);
+xmlNodePtr xmlGetLastChild(xmlNodePtr parent);
+int xmlNodeIsText(xmlNodePtr node);
 
 /*
  * Changing the structure
  */
-extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
-extern void xmlUnlinkNode(xmlNodePtr cur);
+xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
+void xmlUnlinkNode(xmlNodePtr cur);
 
-extern xmlNodePtr xmlTextMerge(xmlNodePtr first, xmlNodePtr second);
-extern void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
+xmlNodePtr xmlTextMerge(xmlNodePtr first, xmlNodePtr second);
+void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len);
 
-extern void xmlFreeNodeList(xmlNodePtr cur);
-extern void xmlFreeNode(xmlNodePtr cur);
+void xmlFreeNodeList(xmlNodePtr cur);
+void xmlFreeNode(xmlNodePtr cur);
 
 /*
  * Namespaces
  */
-extern xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
+xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node,
                             const CHAR *nameSpace);
-extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
+xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
                                   const CHAR *href);
-extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
-extern xmlNsPtr xmlCopyNamespace(xmlNsPtr cur);
-extern xmlNsPtr xmlCopyNamespaceList(xmlNsPtr cur);
+void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
+xmlNsPtr xmlCopyNamespace(xmlNsPtr cur);
+xmlNsPtr xmlCopyNamespaceList(xmlNsPtr cur);
 
 /*
  * Changing the content.
  */
-extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
+xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
                              const CHAR *value);
-extern CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
-extern xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR *value);
-extern xmlNodePtr xmlStringLenGetNodeList(xmlDocPtr doc, const CHAR *value,
+CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
+xmlNodePtr xmlStringGetNodeList(xmlDocPtr doc, const CHAR *value);
+xmlNodePtr xmlStringLenGetNodeList(xmlDocPtr doc, const CHAR *value,
                                           int len);
-extern CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine);
-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 CHAR *xmlNodeGetContent(xmlNodePtr cur);
+CHAR *xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine);
+void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content);
+void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len);
+void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content);
+void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len);
+CHAR *xmlNodeGetContent(xmlNodePtr cur);
 
 /*
  * Internal, don't use
  */
-extern void xmlBufferWriteCHAR(const CHAR *string);
-extern void xmlBufferWriteChar(const char *string);
+void xmlBufferWriteCHAR(const CHAR *string);
+void xmlBufferWriteChar(const char *string);
 
 /*
  * Saving
  */
-extern void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
-extern void xmlDocDump(FILE *f, xmlDocPtr doc);
+void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size);
+void xmlDocDump(FILE *f, xmlDocPtr cur);
 int xmlSaveFile(const char *filename, xmlDocPtr cur);
 
 /*
  * Compression
  */
-extern int  xmlGetDocCompressMode (xmlDocPtr doc);
-extern void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
-extern int  xmlGetCompressMode(void);
-extern void xmlSetCompressMode(int mode);
+int  xmlGetDocCompressMode (xmlDocPtr doc);
+void xmlSetDocCompressMode (xmlDocPtr doc, int mode);
+int  xmlGetCompressMode(void);
+void xmlSetCompressMode(int mode);
 
 #ifdef __cplusplus
 }
diff --git a/valid.c b/valid.c
index 942e478..3cb6276 100644
--- a/valid.c
+++ b/valid.c
@@ -26,7 +26,7 @@
  *
  * Allocate an element content structure.
  *
- * return values: NULL if not, othervise the new element content structure
+ * Returns NULL if not, othervise the new element content structure
  */
 xmlElementContentPtr
 xmlNewElementContent(CHAR *name, int type) {
@@ -60,6 +60,7 @@
         ret->name = xmlStrdup(name);
     else
         ret->name = NULL;
+    ret->c1 = ret->c2 = NULL;
     return(ret);
 }
 
@@ -69,12 +70,17 @@
  *
  * Build a copy of an element content description.
  * 
- * return values: the new xmlElementContentPtr or NULL in case of error.
+ * Returns the new xmlElementContentPtr or NULL in case of error.
  */
 xmlElementContentPtr
-xmlCopyElementContent(xmlElementContentPtr content) {
-/* TODO !!! */
-    return(NULL);
+xmlCopyElementContent(xmlElementContentPtr cur) {
+    xmlElementContentPtr ret;
+
+    if (cur == NULL) return(NULL);
+    ret = xmlNewElementContent((CHAR *) cur->name, cur->type);
+    if (cur->c1 != NULL) cur->c1 = xmlCopyElementContent(cur->c1);
+    if (cur->c2 != NULL) cur->c2 = xmlCopyElementContent(cur->c2);
+    return(ret);
 }
 
 /**
@@ -85,7 +91,12 @@
  */
 void
 xmlFreeElementContent(xmlElementContentPtr cur) {
-/* TODO !!! */
+    if (cur == NULL) return;
+    if (cur->c1 != NULL) xmlFreeElementContent(cur->c1);
+    if (cur->c2 != NULL) xmlFreeElementContent(cur->c2);
+    if (cur->name != NULL) free((CHAR *) cur->name);
+    memset(cur, -1, sizeof(xmlElementContent));
+    free(cur);
 }
 
 /**
@@ -166,7 +177,7 @@
  *
  * create and initialize an empty element hash table.
  *
- * return values: the xmlElementTablePtr just created or NULL in case of error.
+ * Returns the xmlElementTablePtr just created or NULL in case of error.
  */
 xmlElementTablePtr
 xmlCreateElementTable(void) {
@@ -179,7 +190,7 @@
 	        sizeof(xmlElementTable));
         return(NULL);
     }
-    ret->max_elements = XML_MIN_ENTITIES_TABLE;
+    ret->max_elements = XML_MIN_ELEMENT_TABLE;
     ret->nb_elements = 0;
     ret->table = (xmlElementPtr ) 
          malloc(ret->max_elements * sizeof(xmlElement));
@@ -195,14 +206,17 @@
 
 /**
  * xmlAddElementDecl:
+ * @dtd:  pointer to the DTD
  * @name:  the entity name
+ * @type:  the element type
+ * @content:  the element content tree or NULL
  *
  * Register a new element declaration
  *
- * return values: NULL if not, othervise the entity
+ * Returns NULL if not, othervise the entity
  */
 xmlElementPtr
-xmlAddElementDecl(xmlDtdPtr dtd, char *name, int type, 
+xmlAddElementDecl(xmlDtdPtr dtd, CHAR *name, int type, 
                   xmlElementContentPtr content) {
     xmlElementPtr ret, cur;
     xmlElementTablePtr table;
@@ -318,14 +332,13 @@
     if (elem->name != NULL)
 	free((CHAR *) elem->name);
     memset(elem, -1, sizeof(xmlElement));
-    free(elem);
 }
 
 /**
  * xmlFreeElementTable:
  * @table:  An element table
  *
- * Deallocate the memory used by an entities hash table.
+ * Deallocate the memory used by an element hash table.
  */
 void
 xmlFreeElementTable(xmlElementTablePtr table) {
@@ -346,7 +359,7 @@
  *
  * Build a copy of an element table.
  * 
- * return values: the new xmlElementTablePtr or NULL in case of error.
+ * Returns the new xmlElementTablePtr or NULL in case of error.
  */
 xmlElementTablePtr
 xmlCopyElementTable(xmlElementTablePtr table) {
@@ -431,3 +444,645 @@
 	}
     }
 }
+
+/**
+ * xmlCreateEnumeration:
+ * @name:  the enumeration name or NULL
+ *
+ * create and initialize an enumeration attribute node.
+ *
+ * Returns the xmlEnumerationPtr just created or NULL in case
+ *                of error.
+ */
+xmlEnumerationPtr
+xmlCreateEnumeration(CHAR *name) {
+    xmlEnumerationPtr ret;
+
+    ret = (xmlEnumerationPtr) malloc(sizeof(xmlEnumeration));
+    if (ret == NULL) {
+        fprintf(stderr, "xmlCreateEnumeration : malloc(%d) failed\n",
+	        sizeof(xmlEnumeration));
+        return(NULL);
+    }
+
+    if (name != NULL)
+        ret->name = xmlStrdup(name);
+    else
+        ret->name = NULL;
+    ret->next = NULL;
+    return(ret);
+}
+
+/**
+ * xmlFreeEnumeration:
+ * @cur:  the tree to free.
+ *
+ * free an enumeration attribute node (recursive).
+ */
+void
+xmlFreeEnumeration(xmlEnumerationPtr cur) {
+    if (cur == NULL) return;
+
+    if (cur->next != NULL) xmlFreeEnumeration(cur->next);
+
+    if (cur->name != NULL) free((CHAR *) cur->name);
+    memset(cur, -1, sizeof(xmlEnumeration));
+    free(cur);
+}
+
+/**
+ * xmlCopyEnumeration:
+ * @cur:  the tree to copy.
+ *
+ * Copy an enumeration attribute node (recursive).
+ *
+ * Returns the xmlEnumerationPtr just created or NULL in case
+ *                of error.
+ */
+xmlEnumerationPtr
+xmlCopyEnumeration(xmlEnumerationPtr cur) {
+    xmlEnumerationPtr ret;
+
+    if (cur == NULL) return(NULL);
+    ret = xmlCreateEnumeration((CHAR *) cur->name);
+
+    if (cur->next != NULL) ret->next = xmlCopyEnumeration(cur->next);
+    else ret->next = NULL;
+
+    return(ret);
+}
+
+/**
+ * xmlCreateAttributeTable:
+ *
+ * create and initialize an empty attribute hash table.
+ *
+ * Returns the xmlAttributeTablePtr just created or NULL in case
+ *                of error.
+ */
+xmlAttributeTablePtr
+xmlCreateAttributeTable(void) {
+    xmlAttributeTablePtr ret;
+
+    ret = (xmlAttributeTablePtr) 
+         malloc(sizeof(xmlAttributeTable));
+    if (ret == NULL) {
+        fprintf(stderr, "xmlCreateAttributeTable : malloc(%d) failed\n",
+	        sizeof(xmlAttributeTable));
+        return(NULL);
+    }
+    ret->max_attributes = XML_MIN_ATTRIBUTE_TABLE;
+    ret->nb_attributes = 0;
+    ret->table = (xmlAttributePtr ) 
+         malloc(ret->max_attributes * sizeof(xmlAttribute));
+    if (ret == NULL) {
+        fprintf(stderr, "xmlCreateAttributeTable : malloc(%d) failed\n",
+	        ret->max_attributes * sizeof(xmlAttribute));
+	free(ret);
+        return(NULL);
+    }
+    return(ret);
+}
+
+
+/**
+ * xmlAddAttributeDecl:
+ * @dtd:  pointer to the DTD
+ * @elem:  the element name
+ * @name:  the attribute name
+ * @type:  the attribute type
+ * @def:  the attribute default type
+ * @defaultValue:  the attribute default value
+ * @tree:  if it's an enumeration, the associated list
+ *
+ * Register a new attribute declaration
+ *
+ * Returns NULL if not, othervise the entity
+ */
+xmlAttributePtr
+xmlAddAttributeDecl(xmlDtdPtr dtd, CHAR *elem, CHAR *name, int type, int def,
+                    CHAR *defaultValue, xmlEnumerationPtr tree) {
+    xmlAttributePtr ret, cur;
+    xmlAttributeTablePtr table;
+    int i;
+
+    if (dtd == NULL) {
+        fprintf(stderr, "xmlAddAttributeDecl: dtd == NULL\n");
+	return(NULL);
+    }
+    if (name == NULL) {
+        fprintf(stderr, "xmlAddAttributeDecl: name == NULL\n");
+	return(NULL);
+    }
+    if (elem == NULL) {
+        fprintf(stderr, "xmlAddAttributeDecl: elem == NULL\n");
+	return(NULL);
+    }
+    /* TODO: Lacks verifications !!! */
+    switch (type) {
+        case XML_ATTRIBUTE_CDATA:
+	    break;
+        case XML_ATTRIBUTE_ID:
+	    break;
+        case XML_ATTRIBUTE_IDREF:
+	    break;
+        case XML_ATTRIBUTE_IDREFS:
+	    break;
+        case XML_ATTRIBUTE_ENTITY:
+	    break;
+        case XML_ATTRIBUTE_ENTITIES:
+	    break;
+        case XML_ATTRIBUTE_NMTOKEN:
+	    break;
+        case XML_ATTRIBUTE_NMTOKENS:
+	    break;
+        case XML_ATTRIBUTE_ENUMERATION:
+	    break;
+        case XML_ATTRIBUTE_NOTATION:
+	    break;
+	default:
+	    fprintf(stderr, "xmlAddAttributeDecl: unknown type %d\n", type);
+	    return(NULL);
+    }
+
+    /*
+     * Create the Attribute table if needed.
+     */
+    table = dtd->attributes;
+    if (table == NULL) 
+        table = dtd->attributes = xmlCreateAttributeTable();
+    if (table == NULL) {
+	fprintf(stderr, "xmlAddAttributeDecl: Table creation failed!\n");
+        return(NULL);
+    }
+
+    /*
+     * Validity Check:
+     * Search the DTD for previous declarations of the ATTLIST
+     */
+    for (i = 0;i < table->nb_attributes;i++) {
+        cur = &table->table[i];
+	if ((!xmlStrcmp(cur->name, name)) && (!xmlStrcmp(cur->elem, elem))) {
+	    /*
+	     * The attribute is already defined in this Dtd.
+	     */
+	    fprintf(stderr,
+		    "xmlAddAttributeDecl: %s already defined\n", name);
+	}
+    }
+
+    /*
+     * Grow the table, if needed.
+     */
+    if (table->nb_attributes >= table->max_attributes) {
+        /*
+	 * need more attributes.
+	 */
+	table->max_attributes *= 2;
+	table->table = (xmlAttributePtr) 
+	    realloc(table->table, table->max_attributes * sizeof(xmlAttribute));
+	if (table->table) {
+	    fprintf(stderr, "xmlAddAttributeDecl: out of memory\n");
+	    return(NULL);
+	}
+    }
+    ret = &table->table[table->nb_attributes];
+
+    /*
+     * fill the structure.
+     */
+    ret->type = type;
+    ret->name = xmlStrdup(name);
+    ret->elem = xmlStrdup(elem);
+    ret->def = def;
+    ret->tree = tree;
+    if (defaultValue != NULL)
+	ret->defaultValue = xmlStrdup(defaultValue);
+    else
+        ret->defaultValue = NULL;
+    table->nb_attributes++;
+
+    return(ret);
+}
+
+/**
+ * xmlFreeAttribute:
+ * @elem:  An attribute
+ *
+ * Deallocate the memory used by an attribute definition
+ */
+void
+xmlFreeAttribute(xmlAttributePtr attr) {
+    if (attr == NULL) return;
+    if (attr->tree != NULL)
+        xmlFreeEnumeration(attr->tree);
+    if (attr->elem != NULL)
+	free((CHAR *) attr->elem);
+    if (attr->name != NULL)
+	free((CHAR *) attr->name);
+    if (attr->defaultValue != NULL)
+	free((CHAR *) attr->defaultValue);
+    memset(attr, -1, sizeof(xmlAttribute));
+}
+
+/**
+ * xmlFreeAttributeTable:
+ * @table:  An attribute table
+ *
+ * Deallocate the memory used by an entities hash table.
+ */
+void
+xmlFreeAttributeTable(xmlAttributeTablePtr table) {
+    int i;
+
+    if (table == NULL) return;
+
+    for (i = 0;i < table->nb_attributes;i++) {
+        xmlFreeAttribute(&table->table[i]);
+    }
+    free(table->table);
+    free(table);
+}
+
+/**
+ * xmlCopyAttributeTable:
+ * @table:  An attribute table
+ *
+ * Build a copy of an attribute table.
+ * 
+ * Returns the new xmlAttributeTablePtr or NULL in case of error.
+ */
+xmlAttributeTablePtr
+xmlCopyAttributeTable(xmlAttributeTablePtr table) {
+    xmlAttributeTablePtr ret;
+    xmlAttributePtr cur, attr;
+    int i;
+
+    ret = (xmlAttributeTablePtr) malloc(sizeof(xmlAttributeTable));
+    if (ret == NULL) {
+        fprintf(stderr, "xmlCopyAttributeTable: out of memory !\n");
+	return(NULL);
+    }
+    ret->table = (xmlAttributePtr) malloc(table->max_attributes *
+                                         sizeof(xmlAttribute));
+    if (ret->table == NULL) {
+        fprintf(stderr, "xmlCopyAttributeTable: out of memory !\n");
+	free(ret);
+	return(NULL);
+    }
+    ret->max_attributes = table->max_attributes;
+    ret->nb_attributes = table->nb_attributes;
+    for (i = 0;i < ret->nb_attributes;i++) {
+	cur = &ret->table[i];
+	attr = &table->table[i];
+	cur->type = attr->type;
+	cur->def = attr->def;
+	cur->tree = xmlCopyEnumeration(attr->tree);
+	if (attr->elem != NULL)
+	    cur->elem = xmlStrdup(attr->elem);
+	else
+	    cur->elem = NULL;
+	if (attr->name != NULL)
+	    cur->name = xmlStrdup(attr->name);
+	else
+	    cur->name = NULL;
+	if (attr->defaultValue != NULL)
+	    cur->defaultValue = xmlStrdup(attr->defaultValue);
+	else
+	    cur->defaultValue = NULL;
+    }
+    return(ret);
+}
+
+/**
+ * xmlDumpAttributeTable:
+ * @table:  An attribute table
+ *
+ * This will dump the content of the attribute table as an XML DTD definition
+ *
+ * NOTE: TODO an extra parameter allowing a reentant implementation will
+ *       be added.
+ */
+void
+xmlDumpAttributeTable(xmlAttributeTablePtr table) {
+    int i;
+    xmlAttributePtr cur;
+
+    if (table == NULL) return;
+
+    for (i = 0;i < table->nb_attributes;i++) {
+        cur = &table->table[i];
+	xmlBufferWriteChar("<!ATTLIST ");
+	xmlBufferWriteCHAR(cur->elem);
+	xmlBufferWriteChar(" ");
+	xmlBufferWriteCHAR(cur->name);
+        switch (cur->type) {
+            case XML_ATTRIBUTE_CDATA:
+		xmlBufferWriteChar(" CDATA");
+                break;
+            case XML_ATTRIBUTE_ID:
+		xmlBufferWriteChar(" ID");
+                break;
+            case XML_ATTRIBUTE_IDREF:
+		xmlBufferWriteChar(" IDREF");
+                break;
+            case XML_ATTRIBUTE_IDREFS:
+		xmlBufferWriteChar(" IDREFS");
+                break;
+            case XML_ATTRIBUTE_ENTITY:
+		xmlBufferWriteChar(" ENTITY");
+                break;
+            case XML_ATTRIBUTE_ENTITIES:
+		xmlBufferWriteChar(" ENTITIES");
+                break;
+            case XML_ATTRIBUTE_NMTOKEN:
+		xmlBufferWriteChar(" NMTOKEN");
+                break;
+            case XML_ATTRIBUTE_NMTOKENS:
+		xmlBufferWriteChar(" NMTOKENS");
+                break;
+            case XML_ATTRIBUTE_ENUMERATION:
+                xmlBufferWriteChar(" (pbm)");
+                break;
+            case XML_ATTRIBUTE_NOTATION:
+                xmlBufferWriteChar(" NOTATION (pbm)");
+                break;
+	    default:
+	        fprintf(stderr,
+		    "xmlDumpAttributeTable: internal: unknown type %d\n",
+		        cur->type);
+	}
+        switch (cur->def) {
+            case XML_ATTRIBUTE_NONE:
+                break;
+            case XML_ATTRIBUTE_REQUIRED:
+		xmlBufferWriteChar(" #REQUIRED");
+                break;
+            case XML_ATTRIBUTE_IMPLIED:
+		xmlBufferWriteChar(" #IMPLIED");
+		if (cur->defaultValue != NULL) {
+		    xmlBufferWriteChar(" \"");
+		    xmlBufferWriteCHAR(cur->defaultValue);
+		    xmlBufferWriteChar("\"");
+		}
+                break;
+            case XML_ATTRIBUTE_FIXED:
+		xmlBufferWriteChar(" #FIXED \"");
+		xmlBufferWriteCHAR(cur->defaultValue);
+		xmlBufferWriteChar("\"");
+                break;
+	    default:
+	        fprintf(stderr,
+		    "xmlDumpAttributeTable: internal: unknown default %d\n",
+		        cur->def);
+        }
+        xmlBufferWriteChar(">\n");
+    }
+}
+
+/************************************************************************
+ *									*
+ *				NOTATIONs				*
+ *									*
+ ************************************************************************/
+/**
+ * xmlCreateNotationTable:
+ *
+ * create and initialize an empty notation hash table.
+ *
+ * Returns the xmlNotationTablePtr just created or NULL in case
+ *                of error.
+ */
+xmlNotationTablePtr
+xmlCreateNotationTable(void) {
+    xmlNotationTablePtr ret;
+
+    ret = (xmlNotationTablePtr) 
+         malloc(sizeof(xmlNotationTable));
+    if (ret == NULL) {
+        fprintf(stderr, "xmlCreateNotationTable : malloc(%d) failed\n",
+	        sizeof(xmlNotationTable));
+        return(NULL);
+    }
+    ret->max_notations = XML_MIN_NOTATION_TABLE;
+    ret->nb_notations = 0;
+    ret->table = (xmlNotationPtr ) 
+         malloc(ret->max_notations * sizeof(xmlNotation));
+    if (ret == NULL) {
+        fprintf(stderr, "xmlCreateNotationTable : malloc(%d) failed\n",
+	        ret->max_notations * sizeof(xmlNotation));
+	free(ret);
+        return(NULL);
+    }
+    return(ret);
+}
+
+
+/**
+ * xmlAddNotationDecl:
+ * @dtd:  pointer to the DTD
+ * @name:  the entity name
+ * @PublicID:  the public identifier or NULL
+ * @SystemID:  the system identifier or NULL
+ *
+ * Register a new notation declaration
+ *
+ * Returns NULL if not, othervise the entity
+ */
+xmlNotationPtr
+xmlAddNotationDecl(xmlDtdPtr dtd, CHAR *name, CHAR *PublicID, CHAR *SystemID) {
+    xmlNotationPtr ret, cur;
+    xmlNotationTablePtr table;
+    int i;
+
+    if (dtd == NULL) {
+        fprintf(stderr, "xmlAddNotationDecl: dtd == NULL\n");
+	return(NULL);
+    }
+    if (name == NULL) {
+        fprintf(stderr, "xmlAddNotationDecl: name == NULL\n");
+	return(NULL);
+    }
+    if ((PublicID == NULL) && (SystemID == NULL)) {
+        fprintf(stderr, "xmlAddNotationDecl: no PUBLIC ID nor SYSTEM ID\n");
+    }
+
+    /*
+     * Create the Notation table if needed.
+     */
+    table = dtd->notations;
+    if (table == NULL) 
+        table = dtd->notations = xmlCreateNotationTable();
+    if (table == NULL) {
+	fprintf(stderr, "xmlAddNotationDecl: Table creation failed!\n");
+        return(NULL);
+    }
+
+    /*
+     * Validity Check:
+     * Search the DTD for previous declarations of the ATTLIST
+     */
+    for (i = 0;i < table->nb_notations;i++) {
+        cur = &table->table[i];
+	if (!xmlStrcmp(cur->name, name)) {
+	    /*
+	     * The notation is already defined in this Dtd.
+	     */
+	    fprintf(stderr,
+		    "xmlAddNotationDecl: %s already defined\n", name);
+	}
+    }
+
+    /*
+     * Grow the table, if needed.
+     */
+    if (table->nb_notations >= table->max_notations) {
+        /*
+	 * need more notations.
+	 */
+	table->max_notations *= 2;
+	table->table = (xmlNotationPtr) 
+	    realloc(table->table, table->max_notations * sizeof(xmlNotation));
+	if (table->table) {
+	    fprintf(stderr, "xmlAddNotationDecl: out of memory\n");
+	    return(NULL);
+	}
+    }
+    ret = &table->table[table->nb_notations];
+
+    /*
+     * fill the structure.
+     */
+    ret->name = xmlStrdup(name);
+    if (SystemID != NULL)
+        ret->SystemID = xmlStrdup(SystemID);
+    else
+        ret->SystemID = NULL;
+    if (PublicID != NULL)
+        ret->PublicID = xmlStrdup(PublicID);
+    else
+        ret->PublicID = NULL;
+    table->nb_notations++;
+
+    return(ret);
+}
+
+/**
+ * xmlFreeNotation:
+ * @not:  A notation
+ *
+ * Deallocate the memory used by an notation definition
+ */
+void
+xmlFreeNotation(xmlNotationPtr nota) {
+    if (nota == NULL) return;
+    if (nota->name != NULL)
+	free((CHAR *) nota->name);
+    if (nota->PublicID != NULL)
+	free((CHAR *) nota->PublicID);
+    if (nota->SystemID != NULL)
+	free((CHAR *) nota->SystemID);
+    memset(nota, -1, sizeof(xmlNotation));
+}
+
+/**
+ * xmlFreeNotationTable:
+ * @table:  An notation table
+ *
+ * Deallocate the memory used by an entities hash table.
+ */
+void
+xmlFreeNotationTable(xmlNotationTablePtr table) {
+    int i;
+
+    if (table == NULL) return;
+
+    for (i = 0;i < table->nb_notations;i++) {
+        xmlFreeNotation(&table->table[i]);
+    }
+    free(table->table);
+    free(table);
+}
+
+/**
+ * xmlCopyNotationTable:
+ * @table:  A notation table
+ *
+ * Build a copy of a notation table.
+ * 
+ * Returns the new xmlNotationTablePtr or NULL in case of error.
+ */
+xmlNotationTablePtr
+xmlCopyNotationTable(xmlNotationTablePtr table) {
+    xmlNotationTablePtr ret;
+    xmlNotationPtr cur, nota;
+    int i;
+
+    ret = (xmlNotationTablePtr) malloc(sizeof(xmlNotationTable));
+    if (ret == NULL) {
+        fprintf(stderr, "xmlCopyNotationTable: out of memory !\n");
+	return(NULL);
+    }
+    ret->table = (xmlNotationPtr) malloc(table->max_notations *
+                                         sizeof(xmlNotation));
+    if (ret->table == NULL) {
+        fprintf(stderr, "xmlCopyNotationTable: out of memory !\n");
+	free(ret);
+	return(NULL);
+    }
+    ret->max_notations = table->max_notations;
+    ret->nb_notations = table->nb_notations;
+    for (i = 0;i < ret->nb_notations;i++) {
+	cur = &ret->table[i];
+	nota = &table->table[i];
+	if (nota->name != NULL)
+	    cur->name = xmlStrdup(nota->name);
+	else
+	    cur->name = NULL;
+	if (nota->PublicID != NULL)
+	    cur->PublicID = xmlStrdup(nota->PublicID);
+	else
+	    cur->PublicID = NULL;
+	if (nota->SystemID != NULL)
+	    cur->SystemID = xmlStrdup(nota->SystemID);
+	else
+	    cur->SystemID = NULL;
+    }
+    return(ret);
+}
+
+/**
+ * xmlDumpNotationTable:
+ * @table:  A notation table
+ *
+ * This will dump the content of the notation table as an XML DTD definition
+ *
+ * NOTE: TODO an extra parameter allowing a reentant implementation will
+ *       be added.
+ */
+void
+xmlDumpNotationTable(xmlNotationTablePtr table) {
+    int i;
+    xmlNotationPtr cur;
+
+    if (table == NULL) return;
+
+    for (i = 0;i < table->nb_notations;i++) {
+        cur = &table->table[i];
+	xmlBufferWriteChar("<!NOTATION ");
+	xmlBufferWriteCHAR(cur->name);
+	if (cur->PublicID != NULL) {
+	    xmlBufferWriteChar(" PUBLIC \"");
+	    xmlBufferWriteCHAR(cur->PublicID);
+	    xmlBufferWriteChar("\"");
+	    if (cur->SystemID != NULL) {
+		xmlBufferWriteChar(" ");
+		xmlBufferWriteCHAR(cur->SystemID);
+	    }
+	} else {
+	    xmlBufferWriteChar(" SYSTEM ");
+	    xmlBufferWriteCHAR(cur->SystemID);
+	}
+        xmlBufferWriteChar(" >\n");
+    }
+}
diff --git a/valid.h b/valid.h
index 6f0023a..14a7228 100644
--- a/valid.h
+++ b/valid.h
@@ -12,6 +12,20 @@
 #include "tree.h"
 
 /*
+ * ALl notation declarations are stored in a table
+ * there is one table per DTD
+ */
+
+#define XML_MIN_NOTATION_TABLE	32
+
+typedef struct xmlNotationTable {
+    int nb_notations;		/* number of notations stored */
+    int max_notations;		/* maximum number of notations */
+    xmlNotationPtr table;	/* the table of attributes */
+} xmlNotationTable;
+typedef xmlNotationTable *xmlNotationTablePtr;
+
+/*
  * ALl element declarations are stored in a table
  * there is one table per DTD
  */
@@ -21,16 +35,54 @@
 typedef struct xmlElementTable {
     int nb_elements;		/* number of elements stored */
     int max_elements;		/* maximum number of elements */
-    xmlElementPtr table;	/* the table of entities */
-} xmlElementTable, *xmlElementTablePtr;
+    xmlElementPtr table;	/* the table of elements */
+} xmlElementTable;
+typedef xmlElementTable *xmlElementTablePtr;
 
-extern xmlElementPtr xmlAddElementDecl(xmlDtdPtr dtd, char *name, int type, 
+/*
+ * ALl attribute declarations are stored in a table
+ * there is one table per DTD
+ */
+
+#define XML_MIN_ATTRIBUTE_TABLE	32
+
+typedef struct xmlAttributeTable {
+    int nb_attributes;		/* number of attributes stored */
+    int max_attributes;		/* maximum number of attributes */
+    xmlAttributePtr table;	/* the table of attributes */
+} xmlAttributeTable;
+typedef xmlAttributeTable *xmlAttributeTablePtr;
+
+/* Notation */
+xmlNotationPtr xmlAddNotationDecl(xmlDtdPtr dtd, CHAR *name,
+	       CHAR *PublicID, CHAR *SystemID);
+xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table);
+void xmlFreeNotationTable(xmlNotationTablePtr table);
+void xmlDumpNotationTable(xmlNotationTablePtr table);
+
+/* Element Content */
+xmlElementContentPtr xmlNewElementContent(CHAR *name, int type);
+xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
+void xmlFreeElementContent(xmlElementContentPtr cur);
+
+/* Element */
+xmlElementPtr xmlAddElementDecl(xmlDtdPtr dtd, CHAR *name, int type, 
                                        xmlElementContentPtr content);
-extern xmlElementContentPtr xmlNewElementContent(CHAR *name, int type);
-extern xmlElementContentPtr xmlCopyElementContent(xmlElementContentPtr content);
-extern void xmlFreeElementContent(xmlElementContentPtr cur);
+xmlElementTablePtr xmlCopyElementTable(xmlElementTablePtr table);
+void xmlFreeElementTable(xmlElementTablePtr table);
+void xmlDumpElementTable(xmlElementTablePtr table);
 
-extern xmlElementTablePtr xmlCopyElementTable(xmlElementTablePtr table);
-extern void xmlFreeElementTable(xmlElementTablePtr table);
-extern void xmlDumpElementTable(xmlElementTablePtr table);
+/* Enumeration */
+xmlEnumerationPtr xmlCreateEnumeration(CHAR *name);
+void xmlFreeEnumeration(xmlEnumerationPtr cur);
+xmlEnumerationPtr xmlCopyEnumeration(xmlEnumerationPtr cur);
+
+/* Attribute */
+xmlAttributePtr xmlAddAttributeDecl(xmlDtdPtr dtd, CHAR *elem,
+	       CHAR *name, int type, int def,
+	       CHAR *defaultValue, xmlEnumerationPtr tree);
+xmlAttributeTablePtr xmlCopyAttributeTable(xmlAttributeTablePtr table);
+void xmlFreeAttributeTable(xmlAttributeTablePtr table);
+void xmlDumpAttributeTable(xmlAttributeTablePtr table);
+
 #endif /* __XML_VALID_H__ */