From 5099ae89ef661eea3e82dbf4b16bab9d7e9be2ff Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Wed, 21 Apr 1999 20:12:07 +0000 Subject: [PATCH] Removal of threading problems, update documentation, added SAX tests, Daniel --- ChangeLog | 9 + TODO | 11 +- doc/html/gnome-xml-entities.html | 76 +- doc/html/gnome-xml-parser.html | 1399 +++++++++++++++++++++-- doc/html/gnome-xml-parserinternals.html | 1172 +++++++++++++++---- doc/html/gnome-xml-tree.html | 845 ++++++++++++-- doc/html/gnome-xml-valid.html | 159 ++- doc/html/index.sgml | 31 + entities.c | 96 +- entities.h | 2 +- include/libxml/entities.h | 2 +- include/libxml/tree.h | 27 +- include/libxml/valid.h | 6 +- parser.c | 2 +- testSAX.c | 599 ++++++++++ tree.c | 467 +++++--- tree.h | 27 +- valid.c | 144 ++- valid.h | 6 +- 19 files changed, 4311 insertions(+), 769 deletions(-) create mode 100644 testSAX.c diff --git a/ChangeLog b/ChangeLog index de4e14b2..43ea9798 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Wed Apr 21 22:07:35 CEST 1999 + + * parser.[ch] tree.[ch] entities.[ch] valid.[ch] : removed the main + reentrancy problem at printing. One is left in entities.c, to + remove ASAP + * testSAX.c : added a test example showing the use of the SAX + interface if one doesn't want to build the DOM tree. + * html/gnome-xml-*.html html/index.sgml: regenerated the documentation + Mon Apr 5 14:14:40 CEST 1999 Daniel Veillard * parser.[ch] tree.[ch] SAX.c, parserInternals.h valid.[ch]: diff --git a/TODO b/TODO index d8218bc0..84167631 100644 --- a/TODO +++ b/TODO @@ -6,18 +6,9 @@ asbtraction of an input stream. A large part of the context is still located on the stack, moving to a state machine and putting everyting in the parsing context should provide an adequate solution. -- DOM support, instead of using a proprietary in memory - format for the document representation, the parser should - call a DOM API to actually build the resulting document. - Then the parser becomes independent of the in-memory - representation of the document. Even better using RPC's - the parser can actually build the document in another - program. -- Support for Comments (bad, should be in ASAP, they are parsed - but not stored), should be configurable. -- Improve the support of entities on save (+SAX). Done: +- Improve the support for SAX - C++ support : John Ehresman - Updated code to follow more recent specs, added compatibility flag - Better error handling, use a dedicated, overridable error diff --git a/doc/html/gnome-xml-entities.html b/doc/html/gnome-xml-entities.html index eccca5ea..c3987094 100644 --- a/doc/html/gnome-xml-entities.html +++ b/doc/html/gnome-xml-entities.html @@ -65,7 +65,7 @@ WIDTH="100%">

Name

Synopsis

xmlDumpEntitiesTable (xmlBufferPtr buf, + xmlEntitiesTablePtr table); @@ -276,7 +280,7 @@ HREF="gnome-xml-entities.html#XMLENTITYPTR" >

Description

Details




















void        xmlDumpEntitiesTable            (xmlBufferPtr buf,
+                                             xmlEntitiesTablePtr table);

This will dump the content of the entity table as an XML DTD definition

NOTE: TODO an extra parameter allowing a reentant implementation will -be added.

buf : An XML buffer.table :

CHAR *systemId); void (*internalSubsetSAXFunc) (xmlParserCtxtPtr ctxt, + const CHAR *name, + const CHAR *ExternalID, + const CHAR *SystemID); +xmlEntityPtr (*getEntitySAXFunc) (xmlParserCtxtPtr ctxt, + const CHAR *name); +void (*entityDeclSAXFunc) (xmlParserCtxtPtr ctxt, + const CHAR *name, + int type, + const CHAR *publicId, + const CHAR *systemId, + CHAR *content); +void (*notationDeclSAXFunc) (CHAR *systemId); void (*attributeDeclSAXFunc) (xmlParserCtxtPtr ctxt, + const CHAR *elem, + const CHAR *name, + int type, + int def, + const CHAR *defaultValue, + xmlEnumerationPtr tree); +void (*elementDeclSAXFunc) (xmlParserCtxtPtr ctxt, + const CHAR *name, + int type, + xmlElementContentPtr content); +void (*unparsedEntityDeclSAXFunc) (CHAR *name); +> *name, + const CHAR **atts); void (*endElementSAXFuncCHAR *value); void (*referenceSAXFunc) (xmlParserCtxtPtr ctxt, + const CHAR *name); +void (*charactersSAXFunc) (CHAR *ch, - int start, int len); void (CHAR *ch, - int start, int len); void (CHAR *data); void (*commentSAXFunc) (xmlParserCtxtPtr ctxt, + const CHAR *value); +void (*warningSAXFunc) ( ctxt, const char *msg, ...); +int (*isStandaloneSAXFunc) (xmlParserCtxtPtr ctxt); +int (*hasInternalSubsetSAXFunc) (xmlParserCtxtPtr ctxt); +int (*hasExternalSubsetSAXFunc) (xmlParserCtxtPtr ctxt); typedef xmlSAXHandlerPtr

Description

Details













internalSubsetSAXFunc()

void        (*internalSubsetSAXFunc)        (xmlParserCtxtPtr ctxt,
+                                             const CHAR *name,
+                                             const CHAR *ExternalID,
+                                             const CHAR *SystemID);

ctxt : 
name : 
ExternalID : 
SystemID : 


getEntitySAXFunc()

xmlEntityPtr (*getEntitySAXFunc)            (xmlParserCtxtPtr ctxt,
+                                             const CHAR *name);

ctxt : 
name : 
Returns : 


entityDeclSAXFunc()

void        (*entityDeclSAXFunc)            (xmlParserCtxtPtr ctxt,
+                                             const CHAR *name,
+                                             int type,
+                                             const CHAR *publicId,
+                                             const CHAR *systemId,
+                                             CHAR *content);

ctxt : 
name : 
type : 
publicId : 
systemId : 
content : 



attributeDeclSAXFunc()

void        (*attributeDeclSAXFunc)         (xmlParserCtxtPtr ctxt,
+                                             const CHAR *elem,
+                                             const CHAR *name,
+                                             int type,
+                                             int def,
+                                             const CHAR *defaultValue,
+                                             xmlEnumerationPtr tree);

ctxt : 
elem : 
name : 
type : 
def : 
defaultValue : 
tree : 


elementDeclSAXFunc()

void        (*elementDeclSAXFunc)           (xmlParserCtxtPtr ctxt,
+                                             const CHAR *name,
+                                             int type,
+                                             xmlElementContentPtr content);

ctxt : 
name : 
type : 
content : 






CHAR *name); *name, + const CHAR **atts); atts : 




referenceSAXFunc()

void        (*referenceSAXFunc)             (xmlParserCtxtPtr ctxt,
+                                             const CHAR *name);

ctxt : 
name : 


CHAR *ch, - int start, int len);start : len :

CHAR *ch, - int start, int len);start : len :


commentSAXFunc()

void        (*commentSAXFunc)               (xmlParserCtxtPtr ctxt,
+                                             const CHAR *value);

ctxt : 
value : 





isStandaloneSAXFunc()

int         (*isStandaloneSAXFunc)          (xmlParserCtxtPtr ctxt);

ctxt : 
Returns : 


hasInternalSubsetSAXFunc()

int         (*hasInternalSubsetSAXFunc)     (xmlParserCtxtPtr ctxt);

ctxt : 
Returns : 


hasExternalSubsetSAXFunc()

int         (*hasExternalSubsetSAXFunc)     (xmlParserCtxtPtr ctxt);

ctxt : 
Returns : 





























Name

Synopsis

+#define IS_CHAR (c) +#define IS_BLANK (c) +#define IS_BASECHAR (c) +#define IS_DIGIT (c) +#define IS_COMBINING (c) +#define IS_EXTENDER (c) +#define IS_IDEOGRAPHIC (c) +#define IS_LETTER (c) +#define IS_PUBIDCHAR (c) +#define SKIP_EOL (p) +#define MOVETO_ENDTAG (p) +#define MOVETO_STARTTAG (p) xmlParserCtxtPtrCHAR* xmlSplitQName (const CHAR *name, + CHAR **prefix); +CHAR* xmlNamespaceParseNCName (CHAR **publicID, int strict); -xmlNodePtr xmlParseComment (xmlParserCtxtPtr ctxt); xmlAttrPtr CHAR* xmlParseAttribute (xmlParserCtxtPtr ctxt, xmlNodePtr node); -xmlNodePtr CHAR **value); +void xmlParseStartTag ( (xmlParserCtxtPtr ctxt, - xmlNsPtr *nsPtr, - CHAR **tagPtr); +> ctxt); void xmlParseCDSectxmlParserCtxtPtr ctxt); -xmlNodePtr xmlParseElement (

Description

Details


IS_CHAR()

#define     IS_CHAR(c)

c : 


IS_BLANK()

#define     IS_BLANK(c)

c : 


IS_BASECHAR()

#define     IS_BASECHAR(c)

c : 


IS_DIGIT()

#define     IS_DIGIT(c)

c : 


IS_COMBINING()

#define     IS_COMBINING(c)

c : 


IS_EXTENDER()

#define     IS_EXTENDER(c)

c : 


IS_IDEOGRAPHIC()

#define IS_IDEOGRAPHIC(c)						\
+    ((((c) >= 0x4e00) && ((c) <= 0x9fa5)) ||				\
+     (((c) >= 0xf900) && ((c) <= 0xfa2d)) ||				\
+     (((c) >= 0x3021) && ((c) <= 0x3029)) ||				\
+      ((c) == 0x3007))

c : 


IS_LETTER()

#define     IS_LETTER(c)

c : 


IS_PUBIDCHAR()

#define IS_PUBIDCHAR(c)							\
+    (((c) == 0x20) || ((c) == 0x0D) || ((c) == 0x0A) ||			\
+     (((c) >= 'a') && ((c) <= 'z')) ||					\
+     (((c) >= 'A') && ((c) <= 'Z')) ||					\
+     (((c) >= '0') && ((c) <= '9')) ||					\
+     ((c) == '-') || ((c) == '\'') || ((c) == '(') || ((c) == ')') ||	\
+     ((c) == '+') || ((c) == ',') || ((c) == '.') || ((c) == '/') ||	\
+     ((c) == ':') || ((c) == '=') || ((c) == '?') || ((c) == ';') ||	\
+     ((c) == '!') || ((c) == '*') || ((c) == '#') || ((c) == '@') ||	\
+     ((c) == '$') || ((c) == '_') || ((c) == '%'))

c : 


SKIP_EOL()

#define SKIP_EOL(p) 							\
+    if (*(p) == 0x13) { p++ ; if (*(p) == 0x10) p++; }			\
+    if (*(p) == 0x10) { p++ ; if (*(p) == 0x13) p++; }

p : 


MOVETO_ENDTAG()

#define MOVETO_ENDTAG(p)						\
+    while (IS_CHAR(*p) && (*(p) != '>')) (p)++

p : 


MOVETO_STARTTAG()

#define MOVETO_STARTTAG(p)						\
+    while (IS_CHAR(*p) && (*(p) != '<')) (p)++

p : 





Free all the memory used by a parser context. However the parsed -document in ctxt->doc is not freed.







xmlSplitQName()

CHAR*       xmlSplitQName                   (const CHAR *name,
+                                             CHAR **prefix);

parse an XML qualified name string

[NS 5] QName ::= (Prefix ':')? LocalPart

[NS 6] Prefix ::= NCName

[NS 7] LocalPart ::= NCName

name : an XML parser context
prefix : a CHAR **
Returns :the function returns the local part, and prefix is updated +to get the Prefix if any.















xmlNodePtr  xmlParseComment                 (void        xmlParseComment                 (xmlParserCtxtPtr ctxt,
@@ -2573,9 +3437,6 @@ must not occur within comments. "

[15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'

TODO: this should call a SAX function which will handle (or not) the -creation of the comment !

should we create a node, or just skip the contentReturns :the comment node, or NULL






















xmlAttrPtr  xmlParseAttribute               (CHAR*       xmlParseAttribute               (xmlParserCtxtPtr ctxt,
                                              xmlNodePtr node);
CHAR **value);

nodevalue : the node carrying the attribute a CHAR ** used to store the value of the attributethe attribute just parsed of NULL in case of error.the attribute name, and the value in *value.


xmlNodePtr  xmlParseStartTag                (void        xmlParseStartTag                (xmlParserCtxtPtr ctxt);
an XML parser contextReturns :the XML new node or NULL.


void xmlParseEndTag (xmlParserCtxtPtr ctxt, - xmlNsPtr *nsPtr, - CHAR **tagPtr); ctxt);

With namespace

[9] ETag ::= '</' QName S? '>'

tagPtr receive the tag name just read

[NS 9] ETag ::= '</' QName S? '>'

an XML parser contextnsPtr : the current node namespace definitiontagPtr : CHAR** receive the tag value




xmlNodePtr  xmlParseElement                 (void        xmlParseElement                 (xmlParserCtxtPtr ctxt);
an XML parser contextReturns :the XML new node or NULL








Name

Synopsis

xmlDocPtr +typedef xmlBuffer +typedef xmlBufferPtr +xmlBufferPtr xmlBufferCreate (void); +void xmlBufferFree (xmlBufferPtr buf); +int xmlBufferDump (FILE *file, + xmlBufferPtr buf); +void xmlBufferAdd (xmlBufferPtr buf, + const CHAR *str, + int len); +void xmlBufferCat (xmlBufferPtr buf, + const CHAR *str); +void xmlBufferCCat (xmlBufferPtr buf, + const char *str); xmlDtdPtrxmlDocPtr doc, - CHAR *content); @@ -498,7 +562,7 @@ HREF="gnome-xml-tree.html#XMLNODEPTR" > xmlNewComment ( (const CHAR *content); @@ -817,14 +881,22 @@ HREF="gnome-xml-tree.html#XMLNODEPTR" void xmlBufferWriteCHAR (const (xmlBufferPtr buf, + const CHAR *string); void xmlBufferWriteChar (const char *string); +> (xmlBufferPtr buf, + const char *string); void xmlDocDumpMemory

Description

Details






















xmlBuffer

typedef _xmlBuffer xmlBuffer;


xmlBufferPtr

typedef xmlBuffer *xmlBufferPtr;


xmlBufferCreate()

xmlBufferPtr xmlBufferCreate                (void);

routine to create an XML buffer.

Returns :the new structure.


xmlBufferFree()

void        xmlBufferFree                   (xmlBufferPtr buf);

Frees an XML buffer.

buf : the buffer to free


xmlBufferDump()

int         xmlBufferDump                   (FILE *file,
+                                             xmlBufferPtr buf);

Dumps an XML buffer to a FILE *.

file : the file output
buf : the buffer to dump
Returns :the number of CHAR written


xmlBufferAdd()

void        xmlBufferAdd                    (xmlBufferPtr buf,
+                                             const CHAR *str,
+                                             int len);

Add a string range to an XML buffer.

buf : the buffer to dump
str : the CHAR string
len : the number of CHAR to add


xmlBufferCat()

void        xmlBufferCat                    (xmlBufferPtr buf,
+                                             const CHAR *str);

Append a zero terminated string to an XML buffer.

buf : the buffer to dump
str : the CHAR string


xmlBufferCCat()

void        xmlBufferCCat                   (xmlBufferPtr buf,
+                                             const char *str);

Append a zero terminated C string to an XML buffer.

buf : the buffer to dump
str : the C char string

























xmlDocPtr doc, - CHAR *content);

xmlNodePtr xmlNewComment ( xmlNewComment (const CHAR *content);


























a new CHAR * or NULL if no content is available.a new CHAR * or NULL if no content is available. +It's up to the caller to free the memory.


void        xmlBufferWriteCHAR              (const void        xmlBufferWriteCHAR              (xmlBufferPtr buf,
+                                             const CHAR *string);

routine which manage and grows an output buffer. This one add -CHARs at the end of the array.

buf : the XML bufferstring :

void        xmlBufferWriteChar              (const char *string);
void xmlBufferWriteChar (
xmlBufferPtr buf, + const char *string);buf : the XML bufferstring :







Name

Synopsis

xmlDtdPtr dtd, - CHAR *name, - CHAR *PublicID, - CHAR *SystemID); @@ -155,6 +155,10 @@ void xmlDumpNotationTable (xmlBufferPtr buf, + xmlNotationTablePtr table); @@ -196,7 +200,7 @@ HREF="gnome-xml-valid.html#XMLADDELEMENTDECL" HREF="gnome-xml-tree.html#XMLDTDPTR" >xmlDtdPtr dtd, - CHAR *name, @@ -226,6 +230,10 @@ void xmlDumpElementTable (xmlBufferPtr buf, + xmlElementTablePtr table); @@ -266,17 +274,17 @@ HREF="gnome-xml-valid.html#XMLADDATTRIBUTEDECL" HREF="gnome-xml-tree.html#XMLDTDPTR" >xmlDtdPtr dtd, - CHAR *elem, - CHAR *name, int type, int def, - CHAR *defaultValue, @@ -305,6 +313,10 @@ void xmlDumpAttributeTable (xmlBufferPtr buf, + xmlAttributeTablePtr table);

Description

Details








xmlDtdPtr dtd, - CHAR *name, - CHAR *PublicID, - CHAR *SystemID);



void        xmlDumpNotationTable            (xmlBufferPtr buf,
+                                             xmlNotationTablePtr table);
buf : table :




xmlDtdPtr dtd, - CHAR *name, @@ -1226,7 +1259,7 @@ VALIGN="TOP" >



void        xmlDumpElementTable             (xmlBufferPtr buf,
+                                             xmlElementTablePtr table);
buf : table :




xmlDtdPtr dtd, - CHAR *elem, - CHAR *name, int type, int def, - CHAR *defaultValue, @@ -1864,7 +1918,7 @@ VALIGN="TOP" >



void        xmlDumpAttributeTable           (xmlBufferPtr buf,
+                                             xmlAttributeTablePtr table);
buf : table : + + + + + @@ -18,12 +23,17 @@ + + + + + @@ -73,6 +83,14 @@ + + + + + + + + @@ -183,6 +201,18 @@ + + + + + + + + + + + + @@ -192,6 +222,7 @@ + diff --git a/entities.c b/entities.c index e16dc555..88f2661f 100644 --- a/entities.c +++ b/entities.c @@ -523,15 +523,13 @@ xmlCopyEntitiesTable(xmlEntitiesTablePtr table) { /** * xmlDumpEntitiesTable: + * @buf: An XML buffer. * @table: An entity table * * This will dump the content of the entity table as an XML DTD definition - * - * NOTE: TODO an extra parameter allowing a reentant implementation will - * be added. */ void -xmlDumpEntitiesTable(xmlEntitiesTablePtr table) { +xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table) { int i; xmlEntityPtr cur; @@ -541,70 +539,70 @@ xmlDumpEntitiesTable(xmlEntitiesTablePtr table) { cur = &table->table[i]; switch (cur->type) { case XML_INTERNAL_GENERAL_ENTITY: - xmlBufferWriteChar("name); - xmlBufferWriteChar(" \""); - xmlBufferWriteCHAR(cur->content); - xmlBufferWriteChar("\">\n"); + xmlBufferWriteChar(buf, "name); + xmlBufferWriteChar(buf, " \""); + xmlBufferWriteCHAR(buf, cur->content); + xmlBufferWriteChar(buf, "\">\n"); break; case XML_EXTERNAL_GENERAL_PARSED_ENTITY: - xmlBufferWriteChar("name); + xmlBufferWriteChar(buf, "name); if (cur->ExternalID != NULL) { - xmlBufferWriteChar(" PUBLIC \""); - xmlBufferWriteCHAR(cur->ExternalID); - xmlBufferWriteChar("\" \""); - xmlBufferWriteCHAR(cur->SystemID); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " PUBLIC \""); + xmlBufferWriteCHAR(buf, cur->ExternalID); + xmlBufferWriteChar(buf, "\" \""); + xmlBufferWriteCHAR(buf, cur->SystemID); + xmlBufferWriteChar(buf, "\""); } else { - xmlBufferWriteChar(" SYSTEM \""); - xmlBufferWriteCHAR(cur->SystemID); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " SYSTEM \""); + xmlBufferWriteCHAR(buf, cur->SystemID); + xmlBufferWriteChar(buf, "\""); } - xmlBufferWriteChar(">\n"); + xmlBufferWriteChar(buf, ">\n"); break; case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: - xmlBufferWriteChar("name); + xmlBufferWriteChar(buf, "name); if (cur->ExternalID != NULL) { - xmlBufferWriteChar(" PUBLIC \""); - xmlBufferWriteCHAR(cur->ExternalID); - xmlBufferWriteChar("\" \""); - xmlBufferWriteCHAR(cur->SystemID); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " PUBLIC \""); + xmlBufferWriteCHAR(buf, cur->ExternalID); + xmlBufferWriteChar(buf, "\" \""); + xmlBufferWriteCHAR(buf, cur->SystemID); + xmlBufferWriteChar(buf, "\""); } else { - xmlBufferWriteChar(" SYSTEM \""); - xmlBufferWriteCHAR(cur->SystemID); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " SYSTEM \""); + xmlBufferWriteCHAR(buf, cur->SystemID); + xmlBufferWriteChar(buf, "\""); } if (cur->content != NULL) { /* Should be true ! */ - xmlBufferWriteChar(" NDATA "); - xmlBufferWriteCHAR(cur->content); + xmlBufferWriteChar(buf, " NDATA "); + xmlBufferWriteCHAR(buf, cur->content); } - xmlBufferWriteChar(">\n"); + xmlBufferWriteChar(buf, ">\n"); break; case XML_INTERNAL_PARAMETER_ENTITY: - xmlBufferWriteChar("name); - xmlBufferWriteChar(" \""); - xmlBufferWriteCHAR(cur->content); - xmlBufferWriteChar("\">\n"); + xmlBufferWriteChar(buf, "name); + xmlBufferWriteChar(buf, " \""); + xmlBufferWriteCHAR(buf, cur->content); + xmlBufferWriteChar(buf, "\">\n"); break; case XML_EXTERNAL_PARAMETER_ENTITY: - xmlBufferWriteChar("name); + xmlBufferWriteChar(buf, "name); if (cur->ExternalID != NULL) { - xmlBufferWriteChar(" PUBLIC \""); - xmlBufferWriteCHAR(cur->ExternalID); - xmlBufferWriteChar("\" \""); - xmlBufferWriteCHAR(cur->SystemID); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " PUBLIC \""); + xmlBufferWriteCHAR(buf, cur->ExternalID); + xmlBufferWriteChar(buf, "\" \""); + xmlBufferWriteCHAR(buf, cur->SystemID); + xmlBufferWriteChar(buf, "\""); } else { - xmlBufferWriteChar(" SYSTEM \""); - xmlBufferWriteCHAR(cur->SystemID); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " SYSTEM \""); + xmlBufferWriteCHAR(buf, cur->SystemID); + xmlBufferWriteChar(buf, "\""); } - xmlBufferWriteChar(">\n"); + xmlBufferWriteChar(buf, ">\n"); break; default: fprintf(stderr, diff --git a/entities.h b/entities.h index 89770547..5d6506d9 100644 --- a/entities.h +++ b/entities.h @@ -69,7 +69,7 @@ CHAR *xmlEncodeEntities(xmlDocPtr doc, const CHAR *input); xmlEntitiesTablePtr xmlCreateEntitiesTable(void); xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table); void xmlFreeEntitiesTable(xmlEntitiesTablePtr table); -void xmlDumpEntitiesTable(xmlEntitiesTablePtr table); +void xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table); xmlParserInputPtr xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity); xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table); diff --git a/include/libxml/entities.h b/include/libxml/entities.h index 89770547..5d6506d9 100644 --- a/include/libxml/entities.h +++ b/include/libxml/entities.h @@ -69,7 +69,7 @@ CHAR *xmlEncodeEntities(xmlDocPtr doc, const CHAR *input); xmlEntitiesTablePtr xmlCreateEntitiesTable(void); xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table); void xmlFreeEntitiesTable(xmlEntitiesTablePtr table); -void xmlDumpEntitiesTable(xmlEntitiesTablePtr table); +void xmlDumpEntitiesTable(xmlBufferPtr buf, xmlEntitiesTablePtr table); xmlParserInputPtr xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity); xmlEntitiesTablePtr xmlCopyEntitiesTable(xmlEntitiesTablePtr table); diff --git a/include/libxml/tree.h b/include/libxml/tree.h index 3f00aa09..ff6b55f7 100644 --- a/include/libxml/tree.h +++ b/include/libxml/tree.h @@ -240,6 +240,18 @@ typedef struct xmlDoc { typedef _xmlDoc xmlDoc; typedef xmlDoc *xmlDocPtr; +/* + * A buffer structure + */ + +typedef struct xmlBuffer { + CHAR *content; /* The buffer content UTF8 */ + unsigned int use; /* The buffer size used */ + unsigned int size; /* The buffer size */ +} _xmlBuffer; +typedef _xmlBuffer xmlBuffer; +typedef xmlBuffer *xmlBufferPtr; + /* * Variables. */ @@ -247,6 +259,17 @@ extern xmlNsPtr baseDTD; extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */ extern int xmlIndentTreeOutput; /* try to indent the tree dumps */ +/* + * Handling Buffers. + */ + +xmlBufferPtr xmlBufferCreate(void); +void xmlBufferFree(xmlBufferPtr buf); +int xmlBufferDump(FILE *file, xmlBufferPtr buf); +void xmlBufferAdd(xmlBufferPtr buf, const CHAR *str, int len); +void xmlBufferCat(xmlBufferPtr buf, const CHAR *str); +void xmlBufferCCat(xmlBufferPtr buf, const char *str); + /* * Creating/freeing new structures */ @@ -337,8 +360,8 @@ CHAR *xmlNodeGetContent(xmlNodePtr cur); /* * Internal, don't use */ -void xmlBufferWriteCHAR(const CHAR *string); -void xmlBufferWriteChar(const char *string); +void xmlBufferWriteCHAR(xmlBufferPtr buf, const CHAR *string); +void xmlBufferWriteChar(xmlBufferPtr buf, const char *string); /* * Saving diff --git a/include/libxml/valid.h b/include/libxml/valid.h index 22c824ab..084d97fa 100644 --- a/include/libxml/valid.h +++ b/include/libxml/valid.h @@ -58,7 +58,7 @@ xmlNotationPtr xmlAddNotationDecl(xmlDtdPtr dtd, const CHAR *name, const CHAR *PublicID, const CHAR *SystemID); xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table); void xmlFreeNotationTable(xmlNotationTablePtr table); -void xmlDumpNotationTable(xmlNotationTablePtr table); +void xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table); /* Element Content */ xmlElementContentPtr xmlNewElementContent(CHAR *name, int type); @@ -70,7 +70,7 @@ xmlElementPtr xmlAddElementDecl(xmlDtdPtr dtd, const CHAR *name, int type, xmlElementContentPtr content); xmlElementTablePtr xmlCopyElementTable(xmlElementTablePtr table); void xmlFreeElementTable(xmlElementTablePtr table); -void xmlDumpElementTable(xmlElementTablePtr table); +void xmlDumpElementTable(xmlBufferPtr buf, xmlElementTablePtr table); /* Enumeration */ xmlEnumerationPtr xmlCreateEnumeration(CHAR *name); @@ -83,6 +83,6 @@ xmlAttributePtr xmlAddAttributeDecl(xmlDtdPtr dtd, const CHAR *elem, const CHAR *defaultValue, xmlEnumerationPtr tree); xmlAttributeTablePtr xmlCopyAttributeTable(xmlAttributeTablePtr table); void xmlFreeAttributeTable(xmlAttributeTablePtr table); -void xmlDumpAttributeTable(xmlAttributeTablePtr table); +void xmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table); #endif /* __XML_VALID_H__ */ diff --git a/parser.c b/parser.c index f1ea2fb9..0e4eafc8 100644 --- a/parser.c +++ b/parser.c @@ -4337,7 +4337,7 @@ xmlFreeParserCtxt(xmlParserCtxtPtr ctxt) if (ctxt->nodeTab != NULL) free(ctxt->nodeTab); if (ctxt->inputTab != NULL) free(ctxt->inputTab); - if (ctxt->version != NULL) free(ctxt->version); + if (ctxt->version != NULL) free((char *) ctxt->version); free(ctxt); } diff --git a/testSAX.c b/testSAX.c new file mode 100644 index 00000000..2ce82cb6 --- /dev/null +++ b/testSAX.c @@ -0,0 +1,599 @@ +/* + * tester.c : a small tester program for parsing using the SAX API. + * + * See Copyright for the status of this software. + * + * Daniel.Veillard@w3.org + */ + +#ifdef WIN32 +#define HAVE_FCNTL_H +#include +#else +#include +#endif +#include +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#include +#include +#include +#include + +#include "parser.h" +#include "tree.h" +#include "debugXML.h" + +static int debug = 0; +static int copy = 0; +static int recovery = 0; + +xmlSAXHandler emptySAXHandlerStruct = { + NULL, /* internalSubset */ + NULL, /* isStandalone */ + NULL, /* hasInternalSubset */ + NULL, /* hasExternalSubset */ + NULL, /* resolveEntity */ + NULL, /* getEntity */ + NULL, /* entityDecl */ + NULL, /* notationDecl */ + NULL, /* attributeDecl */ + NULL, /* elementDecl */ + NULL, /* unparsedEntityDecl */ + NULL, /* setDocumentLocator */ + NULL, /* startDocument */ + NULL, /* endDocument */ + NULL, /* startElement */ + NULL, /* endElement */ + NULL, /* reference */ + NULL, /* characters */ + NULL, /* ignorableWhitespace */ + NULL, /* processingInstruction */ + NULL, /* comment */ + NULL, /* xmlParserWarning */ + NULL, /* xmlParserError */ + NULL, /* xmlParserError */ +}; + +xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct; + +/* + * Note: there is a couple of errors introduced on purpose. + */ +static CHAR buffer[] = +"\n\ +\n\ +\n\ +\n\ +\n\ + \n\ + \n\ + Jim Whitehead\n\ + Roy Fielding\n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ +\n\ +\n\ +"; + +/************************************************************************ + * * + * Debug Handlers * + * * + ************************************************************************/ + +/** + * isStandaloneDebug: + * @ctxt: An XML parser context + * + * Is this document tagged standalone ? + * + * Returns 1 if true + */ +int +isStandaloneDebug(xmlParserCtxtPtr ctxt) +{ + fprintf(stderr, "SAX.isStandalone()\n"); + return(0); +} + +/** + * hasInternalSubsetDebug: + * @ctxt: An XML parser context + * + * Does this document has an internal subset + * + * Returns 1 if true + */ +int +hasInternalSubsetDebug(xmlParserCtxtPtr ctxt) +{ + fprintf(stderr, "SAX.hasInternalSubset()\n"); + return(0); +} + +/** + * hasExternalSubsetDebug: + * @ctxt: An XML parser context + * + * Does this document has an external subset + * + * Returns 1 if true + */ +int +hasExternalSubsetDebug(xmlParserCtxtPtr ctxt) +{ + fprintf(stderr, "SAX.hasExternalSubset()\n"); + return(0); +} + +/** + * hasInternalSubsetDebug: + * @ctxt: An XML parser context + * + * Does this document has an internal subset + */ +void +internalSubsetDebug(xmlParserCtxtPtr ctxt, const CHAR *name, + const CHAR *ExternalID, const CHAR *SystemID) +{ + fprintf(stderr, "SAX.internalSubset(%s, %s, %s)\n", + name, ExternalID, SystemID); +} + +/** + * resolveEntityDebug: + * @ctxt: An XML parser context + * @publicId: The public ID of the entity + * @systemId: The system ID of the entity + * + * Special entity resolver, better left to the parser, it has + * more context than the application layer. + * The default behaviour is to NOT resolve the entities, in that case + * the ENTITY_REF nodes are built in the structure (and the parameter + * values). + * + * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. + */ +xmlParserInputPtr +resolveEntityDebug(xmlParserCtxtPtr ctxt, const CHAR *publicId, const CHAR *systemId) +{ + fprintf(stderr, "SAX.resolveEntity(%s, %s)\n", + (char *)publicId, (char *)systemId); + return(NULL); +} + +/** + * getEntityDebug: + * @ctxt: An XML parser context + * @name: The entity name + * + * Get an entity by name + * + * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. + */ +xmlEntityPtr +getEntityDebug(xmlParserCtxtPtr ctxt, const CHAR *name) +{ + fprintf(stderr, "SAX.getEntity(%s)\n", name); + return(NULL); +} + + +/** + * entityDeclDebug: + * @ctxt: An XML parser context + * @name: the entity name + * @type: the entity type + * @publicId: The public ID of the entity + * @systemId: The system ID of the entity + * @content: the entity value (without processing). + * + * An entity definition has been parsed + */ +void +entityDeclDebug(xmlParserCtxtPtr ctxt, const CHAR *name, int type, + const CHAR *publicId, const CHAR *systemId, CHAR *content) +{ + fprintf(stderr, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", + name, type, publicId, systemId, content); +} + +/** + * attributeDeclDebug: + * @ctxt: An XML parser context + * @name: the attribute name + * @type: the attribute type + * + * An attribute definition has been parsed + */ +void +attributeDeclDebug(xmlParserCtxtPtr ctxt, const CHAR *elem, const CHAR *name, + int type, int def, const CHAR *defaultValue, + xmlEnumerationPtr tree) +{ + fprintf(stderr, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", + elem, name, type, def, defaultValue); +} + +/** + * elementDeclDebug: + * @ctxt: An XML parser context + * @name: the element name + * @type: the element type + * @content: the element value (without processing). + * + * An element definition has been parsed + */ +void +elementDeclDebug(xmlParserCtxtPtr ctxt, const CHAR *name, int type, + xmlElementContentPtr content) +{ + fprintf(stderr, "SAX.elementDecl(%s, %d, ...)\n", + name, type); +} + +/** + * notationDeclDebug: + * @ctxt: An XML parser context + * @name: The name of the notation + * @publicId: The public ID of the entity + * @systemId: The system ID of the entity + * + * What to do when a notation declaration has been parsed. + * TODO Not handled currently. + */ +void +notationDeclDebug(xmlParserCtxtPtr ctxt, const CHAR *name, + const CHAR *publicId, const CHAR *systemId) +{ + fprintf(stderr, "SAX.notationDecl(%s, %s, %s)\n", + (char *) name, (char *) publicId, (char *) systemId); +} + +/** + * unparsedEntityDeclDebug: + * @ctxt: An XML parser context + * @name: The name of the entity + * @publicId: The public ID of the entity + * @systemId: The system ID of the entity + * @notationName: the name of the notation + * + * What to do when an unparsed entity declaration is parsed + * TODO Create an Entity node. + */ +void +unparsedEntityDeclDebug(xmlParserCtxtPtr ctxt, const CHAR *name, + const CHAR *publicId, const CHAR *systemId, + const CHAR *notationName) +{ + fprintf(stderr, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n", + (char *) name, (char *) publicId, (char *) systemId, + (char *) notationName); +} + +/** + * setDocumentLocatorDebug: + * @ctxt: An XML parser context + * @loc: A SAX Locator + * + * Receive the document locator at startup, actually xmlDefaultSAXLocator + * Everything is available on the context, so this is useless in our case. + */ +void +setDocumentLocatorDebug(xmlParserCtxtPtr ctxt, xmlSAXLocatorPtr loc) +{ + fprintf(stderr, "SAX.setDocumentLocator()\n"); +} + +/** + * startDocumentDebug: + * @ctxt: An XML parser context + * + * called when the document start being processed. + */ +void +startDocumentDebug(xmlParserCtxtPtr ctxt) +{ + fprintf(stderr, "SAX.startDocument()\n"); +} + +/** + * endDocumentDebug: + * @ctxt: An XML parser context + * + * called when the document end has been detected. + */ +void +endDocumentDebug(xmlParserCtxtPtr ctxt) +{ + fprintf(stderr, "SAX.endDocument()\n"); +} + +/** + * startElementDebug: + * @ctxt: An XML parser context + * @name: The element name + * + * called when an opening tag has been processed. + * TODO We currently have a small pblm with the arguments ... + */ +void +startElementDebug(xmlParserCtxtPtr ctxt, const CHAR *name, const CHAR **atts) +{ + int i; + + fprintf(stderr, "SAX.startElement(%s", (char *) name); + if (atts != NULL) { + for (i = 0;(atts[i] != NULL);i++) { + fprintf(stderr, ", %s='", atts[i++]); + fprintf(stderr, "%s'", atts[i]); + } + } + fprintf(stderr, ")\n"); +} + +/** + * endElementDebug: + * @ctxt: An XML parser context + * @name: The element name + * + * called when the end of an element has been detected. + */ +void +endElementDebug(xmlParserCtxtPtr ctxt, const CHAR *name) +{ + fprintf(stderr, "SAX.endElement(%s)\n", (char *) name); +} + +/** + * charactersDebug: + * @ctxt: An XML parser context + * @ch: a CHAR string + * @len: the number of CHAR + * + * receiving some chars from the parser. + * Question: how much at a time ??? + */ +void +charactersDebug(xmlParserCtxtPtr ctxt, const CHAR *ch, int len) +{ + fprintf(stderr, "SAX.characters(%.30s, %d)\n", (char *) ch, len); +} + +/** + * referenceDebug: + * @ctxt: An XML parser context + * @name: The entity name + * + * called when an entity reference is detected. + */ +void +referenceDebug(xmlParserCtxtPtr ctxt, const CHAR *name) +{ + fprintf(stderr, "SAX.reference(%s)\n", name); +} + +/** + * ignorableWhitespaceDebug: + * @ctxt: An XML parser context + * @ch: a CHAR string + * @start: the first char in the string + * @len: the number of CHAR + * + * receiving some ignorable whitespaces from the parser. + * Question: how much at a time ??? + */ +void +ignorableWhitespaceDebug(xmlParserCtxtPtr ctxt, const CHAR *ch, int len) +{ + fprintf(stderr, "SAX.ignorableWhitespace(%.30s, %d)\n", + (char *) ch, len); +} + +/** + * processingInstructionDebug: + * @ctxt: An XML parser context + * @target: the target name + * @data: the PI data's + * @len: the number of CHAR + * + * A processing instruction has been parsed. + */ +void +processingInstructionDebug(xmlParserCtxtPtr ctxt, const CHAR *target, + const CHAR *data) +{ + fprintf(stderr, "SAX.processingInstruction(%s, %s)\n", + (char *) target, (char *) data); +} + +/** + * commentDebug: + * @ctxt: An XML parser context + * @value: the comment content + * + * A comment has been parsed. + */ +void +commentDebug(xmlParserCtxtPtr ctxt, const CHAR *value) +{ + fprintf(stderr, "SAX.comment(%s)\n", value); +} + +/** + * warningDebug: + * @ctxt: An XML parser context + * @msg: the message to display/transmit + * @...: extra parameters for the message display + * + * Display and format a warning messages, gives file, line, position and + * extra parameters. + */ +void +warningDebug(xmlParserCtxtPtr ctxt, const char *msg, ...) +{ + va_list args; + + va_start(args, msg); + fprintf(stderr, "SAX.warning: "); + vfprintf(stderr, msg, args); + va_end(args); +} + +/** + * errorDebug: + * @ctxt: An XML parser context + * @msg: the message to display/transmit + * @...: extra parameters for the message display + * + * Display and format a error messages, gives file, line, position and + * extra parameters. + */ +void +errorDebug(xmlParserCtxtPtr ctxt, const char *msg, ...) +{ + va_list args; + + va_start(args, msg); + fprintf(stderr, "SAX.error: "); + vfprintf(stderr, msg, args); + va_end(args); +} + +/** + * fatalErrorDebug: + * @ctxt: An XML parser context + * @msg: the message to display/transmit + * @...: extra parameters for the message display + * + * Display and format a fatalError messages, gives file, line, position and + * extra parameters. + */ +void +fatalErrorDebug(xmlParserCtxtPtr ctxt, const char *msg, ...) +{ + va_list args; + + va_start(args, msg); + fprintf(stderr, "SAX.fatalError: "); + vfprintf(stderr, msg, args); + va_end(args); +} + +xmlSAXHandler debugSAXHandlerStruct = { + internalSubsetDebug, + isStandaloneDebug, + hasInternalSubsetDebug, + hasExternalSubsetDebug, + resolveEntityDebug, + getEntityDebug, + entityDeclDebug, + notationDeclDebug, + attributeDeclDebug, + elementDeclDebug, + unparsedEntityDeclDebug, + setDocumentLocatorDebug, + startDocumentDebug, + endDocumentDebug, + startElementDebug, + endElementDebug, + referenceDebug, + charactersDebug, + ignorableWhitespaceDebug, + processingInstructionDebug, + commentDebug, + warningDebug, + errorDebug, + fatalErrorDebug, +}; + +xmlSAXHandlerPtr debugSAXHandler = &debugSAXHandlerStruct; + +/************************************************************************ + * * + * Debug * + * * + ************************************************************************/ + +void parseAndPrintFile(char *filename) { + xmlDocPtr doc; + + /* + * Empty callbacks for checking + */ + doc = xmlSAXParseFile(emptySAXHandler, filename, 0); + if (doc != NULL) { + fprintf(stderr, "xmlSAXParseFile returned non-NULL\n"); + xmlDocDump(stdout, doc); + } + + /* + * Debug callback + */ + doc = xmlSAXParseFile(debugSAXHandler, filename, 0); + if (doc != NULL) { + fprintf(stderr, "xmlSAXParseFile returned non-NULL\n"); + xmlDocDump(stdout, doc); + } +} + +void parseAndPrintBuffer(CHAR *buf) { + xmlDocPtr doc; + + /* + * Empty callbacks for checking + */ + doc = xmlSAXParseDoc(emptySAXHandler, buf, 0); + if (doc != NULL) { + fprintf(stderr, "xmlSAXParseDoc returned non-NULL\n"); + xmlDocDump(stdout, doc); + } + + /* + * Debug callback + */ + doc = xmlSAXParseDoc(debugSAXHandler, buf, 0); + if (doc != NULL) { + fprintf(stderr, "xmlSAXParseDoc returned non-NULL\n"); + xmlDocDump(stdout, doc); + } +} + +int main(int argc, char **argv) { + int i; + int files = 0; + + for (i = 1; i < argc ; i++) { + if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) + debug++; + else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) + copy++; + else if ((!strcmp(argv[i], "-recover")) || + (!strcmp(argv[i], "--recover"))) + recovery++; + } + for (i = 1; i < argc ; i++) { + if (argv[i][0] != '-') { + parseAndPrintFile(argv[i]); + files ++; + } + } + if (files == 0) { + printf("\nFirst test for the parser, with errors\n"); + parseAndPrintBuffer(buffer); + } + + return(0); +} diff --git a/tree.c b/tree.c index 13c30875..a89e56d6 100644 --- a/tree.c +++ b/tree.c @@ -1707,6 +1707,7 @@ xmlCopyDoc(xmlDocPtr doc, int recursive) { * of the values carried by this node child's (TEXT and ENTITY_REF). * Entity references are substitued. * Returns a new CHAR * or NULL if no content is available. + * It's up to the caller to free the memory. */ CHAR * xmlNodeGetContent(xmlNodePtr cur) { @@ -2106,80 +2107,203 @@ xmlTextConcat(xmlNodePtr node, const CHAR *content, int len) { * * ************************************************************************/ -static CHAR *buffer = NULL; -static int buffer_index = 0; -static int buffer_size = 0; +#define BASE_BUFFER_SIZE 4000 + +/** + * xmlBufferCreate: + * + * routine to create an XML buffer. + * returns the new structure. + */ +xmlBufferPtr +xmlBufferCreate(void) { + xmlBufferPtr ret; + + ret = (xmlBufferPtr) malloc(sizeof(xmlBuffer)); + if (ret == NULL) { + fprintf(stderr, "xmlBufferCreate : out of memory!\n"); + return(NULL); + } + ret->use = 0; + ret->size = BASE_BUFFER_SIZE; + ret->content = (CHAR *) malloc(ret->size * sizeof(CHAR)); + if (ret->content == NULL) { + fprintf(stderr, "xmlBufferCreate : out of memory!\n"); + free(ret); + return(NULL); + } + ret->content[0] = 0; + return(ret); +} + +/** + * xmlBufferFree: + * @buf: the buffer to free + * + * Frees an XML buffer. + */ +void +xmlBufferFree(xmlBufferPtr buf) { + if (buf == NULL) { + fprintf(stderr, "xmlBufferFree: buf == NULL\n"); + return; + } + if (buf->content == NULL) { + fprintf(stderr, "xmlBufferFree: buf->content == NULL\n"); + } else { + memset(buf->content, -1, BASE_BUFFER_SIZE); + free(buf->content); + } + memset(buf, -1, sizeof(xmlBuffer)); + free(buf); +} + +/** + * xmlBufferDump: + * @file: the file output + * @buf: the buffer to dump + * + * Dumps an XML buffer to a FILE *. + * Returns the number of CHAR written + */ +int +xmlBufferDump(FILE *file, xmlBufferPtr buf) { + int ret; + + if (buf == NULL) { + fprintf(stderr, "xmlBufferDump: buf == NULL\n"); + return(0); + } + if (buf->content == NULL) { + fprintf(stderr, "xmlBufferDump: buf->content == NULL\n"); + return(0); + } + if (file == NULL) file = stdout; + ret = fwrite(buf->content, sizeof(CHAR), buf->use, file); + return(ret); +} + +/** + * xmlBufferAdd: + * @buf: the buffer to dump + * @str: the CHAR string + * @len: the number of CHAR to add + * + * Add a string range to an XML buffer. + */ +void +xmlBufferAdd(xmlBufferPtr buf, const CHAR *str, int len) { + const CHAR *cur; + + if (str == NULL) { + fprintf(stderr, "xmlBufferAdd: str == NULL\n"); + return; + } + for (cur = str;(len > 0) && (*cur != 0);cur++, len--) { + if (buf->use + 10 >= buf->size) { + CHAR *rebuf; + + buf->size *= 2; + rebuf = (CHAR *) realloc(buf->content, buf->size * sizeof(CHAR)); + if (rebuf == NULL) { + fprintf(stderr, "xmlBufferAdd : out of memory!\n"); + return; + } + buf->content = rebuf; + } + buf->content[buf->use++] = *cur; + } +} + +/** + * xmlBufferCat: + * @buf: the buffer to dump + * @str: the CHAR string + * + * Append a zero terminated string to an XML buffer. + */ +void +xmlBufferCat(xmlBufferPtr buf, const CHAR *str) { + const CHAR *cur; + + if (str == NULL) { + fprintf(stderr, "xmlBufferAdd: str == NULL\n"); + return; + } + for (cur = str;*cur != 0;cur++) { + if (buf->use + 10 >= buf->size) { + CHAR *rebuf; + + buf->size *= 2; + rebuf = (CHAR *) realloc(buf->content, buf->size * sizeof(CHAR)); + if (rebuf == NULL) { + fprintf(stderr, "xmlBufferAdd : out of memory!\n"); + return; + } + buf->content = rebuf; + } + buf->content[buf->use++] = *cur; + } +} + +/** + * xmlBufferCCat: + * @buf: the buffer to dump + * @str: the C char string + * + * Append a zero terminated C string to an XML buffer. + */ +void +xmlBufferCCat(xmlBufferPtr buf, const char *str) { + const char *cur; + + if (str == NULL) { + fprintf(stderr, "xmlBufferAdd: str == NULL\n"); + return; + } + for (cur = str;*cur != 0;cur++) { + if (buf->use + 10 >= buf->size) { + CHAR *rebuf; + + buf->size *= 2; + rebuf = (CHAR *) realloc(buf->content, buf->size * sizeof(CHAR)); + if (rebuf == NULL) { + fprintf(stderr, "xmlBufferAdd : out of memory!\n"); + return; + } + buf->content = rebuf; + } + buf->content[buf->use++] = *cur; + } +} /** * xmlBufferWriteCHAR: + * @buf: the XML buffer * @string: the string to add * * routine which manage and grows an output buffer. This one add - * CHARs at the end of the array. + * CHARs at the end of the buffer. */ void -xmlBufferWriteCHAR(const CHAR *string) { - const CHAR *cur; - - if (buffer == NULL) { - buffer_size = 50000; - buffer = (CHAR *) malloc(buffer_size * sizeof(CHAR)); - if (buffer == NULL) { - fprintf(stderr, "xmlBufferWrite : out of memory!\n"); - exit(1); - } - } - - if (string == NULL) return; - for (cur = string;*cur != 0;cur++) { - if (buffer_index + 10 >= buffer_size) { - buffer_size *= 2; - buffer = (CHAR *) realloc(buffer, buffer_size * sizeof(CHAR)); - if (buffer == NULL) { - fprintf(stderr, "xmlBufferWrite : out of memory!\n"); - exit(1); - } - } - buffer[buffer_index++] = *cur; - } - buffer[buffer_index] = 0; +xmlBufferWriteCHAR(xmlBufferPtr buf, const CHAR *string) { + xmlBufferCat(buf, string); } /** * xmlBufferWriteChar: + * @buf: the XML buffer * @string: the string to add * * routine which manage and grows an output buffer. This one add * C chars at the end of the array. */ void -xmlBufferWriteChar(const char *string) { - const char *cur; - - if (buffer == NULL) { - buffer_size = 50000; - buffer = (CHAR *) malloc(buffer_size * sizeof(CHAR)); - if (buffer == NULL) { - fprintf(stderr, "xmlBufferWrite : out of memory!\n"); - exit(1); - } - } - - if (string == NULL) return; - for (cur = string;*cur != 0;cur++) { - if (buffer_index + 10 >= buffer_size) { - buffer_size *= 2; - buffer = (CHAR *) realloc(buffer, buffer_size * sizeof(CHAR)); - if (buffer == NULL) { - fprintf(stderr, "xmlBufferWrite : out of memory!\n"); - exit(1); - } - } - buffer[buffer_index++] = *cur; - } - buffer[buffer_index] = 0; +xmlBufferWriteChar(xmlBufferPtr buf, const char *string) { + xmlBufferCCat(buf, string); } + /** * xmlGlobalNsDump: * @cur: a namespace @@ -2187,24 +2311,24 @@ xmlBufferWriteChar(const char *string) { * Dump a global Namespace, this is the old version based on PIs. */ static void -xmlGlobalNsDump(xmlNsPtr cur) { +xmlGlobalNsDump(xmlBufferPtr buf, xmlNsPtr cur) { if (cur == NULL) { fprintf(stderr, "xmlGlobalNsDump : Ns == NULL\n"); return; } if (cur->type == XML_GLOBAL_NAMESPACE) { - xmlBufferWriteChar("href != NULL) { - xmlBufferWriteChar(" href=\""); - xmlBufferWriteCHAR(cur->href); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " href=\""); + xmlBufferWriteCHAR(buf, cur->href); + xmlBufferWriteChar(buf, "\""); } if (cur->prefix != NULL) { - xmlBufferWriteChar(" AS=\""); - xmlBufferWriteCHAR(cur->prefix); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " AS=\""); + xmlBufferWriteCHAR(buf, cur->prefix); + xmlBufferWriteChar(buf, "\""); } - xmlBufferWriteChar("?>\n"); + xmlBufferWriteChar(buf, "?>\n"); } } @@ -2215,9 +2339,9 @@ xmlGlobalNsDump(xmlNsPtr cur) { * Dump a list of global Namespace, this is the old version based on PIs. */ static void -xmlGlobalNsListDump(xmlNsPtr cur) { +xmlGlobalNsListDump(xmlBufferPtr buf, xmlNsPtr cur) { while (cur != NULL) { - xmlGlobalNsDump(cur); + xmlGlobalNsDump(buf, cur); cur = cur->next; } } @@ -2230,7 +2354,7 @@ xmlGlobalNsListDump(xmlNsPtr cur) { * Should be called in the context of attributes dumps. */ static void -xmlNsDump(xmlNsPtr cur) { +xmlNsDump(xmlBufferPtr buf, xmlNsPtr cur) { if (cur == NULL) { fprintf(stderr, "xmlNsDump : Ns == NULL\n"); return; @@ -2238,13 +2362,13 @@ xmlNsDump(xmlNsPtr cur) { if (cur->type == XML_LOCAL_NAMESPACE) { /* Within the context of an element attributes */ if (cur->prefix != NULL) { - xmlBufferWriteChar(" xmlns:"); - xmlBufferWriteCHAR(cur->prefix); + xmlBufferWriteChar(buf, " xmlns:"); + xmlBufferWriteCHAR(buf, cur->prefix); } else - xmlBufferWriteChar(" xmlns"); - xmlBufferWriteChar("=\""); - xmlBufferWriteCHAR(cur->href); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " xmlns"); + xmlBufferWriteChar(buf, "=\""); + xmlBufferWriteCHAR(buf, cur->href); + xmlBufferWriteChar(buf, "\""); } } @@ -2256,9 +2380,9 @@ xmlNsDump(xmlNsPtr cur) { * Should be called in the context of attributes dumps. */ static void -xmlNsListDump(xmlNsPtr cur) { +xmlNsListDump(xmlBufferPtr buf, xmlNsPtr cur) { while (cur != NULL) { - xmlNsDump(cur); + xmlNsDump(buf, cur); cur = cur->next; } } @@ -2270,44 +2394,44 @@ xmlNsListDump(xmlNsPtr cur) { * Dump the XML document DTD, if any. */ static void -xmlDtdDump(xmlDocPtr doc) { +xmlDtdDump(xmlBufferPtr buf, xmlDocPtr doc) { xmlDtdPtr cur = doc->intSubset; if (cur == NULL) { fprintf(stderr, "xmlDtdDump : no internal subset\n"); return; } - xmlBufferWriteChar("name); + xmlBufferWriteChar(buf, "name); if (cur->ExternalID != NULL) { - xmlBufferWriteChar(" PUBLIC \""); - xmlBufferWriteCHAR(cur->ExternalID); - xmlBufferWriteChar("\" \""); - xmlBufferWriteCHAR(cur->SystemID); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " PUBLIC \""); + xmlBufferWriteCHAR(buf, cur->ExternalID); + xmlBufferWriteChar(buf, "\" \""); + xmlBufferWriteCHAR(buf, cur->SystemID); + xmlBufferWriteChar(buf, "\""); } else if (cur->SystemID != NULL) { - xmlBufferWriteChar(" SYSTEM \""); - xmlBufferWriteCHAR(cur->SystemID); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " SYSTEM \""); + xmlBufferWriteCHAR(buf, cur->SystemID); + xmlBufferWriteChar(buf, "\""); } if ((cur->entities == NULL) && (cur->elements == NULL) && (cur->attributes == NULL) && (cur->notations == NULL)) { - xmlBufferWriteChar(">\n"); + xmlBufferWriteChar(buf, ">\n"); return; } - xmlBufferWriteChar(" [\n"); + xmlBufferWriteChar(buf, " [\n"); if (cur->entities != NULL) - xmlDumpEntitiesTable((xmlEntitiesTablePtr) cur->entities); + xmlDumpEntitiesTable(buf, (xmlEntitiesTablePtr) cur->entities); if (cur->notations != NULL) - xmlDumpNotationTable((xmlNotationTablePtr) cur->notations); + xmlDumpNotationTable(buf, (xmlNotationTablePtr) cur->notations); if (cur->elements != NULL) - xmlDumpElementTable((xmlElementTablePtr) cur->elements); + xmlDumpElementTable(buf, (xmlElementTablePtr) cur->elements); if (cur->attributes != NULL) - xmlDumpAttributeTable((xmlAttributeTablePtr) cur->attributes); - xmlBufferWriteChar("]"); + xmlDumpAttributeTable(buf, (xmlAttributeTablePtr) cur->attributes); + xmlBufferWriteChar(buf, "]"); /* TODO !!! a lot more things to dump ... */ - xmlBufferWriteChar(">\n"); + xmlBufferWriteChar(buf, ">\n"); } /** @@ -2318,23 +2442,23 @@ xmlDtdDump(xmlDocPtr doc) { * Dump an XML attribute */ static void -xmlAttrDump(xmlDocPtr doc, xmlAttrPtr cur) { +xmlAttrDump(xmlBufferPtr buf, xmlDocPtr doc, xmlAttrPtr cur) { CHAR *value; if (cur == NULL) { fprintf(stderr, "xmlAttrDump : property == NULL\n"); return; } - xmlBufferWriteChar(" "); - xmlBufferWriteCHAR(cur->name); + xmlBufferWriteChar(buf, " "); + xmlBufferWriteCHAR(buf, cur->name); value = xmlNodeListGetString(doc, cur->val, 0); if (value) { - xmlBufferWriteChar("=\""); - xmlBufferWriteCHAR(value); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, "=\""); + xmlBufferWriteCHAR(buf, value); + xmlBufferWriteChar(buf, "\""); free(value); } else { - xmlBufferWriteChar("=\"\""); + xmlBufferWriteChar(buf, "=\"\""); } } @@ -2346,20 +2470,20 @@ xmlAttrDump(xmlDocPtr doc, xmlAttrPtr cur) { * Dump a list of XML attributes */ static void -xmlAttrListDump(xmlDocPtr doc, xmlAttrPtr cur) { +xmlAttrListDump(xmlBufferPtr buf, xmlDocPtr doc, xmlAttrPtr cur) { if (cur == NULL) { fprintf(stderr, "xmlAttrListDump : property == NULL\n"); return; } while (cur != NULL) { - xmlAttrDump(doc, cur); + xmlAttrDump(buf, doc, cur); cur = cur->next; } } static void -xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level); +xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level); /** * xmlNodeListDump: * @doc: the document @@ -2369,7 +2493,7 @@ xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level); * Dump an XML node list, recursive behaviour,children are printed too. */ static void -xmlNodeListDump(xmlDocPtr doc, xmlNodePtr cur, int level) { +xmlNodeListDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level) { int needIndent = 0, i; if (cur == NULL) { @@ -2381,15 +2505,15 @@ xmlNodeListDump(xmlDocPtr doc, xmlNodePtr cur, int level) { (cur->type != XML_ENTITY_REF_NODE)) { if (!needIndent) { needIndent = 1; - xmlBufferWriteChar("\n"); + xmlBufferWriteChar(buf, "\n"); } } - xmlNodeDump(doc, cur, level); + xmlNodeDump(buf, doc, cur, level); cur = cur->next; } if ((xmlIndentTreeOutput) && (needIndent)) for (i = 1;i < level;i++) - xmlBufferWriteChar(" "); + xmlBufferWriteChar(buf, " "); } /** @@ -2401,7 +2525,7 @@ xmlNodeListDump(xmlDocPtr doc, xmlNodePtr cur, int level) { * Dump an XML node, recursive behaviour,children are printed too. */ static void -xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level) { +xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level) { int i; if (cur == NULL) { @@ -2410,57 +2534,57 @@ xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level) { } if (cur->type == XML_TEXT_NODE) { if (cur->content != NULL) - xmlBufferWriteCHAR(xmlEncodeEntities(doc, cur->content)); + xmlBufferWriteCHAR(buf, xmlEncodeEntities(doc, cur->content)); return; } if (cur->type == XML_COMMENT_NODE) { if (cur->content != NULL) { - xmlBufferWriteChar(""); + xmlBufferWriteChar(buf, ""); } return; } if (cur->type == XML_ENTITY_REF_NODE) { - xmlBufferWriteChar("&"); - xmlBufferWriteCHAR(cur->name); - xmlBufferWriteChar(";"); + xmlBufferWriteChar(buf, "&"); + xmlBufferWriteCHAR(buf, cur->name); + xmlBufferWriteChar(buf, ";"); return; } if (xmlIndentTreeOutput) for (i = 0;i < level;i++) - xmlBufferWriteChar(" "); + xmlBufferWriteChar(buf, " "); - xmlBufferWriteChar("<"); + xmlBufferWriteChar(buf, "<"); if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { - xmlBufferWriteCHAR(cur->ns->prefix); - xmlBufferWriteChar(":"); + xmlBufferWriteCHAR(buf, cur->ns->prefix); + xmlBufferWriteChar(buf, ":"); } - xmlBufferWriteCHAR(cur->name); + xmlBufferWriteCHAR(buf, cur->name); if (cur->nsDef) - xmlNsListDump(cur->nsDef); + xmlNsListDump(buf, cur->nsDef); if (cur->properties != NULL) - xmlAttrListDump(doc, cur->properties); + xmlAttrListDump(buf, doc, cur->properties); if ((cur->content == NULL) && (cur->childs == NULL)) { - xmlBufferWriteChar("/>\n"); + xmlBufferWriteChar(buf, "/>\n"); return; } - xmlBufferWriteChar(">"); + xmlBufferWriteChar(buf, ">"); if (cur->content != NULL) - xmlBufferWriteCHAR(xmlEncodeEntities(doc, cur->content)); + xmlBufferWriteCHAR(buf, xmlEncodeEntities(doc, cur->content)); if (cur->childs != NULL) { - xmlNodeListDump(doc, cur->childs, level + 1); + xmlNodeListDump(buf, doc, cur->childs, level + 1); } - xmlBufferWriteChar("ns != NULL) && (cur->ns->prefix != NULL)) { - xmlBufferWriteCHAR(cur->ns->prefix); - xmlBufferWriteChar(":"); + xmlBufferWriteCHAR(buf, cur->ns->prefix); + xmlBufferWriteChar(buf, ":"); } - xmlBufferWriteCHAR(cur->name); - xmlBufferWriteChar(">\n"); + xmlBufferWriteCHAR(buf, cur->name); + xmlBufferWriteChar(buf, ">\n"); } /** @@ -2470,36 +2594,36 @@ xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level) { * Dump an XML document. */ static void -xmlDocContentDump(xmlDocPtr cur) { +xmlDocContentDump(xmlBufferPtr buf, xmlDocPtr cur) { if (oldXMLWDcompatibility) - xmlBufferWriteChar("version); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, "version); + xmlBufferWriteChar(buf, "\""); if (cur->encoding != NULL) { - xmlBufferWriteChar(" encoding=\""); - xmlBufferWriteCHAR(cur->encoding); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " encoding=\""); + xmlBufferWriteCHAR(buf, cur->encoding); + xmlBufferWriteChar(buf, "\""); } switch (cur->standalone) { case 0: - xmlBufferWriteChar(" standalone=\"no\""); + xmlBufferWriteChar(buf, " standalone=\"no\""); break; case 1: - xmlBufferWriteChar(" standalone=\"yes\""); + xmlBufferWriteChar(buf, " standalone=\"yes\""); break; } - xmlBufferWriteChar("?>\n"); + xmlBufferWriteChar(buf, "?>\n"); if (cur->intSubset != NULL) - xmlDtdDump(cur); + xmlDtdDump(buf, cur); if (cur->root != NULL) { /* global namespace definitions, the old way */ if (oldXMLWDcompatibility) - xmlGlobalNsListDump(cur->oldNs); + xmlGlobalNsListDump(buf, cur->oldNs); else xmlUpgradeOldNs(cur); - xmlNodeDump(cur, cur->root, 0); + xmlNodeDump(buf, cur, cur->root, 0); } } @@ -2514,6 +2638,8 @@ xmlDocContentDump(xmlDocPtr cur) { */ void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size) { + xmlBufferPtr buf; + if (cur == NULL) { #ifdef DEBUG_TREE fprintf(stderr, "xmlDocDumpMemory : document == NULL\n"); @@ -2522,11 +2648,17 @@ xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size) { *size = 0; return; } - buffer_index = 0; - xmlDocContentDump(cur); - - *mem = buffer; - *size = buffer_index; + buf = xmlBufferCreate(); + if (buf == NULL) { + *mem = NULL; + *size = 0; + return; + } + xmlDocContentDump(buf, cur); + *mem = buf->content; + *size = buf->use; + memset(buf, -1, sizeof(xmlBuffer)); + free(buf); } /** @@ -2592,16 +2724,19 @@ xmlSetCompressMode(int mode) { */ void xmlDocDump(FILE *f, xmlDocPtr cur) { + xmlBufferPtr buf; + if (cur == NULL) { #ifdef DEBUG_TREE fprintf(stderr, "xmlDocDump : document == NULL\n"); #endif return; } - buffer_index = 0; - xmlDocContentDump(cur); - - fwrite(buffer, sizeof(CHAR), buffer_index, f); + buf = xmlBufferCreate(); + if (buf == NULL) return; + xmlDocContentDump(buf, cur); + xmlBufferDump(f, buf); + xmlBufferFree(buf); } /** @@ -2615,6 +2750,7 @@ xmlDocDump(FILE *f, xmlDocPtr cur) { */ int xmlSaveFile(const char *filename, xmlDocPtr cur) { + xmlBufferPtr buf; #ifdef HAVE_ZLIB_H gzFile zoutput = NULL; char mode[15]; @@ -2622,6 +2758,13 @@ xmlSaveFile(const char *filename, xmlDocPtr cur) { FILE *output = NULL; int ret; + /* + * save the content to a temp buffer. + */ + buf = xmlBufferCreate(); + if (buf == NULL) return(0); + xmlDocContentDump(buf, cur); + #ifdef HAVE_ZLIB_H if ((cur->compression > 0) && (cur->compression <= 9)) { sprintf(mode, "w%d", cur->compression); @@ -2635,21 +2778,19 @@ xmlSaveFile(const char *filename, xmlDocPtr cur) { } #endif - /* - * save the content to a temp buffer. - */ - buffer_index = 0; - xmlDocContentDump(cur); + xmlDocContentDump(buf, cur); #ifdef HAVE_ZLIB_H if (zoutput != NULL) { - ret = gzwrite(zoutput, buffer, sizeof(CHAR) * buffer_index); + ret = gzwrite(zoutput, buf->content, sizeof(CHAR) * buf->use); gzclose(zoutput); - return(ret); + } else { +#endif + ret = xmlBufferDump(output, buf); + fclose(output); +#ifdef HAVE_ZLIB_H } #endif - ret = fwrite(buffer, sizeof(CHAR), buffer_index, output); - fclose(output); return(ret * sizeof(CHAR)); } diff --git a/tree.h b/tree.h index 3f00aa09..ff6b55f7 100644 --- a/tree.h +++ b/tree.h @@ -240,6 +240,18 @@ typedef struct xmlDoc { typedef _xmlDoc xmlDoc; typedef xmlDoc *xmlDocPtr; +/* + * A buffer structure + */ + +typedef struct xmlBuffer { + CHAR *content; /* The buffer content UTF8 */ + unsigned int use; /* The buffer size used */ + unsigned int size; /* The buffer size */ +} _xmlBuffer; +typedef _xmlBuffer xmlBuffer; +typedef xmlBuffer *xmlBufferPtr; + /* * Variables. */ @@ -247,6 +259,17 @@ extern xmlNsPtr baseDTD; extern int oldXMLWDcompatibility;/* maintain compatibility with old WD */ extern int xmlIndentTreeOutput; /* try to indent the tree dumps */ +/* + * Handling Buffers. + */ + +xmlBufferPtr xmlBufferCreate(void); +void xmlBufferFree(xmlBufferPtr buf); +int xmlBufferDump(FILE *file, xmlBufferPtr buf); +void xmlBufferAdd(xmlBufferPtr buf, const CHAR *str, int len); +void xmlBufferCat(xmlBufferPtr buf, const CHAR *str); +void xmlBufferCCat(xmlBufferPtr buf, const char *str); + /* * Creating/freeing new structures */ @@ -337,8 +360,8 @@ CHAR *xmlNodeGetContent(xmlNodePtr cur); /* * Internal, don't use */ -void xmlBufferWriteCHAR(const CHAR *string); -void xmlBufferWriteChar(const char *string); +void xmlBufferWriteCHAR(xmlBufferPtr buf, const CHAR *string); +void xmlBufferWriteChar(xmlBufferPtr buf, const char *string); /* * Saving diff --git a/valid.c b/valid.c index 2c1be9f2..409db5bd 100644 --- a/valid.c +++ b/valid.c @@ -101,67 +101,65 @@ xmlFreeElementContent(xmlElementContentPtr cur) { /** * xmlDumpElementContent: + * @buf: An XML buffer * @content: An element table * @glob: 1 if one must print the englobing parenthesis, 0 otherwise * * This will dump the content of the element table as an XML DTD definition - * - * NOTE: TODO an extra parameter allowing a reentant implementation will - * be added. */ void -xmlDumpElementContent(xmlElementContentPtr content, int glob) { +xmlDumpElementContent(xmlBufferPtr buf, xmlElementContentPtr content, int glob) { if (content == NULL) return; - if (glob) xmlBufferWriteChar("("); + if (glob) xmlBufferWriteChar(buf, "("); switch (content->type) { case XML_ELEMENT_CONTENT_PCDATA: - xmlBufferWriteChar("#PCDATA"); + xmlBufferWriteChar(buf, "#PCDATA"); break; case XML_ELEMENT_CONTENT_ELEMENT: - xmlBufferWriteCHAR(content->name); + xmlBufferWriteCHAR(buf, content->name); break; case XML_ELEMENT_CONTENT_SEQ: if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || (content->c1->type == XML_ELEMENT_CONTENT_SEQ)) - xmlDumpElementContent(content->c1, 1); + xmlDumpElementContent(buf, content->c1, 1); else - xmlDumpElementContent(content->c1, 0); - xmlBufferWriteChar(" , "); + xmlDumpElementContent(buf, content->c1, 0); + xmlBufferWriteChar(buf, " , "); if (content->c2->type == XML_ELEMENT_CONTENT_OR) - xmlDumpElementContent(content->c2, 1); + xmlDumpElementContent(buf, content->c2, 1); else - xmlDumpElementContent(content->c2, 0); + xmlDumpElementContent(buf, content->c2, 0); break; case XML_ELEMENT_CONTENT_OR: if ((content->c1->type == XML_ELEMENT_CONTENT_OR) || (content->c1->type == XML_ELEMENT_CONTENT_SEQ)) - xmlDumpElementContent(content->c1, 1); + xmlDumpElementContent(buf, content->c1, 1); else - xmlDumpElementContent(content->c1, 0); - xmlBufferWriteChar(" | "); + xmlDumpElementContent(buf, content->c1, 0); + xmlBufferWriteChar(buf, " | "); if (content->c2->type == XML_ELEMENT_CONTENT_SEQ) - xmlDumpElementContent(content->c2, 1); + xmlDumpElementContent(buf, content->c2, 1); else - xmlDumpElementContent(content->c2, 0); + xmlDumpElementContent(buf, content->c2, 0); break; default: fprintf(stderr, "xmlDumpElementContent: unknown type %d\n", content->type); } if (glob) - xmlBufferWriteChar(")"); + xmlBufferWriteChar(buf, ")"); switch (content->ocur) { case XML_ELEMENT_CONTENT_ONCE: break; case XML_ELEMENT_CONTENT_OPT: - xmlBufferWriteChar("?"); + xmlBufferWriteChar(buf, "?"); break; case XML_ELEMENT_CONTENT_MULT: - xmlBufferWriteChar("*"); + xmlBufferWriteChar(buf, "*"); break; case XML_ELEMENT_CONTENT_PLUS: - xmlBufferWriteChar("+"); + xmlBufferWriteChar(buf, "+"); break; } } @@ -404,7 +402,7 @@ xmlCopyElementTable(xmlElementTablePtr table) { * be added. */ void -xmlDumpElementTable(xmlElementTablePtr table) { +xmlDumpElementTable(xmlBufferPtr buf, xmlElementTablePtr table) { int i; xmlElementPtr cur; @@ -414,28 +412,28 @@ xmlDumpElementTable(xmlElementTablePtr table) { cur = &table->table[i]; switch (cur->type) { case XML_ELEMENT_TYPE_EMPTY: - xmlBufferWriteChar("name); - xmlBufferWriteChar(" EMPTY>\n"); + xmlBufferWriteChar(buf, "name); + xmlBufferWriteChar(buf, " EMPTY>\n"); break; case XML_ELEMENT_TYPE_ANY: - xmlBufferWriteChar("name); - xmlBufferWriteChar(" ANY>\n"); + xmlBufferWriteChar(buf, "name); + xmlBufferWriteChar(buf, " ANY>\n"); break; case XML_ELEMENT_TYPE_MIXED: - xmlBufferWriteChar("name); - xmlBufferWriteChar(" "); - xmlDumpElementContent(cur->content, 1); - xmlBufferWriteChar(">\n"); + xmlBufferWriteChar(buf, "name); + xmlBufferWriteChar(buf, " "); + xmlDumpElementContent(buf, cur->content, 1); + xmlBufferWriteChar(buf, ">\n"); break; case XML_ELEMENT_TYPE_ELEMENT: - xmlBufferWriteChar("name); - xmlBufferWriteChar(" "); - xmlDumpElementContent(cur->content, 1); - xmlBufferWriteChar(">\n"); + xmlBufferWriteChar(buf, "name); + xmlBufferWriteChar(buf, " "); + xmlDumpElementContent(buf, cur->content, 1); + xmlBufferWriteChar(buf, ">\n"); break; default: fprintf(stderr, @@ -765,7 +763,7 @@ xmlCopyAttributeTable(xmlAttributeTablePtr table) { * be added. */ void -xmlDumpAttributeTable(xmlAttributeTablePtr table) { +xmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table) { int i; xmlAttributePtr cur; @@ -773,40 +771,40 @@ xmlDumpAttributeTable(xmlAttributeTablePtr table) { for (i = 0;i < table->nb_attributes;i++) { cur = &table->table[i]; - xmlBufferWriteChar("elem); - xmlBufferWriteChar(" "); - xmlBufferWriteCHAR(cur->name); + xmlBufferWriteChar(buf, "elem); + xmlBufferWriteChar(buf, " "); + xmlBufferWriteCHAR(buf, cur->name); switch (cur->type) { case XML_ATTRIBUTE_CDATA: - xmlBufferWriteChar(" CDATA"); + xmlBufferWriteChar(buf, " CDATA"); break; case XML_ATTRIBUTE_ID: - xmlBufferWriteChar(" ID"); + xmlBufferWriteChar(buf, " ID"); break; case XML_ATTRIBUTE_IDREF: - xmlBufferWriteChar(" IDREF"); + xmlBufferWriteChar(buf, " IDREF"); break; case XML_ATTRIBUTE_IDREFS: - xmlBufferWriteChar(" IDREFS"); + xmlBufferWriteChar(buf, " IDREFS"); break; case XML_ATTRIBUTE_ENTITY: - xmlBufferWriteChar(" ENTITY"); + xmlBufferWriteChar(buf, " ENTITY"); break; case XML_ATTRIBUTE_ENTITIES: - xmlBufferWriteChar(" ENTITIES"); + xmlBufferWriteChar(buf, " ENTITIES"); break; case XML_ATTRIBUTE_NMTOKEN: - xmlBufferWriteChar(" NMTOKEN"); + xmlBufferWriteChar(buf, " NMTOKEN"); break; case XML_ATTRIBUTE_NMTOKENS: - xmlBufferWriteChar(" NMTOKENS"); + xmlBufferWriteChar(buf, " NMTOKENS"); break; case XML_ATTRIBUTE_ENUMERATION: - xmlBufferWriteChar(" (pbm)"); + xmlBufferWriteChar(buf, " (pbm)"); break; case XML_ATTRIBUTE_NOTATION: - xmlBufferWriteChar(" NOTATION (pbm)"); + xmlBufferWriteChar(buf, " NOTATION (pbm)"); break; default: fprintf(stderr, @@ -817,27 +815,27 @@ xmlDumpAttributeTable(xmlAttributeTablePtr table) { case XML_ATTRIBUTE_NONE: break; case XML_ATTRIBUTE_REQUIRED: - xmlBufferWriteChar(" #REQUIRED"); + xmlBufferWriteChar(buf, " #REQUIRED"); break; case XML_ATTRIBUTE_IMPLIED: - xmlBufferWriteChar(" #IMPLIED"); + xmlBufferWriteChar(buf, " #IMPLIED"); if (cur->defaultValue != NULL) { - xmlBufferWriteChar(" \""); - xmlBufferWriteCHAR(cur->defaultValue); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " \""); + xmlBufferWriteCHAR(buf, cur->defaultValue); + xmlBufferWriteChar(buf, "\""); } break; case XML_ATTRIBUTE_FIXED: - xmlBufferWriteChar(" #FIXED \""); - xmlBufferWriteCHAR(cur->defaultValue); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " #FIXED \""); + xmlBufferWriteCHAR(buf, cur->defaultValue); + xmlBufferWriteChar(buf, "\""); break; default: fprintf(stderr, "xmlDumpAttributeTable: internal: unknown default %d\n", cur->def); } - xmlBufferWriteChar(">\n"); + xmlBufferWriteChar(buf, ">\n"); } } @@ -1063,7 +1061,7 @@ xmlCopyNotationTable(xmlNotationTablePtr table) { * be added. */ void -xmlDumpNotationTable(xmlNotationTablePtr table) { +xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table) { int i; xmlNotationPtr cur; @@ -1071,20 +1069,20 @@ xmlDumpNotationTable(xmlNotationTablePtr table) { for (i = 0;i < table->nb_notations;i++) { cur = &table->table[i]; - xmlBufferWriteChar("name); + xmlBufferWriteChar(buf, "name); if (cur->PublicID != NULL) { - xmlBufferWriteChar(" PUBLIC \""); - xmlBufferWriteCHAR(cur->PublicID); - xmlBufferWriteChar("\""); + xmlBufferWriteChar(buf, " PUBLIC \""); + xmlBufferWriteCHAR(buf, cur->PublicID); + xmlBufferWriteChar(buf, "\""); if (cur->SystemID != NULL) { - xmlBufferWriteChar(" "); - xmlBufferWriteCHAR(cur->SystemID); + xmlBufferWriteChar(buf, " "); + xmlBufferWriteCHAR(buf, cur->SystemID); } } else { - xmlBufferWriteChar(" SYSTEM "); - xmlBufferWriteCHAR(cur->SystemID); + xmlBufferWriteChar(buf, " SYSTEM "); + xmlBufferWriteCHAR(buf, cur->SystemID); } - xmlBufferWriteChar(" >\n"); + xmlBufferWriteChar(buf, " >\n"); } } diff --git a/valid.h b/valid.h index 22c824ab..084d97fa 100644 --- a/valid.h +++ b/valid.h @@ -58,7 +58,7 @@ xmlNotationPtr xmlAddNotationDecl(xmlDtdPtr dtd, const CHAR *name, const CHAR *PublicID, const CHAR *SystemID); xmlNotationTablePtr xmlCopyNotationTable(xmlNotationTablePtr table); void xmlFreeNotationTable(xmlNotationTablePtr table); -void xmlDumpNotationTable(xmlNotationTablePtr table); +void xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table); /* Element Content */ xmlElementContentPtr xmlNewElementContent(CHAR *name, int type); @@ -70,7 +70,7 @@ xmlElementPtr xmlAddElementDecl(xmlDtdPtr dtd, const CHAR *name, int type, xmlElementContentPtr content); xmlElementTablePtr xmlCopyElementTable(xmlElementTablePtr table); void xmlFreeElementTable(xmlElementTablePtr table); -void xmlDumpElementTable(xmlElementTablePtr table); +void xmlDumpElementTable(xmlBufferPtr buf, xmlElementTablePtr table); /* Enumeration */ xmlEnumerationPtr xmlCreateEnumeration(CHAR *name); @@ -83,6 +83,6 @@ xmlAttributePtr xmlAddAttributeDecl(xmlDtdPtr dtd, const CHAR *elem, const CHAR *defaultValue, xmlEnumerationPtr tree); xmlAttributeTablePtr xmlCopyAttributeTable(xmlAttributeTablePtr table); void xmlFreeAttributeTable(xmlAttributeTablePtr table); -void xmlDumpAttributeTable(xmlAttributeTablePtr table); +void xmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table); #endif /* __XML_VALID_H__ */