From 11a48ec6f439c0a12a02ac503507086aaf260dcc Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 23 Nov 1999 10:40:46 +0000 Subject: [PATCH] Closing bug report #3748, changed global compression flag usage, and added xmlNewTextChild() and xmlNewDocRawNode(), Daniel --- ChangeLog | 7 + doc/html/gnome-xml-entities.html | 50 +- doc/html/gnome-xml-htmlparser.html | 44 +- doc/html/gnome-xml-htmltree.html | 20 +- doc/html/gnome-xml-nanohttp.html | 22 +- doc/html/gnome-xml-parserinternals.html | 182 +++---- doc/html/gnome-xml-tree.html | 620 +++++++++++++++++++----- doc/html/gnome-xml-valid.html | 122 ++--- doc/html/gnome-xml-xml-error.html | 22 +- doc/html/gnome-xml-xmlmemory.html | 38 +- doc/html/gnome-xml-xpath.html | 38 +- doc/html/index.sgml | 2 + include/libxml/tree.h | 8 + parser.c | 5 +- tester.c | 25 +- tree.c | 118 ++++- tree.h | 8 + 17 files changed, 933 insertions(+), 398 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5fe0eede..03459b64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Nov 23 11:23:55 CET 1999 Daniel Veillard + + * tree.[ch]: closing bug 3748, added xmlNewDocRawNode(), + xmlNewTextChild() and xmlSetCompressMode() behaviour. + * tester.c: added --compress option + * doc/*: rebuilt the documentation + Fri Nov 19 18:41:28 CET 1999 Daniel Veillard * HTMLparser.c: bugfixing, the damn thing MUST not crash even diff --git a/doc/html/gnome-xml-entities.html b/doc/html/gnome-xml-entities.html index 0621785d..1ea56d9a 100644 --- a/doc/html/gnome-xml-entities.html +++ b/doc/html/gnome-xml-entities.html @@ -115,7 +115,7 @@ SIZE="3" >

Name

Synopsis

Description

Details





















Name

Synopsis

Description

Details


















Name

Synopsis

Description

Details






Name

Synopsis

Description

Details







Name

Synopsis

Description

Details























































































xmlNodePtr xmlNewDocRawNode (xmlDocPtr doc, + xmlNsPtr ns, + const xmlChar *name, + const xmlChar *content); +xmlNodePtr xmlNewNode (xmlNodePtr xmlNewTextChild (xmlNodePtr parent, + xmlNsPtr ns, + const xmlChar *name, + const xmlChar *content); +xmlNodePtr xmlNewDocText (

Description

Details























































content +are optionnal (NULL). +NOTE: content is supposed to be a piece of XML CDATA, so it allow entities +references, but XML special chars need to be escaped first by using +xmlEncodeEntitiesReentrant(). Use xmlNewDocRawNode() if you don't +need entities support.

doc : the document
ns : namespace if any
name : the node name
content : the XML text content if any
Returns :a pointer to the new node object.


xmlNewDocRawNode ()

xmlNodePtr  xmlNewDocRawNode                (xmlDocPtr doc,
+                                             xmlNsPtr ns,
+                                             const xmlChar *name,
+                                             const xmlChar *content);

Creation of a new node element within a document. ns and content are optionnal (NULL).



content parameters are optionnal (NULL). If content is non NULL, -a child list containing the TEXTs and ENTITY_REFs node will be created.

content is supposed to be a piece of XML CDATA, so it allow entities +references, but XML special chars need to be escaped first by using +
xmlEncodeEntitiesReentrant(). Use xmlNewTextChild() if entities +support is not needed.

the content of the child if any. the XML content of the child if any.

xmlNewTextChild ()

xmlNodePtr  xmlNewTextChild                 (xmlNodePtr parent,
+                                             xmlNsPtr ns,
+                                             const xmlChar *name,
+                                             const xmlChar *content);

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 TEXT node will be created containing the string content.

parent : the parent node
ns : a namespace if any
name : the name of the child
content : the text content of the child if any.
Returns :a pointer to the new node object.















































Dump an XML document to a file. Will use compression if -compiled in and enabled.

filename is "-" the stdout file is +used.





Name

Synopsis

Description

Details

























































Name

Synopsis

Description

Details







Name

Synopsis

Description

Details















Name

Synopsis

Description

Details















+ + diff --git a/include/libxml/tree.h b/include/libxml/tree.h index 6c8ab102..f5fcf57a 100644 --- a/include/libxml/tree.h +++ b/include/libxml/tree.h @@ -363,12 +363,20 @@ xmlNodePtr xmlNewDocNode (xmlDocPtr doc, xmlNsPtr ns, const xmlChar *name, const xmlChar *content); +xmlNodePtr xmlNewDocRawNode (xmlDocPtr doc, + xmlNsPtr ns, + const xmlChar *name, + const xmlChar *content); xmlNodePtr xmlNewNode (xmlNsPtr ns, const xmlChar *name); xmlNodePtr xmlNewChild (xmlNodePtr parent, xmlNsPtr ns, const xmlChar *name, const xmlChar *content); +xmlNodePtr xmlNewTextChild (xmlNodePtr parent, + xmlNsPtr ns, + const xmlChar *name, + const xmlChar *content); xmlNodePtr xmlNewDocText (xmlDocPtr doc, const xmlChar *content); xmlNodePtr xmlNewText (const xmlChar *content); diff --git a/parser.c b/parser.c index f3bd47a1..4d84c8d6 100644 --- a/parser.c +++ b/parser.c @@ -6651,8 +6651,9 @@ xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const xmlChar* buffer, * * Returns 0 in case of success or a error number otherwise */ -int xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data, - const char *filename) { +int +xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data, + const char *filename) { int ret = 0; xmlParserCtxtPtr ctxt; diff --git a/tester.c b/tester.c index 7002614b..02cf5fb9 100644 --- a/tester.c +++ b/tester.c @@ -45,6 +45,7 @@ static int noout = 0; static int valid = 0; static int repeat = 0; static int insert = 0; +static int compress = 0; extern int xmlDoValidityCheckingDefaultValue; @@ -168,9 +169,12 @@ void parseAndPrintFile(char *filename) { /* * print it. */ - if (!debug) - xmlDocDump(stdout, doc); - else + if (!debug) { + if (compress) + xmlSaveFile("-", doc); + else + xmlDocDump(stdout, doc); + } else xmlDebugDumpDocument(stdout, doc); } @@ -203,9 +207,12 @@ void parseAndPrintBuffer(xmlChar *buf) { /* * print it. */ - if (!debug) - xmlDocDump(stdout, doc); - else + if (!debug) { + if (compress) + xmlSaveFile("-", doc); + else + xmlDocDump(stdout, doc); + } else xmlDebugDumpDocument(stdout, doc); /* @@ -241,6 +248,11 @@ int main(int argc, char **argv) { else if ((!strcmp(argv[i], "-repeat")) || (!strcmp(argv[i], "--repeat"))) repeat++; + else if ((!strcmp(argv[i], "-compress")) || + (!strcmp(argv[i], "--compress"))) { + compress++; + xmlSetCompressMode(9); + } } if (noent != 0) xmlSubstituteEntitiesDefault(1); if (valid != 0) xmlDoValidityCheckingDefaultValue = 1; @@ -266,6 +278,7 @@ int main(int argc, char **argv) { printf("\t--valid : validate the document in addition to std well-formed check\n"); printf("\t--repeat : parse the file 100 times, for timing or profiling\n"); printf("\t--insert : test for valid insertions\n"); + printf("\t--compress : turn on gzip compression of output\n"); } xmlMemoryDump(); diff --git a/tree.c b/tree.c index 23819a16..4945ed12 100644 --- a/tree.c +++ b/tree.c @@ -403,7 +403,7 @@ xmlNewDoc(const xmlChar *version) { cur->oldNs = NULL; cur->encoding = NULL; cur->standalone = -1; - cur->compression = xmlCompressMode; + cur->compression = -1; /* not initialized */ cur->ids = NULL; cur->refs = NULL; #ifndef XML_WITHOUT_CORBA @@ -1027,15 +1027,20 @@ xmlNewNode(xmlNsPtr ns, const xmlChar *name) { * @doc: the document * @ns: namespace if any * @name: the node name - * @content: the text content if any + * @content: the XML text content if any * * Creation of a new node element within a document. @ns and @content * are optionnal (NULL). + * NOTE: @content is supposed to be a piece of XML CDATA, so it allow entities + * references, but XML special chars need to be escaped first by using + * xmlEncodeEntitiesReentrant(). Use xmlNewDocRawNode() if you don't + * need entities support. + * * Returns a pointer to the new node object. */ xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns, - const xmlChar *name, const xmlChar *content) { + const xmlChar *name, const xmlChar *content) { xmlNodePtr cur; cur = xmlNewNode(ns, name); @@ -1050,6 +1055,35 @@ xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns, } +/** + * xmlNewDocRawNode: + * @doc: the document + * @ns: namespace if any + * @name: the node name + * @content: the text content if any + * + * Creation of a new node element within a document. @ns and @content + * are optionnal (NULL). + * + * Returns a pointer to the new node object. + */ +xmlNodePtr +xmlNewDocRawNode(xmlDocPtr doc, xmlNsPtr ns, + const xmlChar *name, const xmlChar *content) { + xmlNodePtr cur; + + cur = xmlNewNode(ns, name); + if (cur != NULL) { + cur->doc = doc; + if (content != NULL) { + cur->childs = xmlNewDocText(doc, content); + UPDATE_LAST_CHILD(cur) + } + } + return(cur); +} + + /** * xmlNewText: * @content: the text content @@ -1093,6 +1127,62 @@ xmlNewText(const xmlChar *content) { return(cur); } +/** + * xmlNewTextChild: + * @parent: the parent node + * @ns: a namespace if any + * @name: the name of the child + * @content: the text content of the child if any. + * + * 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 TEXT node will be created containing the string content. + * + * Returns a pointer to the new node object. + */ +xmlNodePtr +xmlNewTextChild(xmlNodePtr parent, xmlNsPtr ns, + const xmlChar *name, const xmlChar *content) { + xmlNodePtr cur, prev; + + if (parent == NULL) { + fprintf(stderr, "xmlNewTextChild : parent == NULL\n"); + return(NULL); + } + + if (name == NULL) { + fprintf(stderr, "xmlNewTextChild : name == NULL\n"); + return(NULL); + } + + /* + * Allocate a new node + */ + if (ns == NULL) + cur = xmlNewDocRawNode(parent->doc, parent->ns, name, content); + else + cur = xmlNewDocRawNode(parent->doc, ns, name, content); + if (cur == NULL) return(NULL); + + /* + * add the new element at the end of the childs list. + */ + cur->type = XML_ELEMENT_NODE; + cur->parent = parent; + cur->doc = parent->doc; + if (parent->childs == NULL) { + parent->childs = cur; + parent->last = cur; + } else { + prev = parent->last; + prev->next = cur; + cur->prev = prev; + parent->last = cur; + } + + return(cur); +} + /** * xmlNewReference: * @doc: the document @@ -1332,22 +1422,27 @@ xmlNewDocComment(xmlDocPtr doc, const xmlChar *content) { return(cur); } + /** * xmlNewChild: * @parent: the parent node * @ns: a namespace if any * @name: the name of the child - * @content: the content of the child if any. + * @content: the XML content of the child if any. * - * * 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. + * NOTE: @content is supposed to be a piece of XML CDATA, so it allow entities + * references, but XML special chars need to be escaped first by using + * xmlEncodeEntitiesReentrant(). Use xmlNewTextChild() if entities + * support is not needed. + * * Returns a pointer to the new node object. */ xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns, - const xmlChar *name, const xmlChar *content) { + const xmlChar *name, const xmlChar *content) { xmlNodePtr cur, prev; if (parent == NULL) { @@ -1703,7 +1798,7 @@ xmlCopyPropList(xmlNodePtr target, xmlAttrPtr cur) { } /* - * NOTE about the CopyNode operations ! + * NOTE abeut the CopyNode operations ! * * They are splitted into external and internal parts for one * tricky reason: namespaces. Doing a direct copy of a node @@ -3242,7 +3337,8 @@ xmlDocDump(FILE *f, xmlDocPtr cur) { * @cur: the document * * Dump an XML document to a file. Will use compression if - * compiled in and enabled. + * compiled in and enabled. If @filename is "-" the stdout file is + * used. * returns: the number of file written or -1 in case of failure. */ int @@ -3263,9 +3359,13 @@ xmlSaveFile(const char *filename, xmlDocPtr cur) { xmlDocContentDump(buf, cur); #ifdef HAVE_ZLIB_H + if (cur->compression < 0) cur->compression = xmlCompressMode; if ((cur->compression > 0) && (cur->compression <= 9)) { sprintf(mode, "w%d", cur->compression); - zoutput = gzopen(filename, mode); + if (!strcmp(filename, "-")) + zoutput = gzdopen(1, mode); + else + zoutput = gzopen(filename, mode); } if (zoutput == NULL) { #endif diff --git a/tree.h b/tree.h index 6c8ab102..f5fcf57a 100644 --- a/tree.h +++ b/tree.h @@ -363,12 +363,20 @@ xmlNodePtr xmlNewDocNode (xmlDocPtr doc, xmlNsPtr ns, const xmlChar *name, const xmlChar *content); +xmlNodePtr xmlNewDocRawNode (xmlDocPtr doc, + xmlNsPtr ns, + const xmlChar *name, + const xmlChar *content); xmlNodePtr xmlNewNode (xmlNsPtr ns, const xmlChar *name); xmlNodePtr xmlNewChild (xmlNodePtr parent, xmlNsPtr ns, const xmlChar *name, const xmlChar *content); +xmlNodePtr xmlNewTextChild (xmlNodePtr parent, + xmlNsPtr ns, + const xmlChar *name, + const xmlChar *content); xmlNodePtr xmlNewDocText (xmlDocPtr doc, const xmlChar *content); xmlNodePtr xmlNewText (const xmlChar *content);