Diff for /XML/tree.c between versions 1.22 and 1.23

version 1.22, 1998/08/13 04:54:38 version 1.23, 1998/10/26 01:38:59
Line 8 Line 8
  * TODO Cleanup the Dump mechanism.   * TODO Cleanup the Dump mechanism.
  */   */
   
   #include "config.h"
 #include <stdio.h>  #include <stdio.h>
 #include <ctype.h>  #include <ctype.h>
 #include <malloc.h>  #include <stdlib.h>
 #include <string.h> /* for memset() only ! */  #include <string.h> /* for memset() only ! */
   
   #ifdef HAVE_ZLIB_H
   #include <zlib.h>
   #endif
   
 #include "tree.h"  #include "tree.h"
 #include "entities.h"  #include "entities.h"
   
Line 20  static CHAR xmlStringText[] = { 't', 'e' Line 25  static CHAR xmlStringText[] = { 't', 'e'
 int oldXMLWDcompatibility = 0;  int oldXMLWDcompatibility = 0;
 int xmlIndentTreeOutput = 1;  int xmlIndentTreeOutput = 1;
   
   static int xmlCompressMode = 0;
   
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
  *              Allocation and deallocation of basic structures         *   *              Allocation and deallocation of basic structures         *
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
     
 /*  /**
  * Upgrade old Namespace and move them to the root of the document.   * xmlUpgradeOldNs:
    * @doc:  a document pointer
    * 
    * Upgrade old style Namespaces (PI) and move them to the root of the document.
  */   */
   
 void xmlUpgradeOldNs(xmlDocPtr doc) {  void xmlUpgradeOldNs(xmlDocPtr doc) {
     xmlNsPtr cur;      xmlNsPtr cur;
   
Line 50  void xmlUpgradeOldNs(xmlDocPtr doc) { Line 59  void xmlUpgradeOldNs(xmlDocPtr doc) {
     doc->oldNs = NULL;      doc->oldNs = NULL;
 }  }
   
 /*  /**
    * xmlNewNs:
    * @node:  the element carrying the namespace
    * @href:  the URI associated
    * @prefix:  the prefix for the namespace
    *
  * Creation of a new Namespace.   * Creation of a new Namespace.
    * return values: returns a new namespace pointer
  */   */
 xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *prefix) {  xmlNsPtr xmlNewNs(xmlNodePtr node, const CHAR *href, const CHAR *prefix) {
     xmlNsPtr cur;      xmlNsPtr cur;
Line 98  xmlNsPtr xmlNewNs(xmlNodePtr node, const Line 113  xmlNsPtr xmlNewNs(xmlNodePtr node, const
     return(cur);      return(cur);
 }  }
   
 /*  /**
  * Creation of a new global namespace (the old way ...).   * xmlNewGlobalNs:
    * @doc:  the document carrying the namespace
    * @href:  the URI associated
    * @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
  */   */
 xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *prefix) {  xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, const CHAR *href, const CHAR *prefix) {
     xmlNsPtr cur;      xmlNsPtr cur;
Line 141  xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, c Line 162  xmlNsPtr xmlNewGlobalNs(xmlDocPtr doc, c
     return(cur);      return(cur);
 }  }
   
 /*  /**
  * Set the node namespace a posteriori   * xmlSetNs:
    * @node:  a node in the document
    * @ns:  a namespace pointer
    *
    * Associate a namespace to a node, a posteriori.
  */   */
 void xmlSetNs(xmlNodePtr node, xmlNsPtr ns) {  void xmlSetNs(xmlNodePtr node, xmlNsPtr ns) {
     if (node == NULL) {      if (node == NULL) {
Line 152  void xmlSetNs(xmlNodePtr node, xmlNsPtr Line 177  void xmlSetNs(xmlNodePtr node, xmlNsPtr
     node->ns = ns;      node->ns = ns;
 }  }
   
 /*  /**
  * Freeing a Namespace   * xmlFreeNs:
    * @cur:  the namespace pointer
    *
    * Free up the structures associated to a namespace
  */   */
 void xmlFreeNs(xmlNsPtr cur) {  void xmlFreeNs(xmlNsPtr cur) {
     if (cur == NULL) {      if (cur == NULL) {
Line 166  void xmlFreeNs(xmlNsPtr cur) { Line 194  void xmlFreeNs(xmlNsPtr cur) {
     free(cur);      free(cur);
 }  }
   
 /*  /**
  * Freeing a Namespace list   * xmlFreeNsList:
    * @cur:  the first namespace pointer
    *
    * Free up all the structures associated to the chained namespaces.
  */   */
 void xmlFreeNsList(xmlNsPtr cur) {  void xmlFreeNsList(xmlNsPtr cur) {
     xmlNsPtr next;      xmlNsPtr next;
Line 182  void xmlFreeNsList(xmlNsPtr cur) { Line 213  void xmlFreeNsList(xmlNsPtr cur) {
     }      }
 }  }
   
 /*  /**
    * xmlNewDtd:
    * @doc:  the document pointer
    * @name:  the DTD name
    * @ExternalID:  the external ID
    * @SystemID:  the system ID
    *
  * Creation of a new DTD.   * Creation of a new DTD.
    * return values: a pointer to the new DTD structure
  */   */
 xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,  xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const CHAR *name,
                     const CHAR *ExternalID, const CHAR *SystemID) {                      const CHAR *ExternalID, const CHAR *SystemID) {
Line 222  xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const Line 260  xmlDtdPtr xmlNewDtd(xmlDocPtr doc, const
     return(cur);      return(cur);
 }  }
   
 /*  /**
  * Freeing a DTD   * xmlFreeDtd:
    * @cur:  the DTD structure to free up
    *
    * Free a DTD structure.
  */   */
 void xmlFreeDtd(xmlDtdPtr cur) {  void xmlFreeDtd(xmlDtdPtr cur) {
     if (cur == NULL) {      if (cur == NULL) {
Line 241  void xmlFreeDtd(xmlDtdPtr cur) { Line 282  void xmlFreeDtd(xmlDtdPtr cur) {
     free(cur);      free(cur);
 }  }
   
 /*  /**
  * Creation of a new document   * xmlNewDoc:
    * @version:  CHAR string giving the version of XML "1.0"
    *
    * Create a new document
  */   */
 xmlDocPtr xmlNewDoc(const CHAR *version) {  xmlDocPtr xmlNewDoc(const CHAR *version) {
     xmlDocPtr cur;      xmlDocPtr cur;
Line 261  xmlDocPtr xmlNewDoc(const CHAR *version) Line 305  xmlDocPtr xmlNewDoc(const CHAR *version)
         return(NULL);          return(NULL);
     }      }
   
       cur->type = XML_DOCUMENT_NODE;
     cur->version = xmlStrdup(version);       cur->version = xmlStrdup(version); 
     cur->name = NULL;      cur->name = NULL;
     cur->root = NULL;       cur->root = NULL; 
Line 269  xmlDocPtr xmlNewDoc(const CHAR *version) Line 314  xmlDocPtr xmlNewDoc(const CHAR *version)
     cur->encoding = NULL;      cur->encoding = NULL;
     cur->entities = NULL;      cur->entities = NULL;
     cur->standalone = -1;      cur->standalone = -1;
       cur->compression = xmlCompressMode;
   #ifndef WITHOUT_CORBA
       cur->_private = NULL;
       cur->vepv = NULL;
   #endif
     return(cur);      return(cur);
 }  }
   
 /*  /**
  * Freeing a document : all the tree is freed too.   * xmlFreeDoc:
    * @cur:  pointer to the document
    * @:  
    *
    * Free up all the structures used by a document, tree included.
  */   */
 void xmlFreeDoc(xmlDocPtr cur) {  void xmlFreeDoc(xmlDocPtr cur) {
     if (cur == NULL) {      if (cur == NULL) {
Line 291  void xmlFreeDoc(xmlDocPtr cur) { Line 345  void xmlFreeDoc(xmlDocPtr cur) {
     free(cur);      free(cur);
 }  }
   
 /*  /**
  * Creation of a new property of a node.   * xmlParsePropValue:
    * @value:  the value of the attribute
    *
    * Parse the value string and build the tree associated. Should
    * produce a flat tree with only text and references.
    * return values: a pointer to the first child
    */
   xmlNodePtr xmlParsePropValue(xmlDocPtr doc, const CHAR *value) {
       xmlNodePtr ret = NULL, last = NULL;
       xmlNodePtr node;
       CHAR *val;
       const CHAR *cur = value;
       const CHAR *q;
   
       if (value == NULL) return(NULL);
   
       q = cur;
       while (*cur != 0) {
           if (*cur == '&') {
               if (cur != q) {
                   node = xmlNewTextLen(q, cur - q);
                   if (node == NULL) return(ret);
                   if (last == NULL)
                       last = ret = node;
                   else {
                       last->next = node;
                       last = node;
                   }
               }
               cur++;
               q = cur;
               while ((*cur != 0) && (*cur != ';')) cur++;
               if (*cur == 0) {
                   fprintf(stderr, "xmlParsePropValue: unterminated entity %s\n",
                           q);
                   return(ret);
               }
               if (cur != q) {
                   val = xmlStrndup(q, cur - q);
                   node = xmlNewReference(doc, val);
                   if (node == NULL) return(ret);
                   if (last == NULL)
                       last = ret = node;
                   else {
                       last->next = node;
                       last = node;
                   }
                   free(val);
               }
               cur++;
               q = cur;
           } else 
               cur++;
       }
       if (cur != q) {
           node = xmlNewTextLen(q, cur - q);
           if (node == NULL) return(ret);
           if (last == NULL)
               last = ret = node;
           else {
               last->next = node;
               last = node;
           }
       }
       return(ret);
   }
   
   /**
    * xmlGetPropValueString:
    * @doc:  the document
    * @prop:  the attribute
    * @inLine:  should we replace entity contents or show their external form
    *
    * Returns the string equivalent for an attribute value.
    * return values: a pointer to the string copy.
    */
   CHAR *xmlGetPropValueString(xmlDocPtr doc, xmlAttrPtr prop, int inLine) {
       xmlNodePtr node;
       CHAR *ret = NULL;
       xmlEntityPtr ent;
   
       if (prop == NULL) return(NULL);
   
       node = prop->val;
       while (node != NULL) {
           if (node->type == XML_TEXT_NODE) {
               if (inLine)
                   ret = xmlStrcat(ret, node->content);
               else
                   ret = xmlStrcat(ret, xmlEncodeEntities(doc, node->content));
           } else if (node->type == XML_ENTITY_REF_NODE) {
               if (inLine) {
                   ent = xmlGetDocEntity(doc, node->name);
                   if (ent != NULL)
                       ret = xmlStrcat(ret, ent->content);
                   else
                       ret = xmlStrcat(ret, node->content);
               } else {
                   CHAR buf[2];
                   buf[0] = '&'; buf[1] = 0;
                   ret = xmlStrncat(ret, buf, 1);
                   ret = xmlStrcat(ret, node->name);
                   buf[0] = ';'; buf[1] = 0;
                   ret = xmlStrncat(ret, buf, 1);
               }
           } else {
               fprintf(stderr, "xmlGetPropValueString : invalide node type %d\n",
                       node->type);
           }
           node = node->next;
       }
       return(ret);
   }
   
   /**
    * xmlNewProp:
    * @node:  the holding node
    * @name:  the name of the attribute
    * @value:  the value of the attribute
    *
    * Create a new property carried by a node.
    * return values: a pointer to the attribute
  */   */
 xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name, const CHAR *value) {  xmlAttrPtr xmlNewProp(xmlNodePtr node, const CHAR *name, const CHAR *value) {
     xmlAttrPtr cur;      xmlAttrPtr cur;
Line 311  xmlAttrPtr xmlNewProp(xmlNodePtr node, c Line 486  xmlAttrPtr xmlNewProp(xmlNodePtr node, c
         return(NULL);          return(NULL);
     }      }
   
       cur->type = XML_ATTRIBUTE_NODE;
     cur->node = node;       cur->node = node; 
     cur->name = xmlStrdup(name);      cur->name = xmlStrdup(name);
     if (value != NULL)      if (value != NULL)
         cur->value = xmlStrdup(value);          cur->val = xmlParsePropValue(node->doc, value);
     else       else 
         cur->value = NULL;          cur->val = NULL;
   #ifndef WITHOUT_CORBA
       cur->_private = NULL;
       cur->vepv = NULL;
   #endif
   
     /*      /*
      * Add it at the end to preserve parsing order ...       * Add it at the end to preserve parsing order ...
Line 335  xmlAttrPtr xmlNewProp(xmlNodePtr node, c Line 515  xmlAttrPtr xmlNewProp(xmlNodePtr node, c
     return(cur);      return(cur);
 }  }
   
 /*  /**
  * Freeing a property list : Free a property and all its siblings,   * xmlNewDocProp:
  *                       this is a recursive behaviour, all the childs   * @doc:  the document
  *                       are freed too.   * @name:  the name of the attribute
    * @value:  the value of the attribute
    *
    * Create a new property carried by a document.
    * return values: a pointer to the attribute
    */
   xmlAttrPtr xmlNewDocProp(xmlDocPtr doc, const CHAR *name, const CHAR *value) {
       xmlAttrPtr cur;
   
       if (name == NULL) {
           fprintf(stderr, "xmlNewProp : name == NULL\n");
           return(NULL);
       }
   
       /*
        * Allocate a new property and fill the fields.
        */
       cur = (xmlAttrPtr) malloc(sizeof(xmlAttr));
       if (cur == NULL) {
           fprintf(stderr, "xmlNewProp : malloc failed\n");
           return(NULL);
       }
   
       cur->type = XML_ATTRIBUTE_NODE;
       cur->node = NULL; 
       cur->name = xmlStrdup(name);
       if (value != NULL)
           cur->val = xmlParsePropValue(doc, value);
       else 
           cur->val = NULL;
   #ifndef WITHOUT_CORBA
       cur->_private = NULL;
       cur->vepv = NULL;
   #endif
   
       cur->next = NULL;
       return(cur);
   }
   
   /**
    * xmlFreePropList:
    * @cur:  the first property in the list
    *
    * Free a property and all its siblings, all the childs are freed too.
  */   */
 void xmlFreePropList(xmlAttrPtr cur) {  void xmlFreePropList(xmlAttrPtr cur) {
     xmlAttrPtr next;      xmlAttrPtr next;
Line 353  void xmlFreePropList(xmlAttrPtr cur) { Line 576  void xmlFreePropList(xmlAttrPtr cur) {
     }      }
 }  }
   
 /*  /**
  * Freeing a property.   * xmlFreeProp:
    * @cur:  the first property in the list
    *
    * Free one property, all the childs are freed too.
  */   */
 void xmlFreeProp(xmlAttrPtr cur) {  void xmlFreeProp(xmlAttrPtr cur) {
     if (cur == NULL) {      if (cur == NULL) {
Line 362  void xmlFreeProp(xmlAttrPtr cur) { Line 588  void xmlFreeProp(xmlAttrPtr cur) {
         return;          return;
     }      }
     if (cur->name != NULL) free((char *) cur->name);      if (cur->name != NULL) free((char *) cur->name);
     if (cur->value != NULL) free((char *) cur->value);      if (cur->val != NULL) xmlFreeNodeList(cur->val);
     memset(cur, -1, sizeof(xmlAttr));      memset(cur, -1, sizeof(xmlAttr));
     free(cur);      free(cur);
 }  }
   
 /*  /**
  * Creation of a new node element in a given DTD.   * xmlNewNode:
  * We assume that the "name" has already being strdup'd !   * @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).
    * return values: a pointer to the new node object.
  */   */
 xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content) {  xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content) {
     xmlNodePtr cur;      xmlNodePtr cur;
Line 388  xmlNodePtr xmlNewNode(xmlNsPtr ns, const Line 619  xmlNodePtr xmlNewNode(xmlNsPtr ns, const
         return(NULL);          return(NULL);
     }      }
   
       cur->type = XML_ELEMENT_NODE;
       cur->doc = NULL;
     cur->parent = NULL;       cur->parent = NULL; 
     cur->next = NULL;       cur->next = NULL;
     cur->childs = NULL;       cur->prev = NULL;
     cur->properties = NULL;       cur->childs = NULL;
       cur->properties = NULL;
     cur->type = 0;      cur->type = 0;
     cur->name = xmlStrdup(name);      cur->name = xmlStrdup(name);
     cur->ns = ns;      cur->ns = ns;
     cur->nsDef = NULL;      cur->nsDef = NULL;
   #ifndef WITHOUT_CORBA
       cur->_private = NULL;
       cur->vepv = NULL;
   #endif
     if (content != NULL)      if (content != NULL)
         cur->content = xmlStrdup(content);          cur->content = xmlStrdup(content);
     else       else 
Line 403  xmlNodePtr xmlNewNode(xmlNsPtr ns, const Line 641  xmlNodePtr xmlNewNode(xmlNsPtr ns, const
     return(cur);      return(cur);
 }  }
   
 /*  /**
  * Creation of a new node contening text.   * xmlNewDocNode:
    * @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).
    * return values: a pointer to the new node object.
    */
   xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
                            const CHAR *name, CHAR *content) {
       xmlNodePtr cur;
   
       cur = xmlNewNode(ns, name, content);
       if (cur != NULL) cur->doc = doc;
       return(cur);
   }
   
   
   /**
    * xmlNewText:
    * @content:  the text content
    *
    * Creation of a new text node.
    * return values: a pointer to the new node object.
  */   */
 xmlNodePtr xmlNewText(const CHAR *content) {  xmlNodePtr xmlNewText(const CHAR *content) {
     xmlNodePtr cur;      xmlNodePtr cur;
Line 418  xmlNodePtr xmlNewText(const CHAR *conten Line 681  xmlNodePtr xmlNewText(const CHAR *conten
         return(NULL);          return(NULL);
     }      }
   
       cur->type = XML_TEXT_NODE;
       cur->doc = NULL;
     cur->parent = NULL;       cur->parent = NULL; 
     cur->next = NULL;       cur->next = NULL; 
       cur->prev = NULL; 
     cur->childs = NULL;       cur->childs = NULL; 
     cur->properties = NULL;       cur->properties = NULL; 
     cur->type = XML_TYPE_TEXT;      cur->type = XML_TEXT_NODE;
     cur->name = xmlStrdup(xmlStringText);      cur->name = xmlStrdup(xmlStringText);
     cur->ns = NULL;      cur->ns = NULL;
     cur->nsDef = NULL;      cur->nsDef = NULL;
Line 433  xmlNodePtr xmlNewText(const CHAR *conten Line 699  xmlNodePtr xmlNewText(const CHAR *conten
     return(cur);      return(cur);
 }  }
   
 /*  /**
  * Creation of a new node contening text.   * xmlNewReference:
    * @doc: the document
    * @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.
    */
   xmlNodePtr xmlNewReference(xmlDocPtr doc, const CHAR *name) {
       xmlNodePtr cur;
       xmlEntityPtr ent;
   
       /*
        * Allocate a new node and fill the fields.
        */
       cur = (xmlNodePtr) malloc(sizeof(xmlNode));
       if (cur == NULL) {
           fprintf(stderr, "xmlNewText : malloc failed\n");
           return(NULL);
       }
   
       cur->type = XML_ENTITY_REF_NODE;
       cur->doc = NULL;
       cur->parent = NULL; 
       cur->next = NULL; 
       cur->prev = NULL; 
       cur->childs = NULL; 
       cur->properties = NULL; 
       if (name[0] == '&') {
           int len;
           name++;
           len = xmlStrlen(name);
           if (name[len - 1] == ';')
               cur->name = xmlStrndup(name, len - 1);
           else
               cur->name = xmlStrndup(name, len);
       } else
           cur->name = xmlStrdup(name);
       cur->ns = NULL;
       cur->nsDef = NULL;
   
       ent = xmlGetDocEntity(doc, cur->name);
       if (ent != NULL)
           cur->content = ent->content;
       else
           cur->content = NULL;
       return(cur);
   }
   
   /**
    * xmlNewDocText:
    * @doc: the document
    * @content:  the text content
    *
    * Creation of a new text node within a document.
    * return values: a pointer to the new node object.
    */
   xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content) {
       xmlNodePtr cur;
   
       cur = xmlNewText(content);
       if (cur != NULL) cur->doc = doc;
       return(cur);
   }
   
   /**
    * xmlNewTextLen:
    * @content:  the text content
    * @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.
  */   */
 xmlNodePtr xmlNewTextLen(const CHAR *content, int len) {  xmlNodePtr xmlNewTextLen(const CHAR *content, int len) {
     xmlNodePtr cur;      xmlNodePtr cur;
Line 448  xmlNodePtr xmlNewTextLen(const CHAR *con Line 784  xmlNodePtr xmlNewTextLen(const CHAR *con
         return(NULL);          return(NULL);
     }      }
   
       cur->type = XML_TEXT_NODE;
       cur->doc = NULL; 
     cur->parent = NULL;       cur->parent = NULL; 
       cur->prev = NULL; 
     cur->next = NULL;       cur->next = NULL; 
     cur->childs = NULL;       cur->childs = NULL; 
     cur->properties = NULL;       cur->properties = NULL; 
     cur->type = XML_TYPE_TEXT;      cur->type = XML_TEXT_NODE;
     cur->name = xmlStrdup(xmlStringText);      cur->name = xmlStrdup(xmlStringText);
     cur->ns = NULL;      cur->ns = NULL;
     cur->nsDef = NULL;      cur->nsDef = NULL;
Line 463  xmlNodePtr xmlNewTextLen(const CHAR *con Line 802  xmlNodePtr xmlNewTextLen(const CHAR *con
     return(cur);      return(cur);
 }  }
   
 /*  /**
  * Creation of a new node contening a comment.   * xmlNewDocTextLen:
    * @doc: the document
    * @content:  the text content
    * @len:  the text len.
    *
    * 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.
    */
   xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len) {
       xmlNodePtr cur;
   
       cur = xmlNewTextLen(content, len);
       if (cur != NULL) cur->doc = doc;
       return(cur);
   }
   
   /**
    * xmlNewComment:
    * @content:  the comment content
    *
    * Creation of a new node containing a comment.
    * return values: a pointer to the new node object.
  */   */
 xmlNodePtr xmlNewComment(CHAR *content) {  xmlNodePtr xmlNewComment(CHAR *content) {
     xmlNodePtr cur;      xmlNodePtr cur;
Line 478  xmlNodePtr xmlNewComment(CHAR *content) Line 839  xmlNodePtr xmlNewComment(CHAR *content)
         return(NULL);          return(NULL);
     }      }
   
       cur->type = XML_COMMENT_NODE;
       cur->doc = NULL; 
     cur->parent = NULL;       cur->parent = NULL; 
       cur->prev = NULL; 
     cur->next = NULL;       cur->next = NULL; 
     cur->childs = NULL;       cur->childs = NULL; 
     cur->properties = NULL;       cur->properties = NULL; 
     cur->type = XML_TYPE_COMMENT;      cur->type = XML_COMMENT_NODE;
     cur->name = xmlStrdup(xmlStringText);      cur->name = xmlStrdup(xmlStringText);
     cur->ns = NULL;      cur->ns = NULL;
     cur->nsDef = NULL;      cur->nsDef = NULL;
Line 493  xmlNodePtr xmlNewComment(CHAR *content) Line 857  xmlNodePtr xmlNewComment(CHAR *content)
     return(cur);      return(cur);
 }  }
   
 /*  /**
  * Creation of a new child element, added at the end.   * xmlNewComment:
    * @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.
    */
   xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content) {
       xmlNodePtr cur;
   
       cur = xmlNewComment(content);
       if (cur != NULL) cur->doc = doc;
       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.
    *
    * 
    * Creation of a new child element, added at the end of @parent childs list.
    * @ns and @content parameters are optionnal (NULL).
    * return values: a pointer to the new node object.
  */   */
 xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,  xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
                        const CHAR *name, CHAR *content) {                         const CHAR *name, CHAR *content) {
Line 522  xmlNodePtr xmlNewChild(xmlNodePtr parent Line 911  xmlNodePtr xmlNewChild(xmlNodePtr parent
     /*      /*
      * add the new element at the end of the childs list.       * add the new element at the end of the childs list.
      */       */
       if (content == NULL)
           cur->type = XML_ELEMENT_NODE;
       else
           cur->type = XML_TEXT_NODE;
     cur->parent = parent;      cur->parent = parent;
       cur->doc = parent->doc;
     if (parent->childs == NULL) {      if (parent->childs == NULL) {
         parent->childs = cur;          parent->childs = cur;
     } else {      } else {
         prev = parent->childs;          prev = parent->childs;
         while (prev->next != NULL) prev = prev->next;          while (prev->next != NULL) prev = prev->next;
         prev->next = cur;          prev->next = cur;
           cur->prev = prev;
     }      }
   
     return(cur);      return(cur);
 }  }
   
 /*  /**
  * Add a new child element, added at the end.   * xmlAddChild:
    * @parent:  the parent node
    * @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.
  */   */
 xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) {  xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) {
     xmlNodePtr prev;      xmlNodePtr prev;
Line 550  xmlNodePtr xmlAddChild(xmlNodePtr parent Line 950  xmlNodePtr xmlAddChild(xmlNodePtr parent
         return(NULL);          return(NULL);
     }      }
   
       if ((cur->doc != NULL) && (parent->doc != NULL) &&
           (cur->doc != parent->doc)) {
           fprintf(stderr, "Elements moved to a different document\n");
       }
   
     /*      /*
      * add the new element at the end of the childs list.       * add the new element at the end of the childs list.
      */       */
     cur->parent = parent;      cur->parent = parent;
       cur->doc = parent->doc; /* the parent may not be linked to a doc ! */
     if (parent->childs == NULL) {      if (parent->childs == NULL) {
         parent->childs = cur;          parent->childs = cur;
     } else {      } else {
         prev = parent->childs;          prev = parent->childs;
         while (prev->next != NULL) prev = prev->next;          while (prev->next != NULL) prev = prev->next;
         prev->next = cur;          prev->next = cur;
           cur->prev = prev;
     }      }
   
     return(cur);      return(cur);
 }  }
   
 /*  /**
  * Search the last child, if any.   * xmlGetLastChild:
    * @parent:  the parent node
    *
    * Search the last child of a node.
    * return values: the last child or NULL if none.
  */   */
 xmlNodePtr xmlGetLastChild(xmlNodePtr parent) {  xmlNodePtr xmlGetLastChild(xmlNodePtr parent) {
     xmlNodePtr last;      xmlNodePtr last;
Line 588  xmlNodePtr xmlGetLastChild(xmlNodePtr pa Line 999  xmlNodePtr xmlGetLastChild(xmlNodePtr pa
     return(last);      return(last);
 }  }
   
 /*  /**
  * Freeing a node list : Free a node and all its siblings,   * xmlFreeNodeList:
  *                       this is a recursive behaviour, all the childs   * @cur:  the first node in the list
  *                       are freed too.   *
    * Free a node and all its siblings, this is a recursive behaviour, all
    * the childs are freed too.
  */   */
 void xmlFreeNodeList(xmlNodePtr cur) {  void xmlFreeNodeList(xmlNodePtr cur) {
     xmlNodePtr next;      xmlNodePtr next;
Line 606  void xmlFreeNodeList(xmlNodePtr cur) { Line 1019  void xmlFreeNodeList(xmlNodePtr cur) {
     }      }
 }  }
   
 /*  /**
  * Freeing a node : this is a recursive behaviour, all the childs   * xmlFreeNode:
  *                  are freed too.   * @cur:  the node
    *
    * Free a node, this is a recursive behaviour, all the childs are freed too.
  */   */
 void xmlFreeNode(xmlNodePtr cur) {  void xmlFreeNode(xmlNodePtr cur) {
     if (cur == NULL) {      if (cur == NULL) {
         fprintf(stderr, "xmlFreeNode : node == NULL\n");          fprintf(stderr, "xmlFreeNode : node == NULL\n");
         return;          return;
     }      }
     if (cur->properties != NULL) xmlFreePropList(cur->properties);      cur->doc = NULL;
       cur->parent = NULL;
       cur->next = NULL;
       cur->prev = NULL;
     if (cur->childs != NULL) xmlFreeNodeList(cur->childs);      if (cur->childs != NULL) xmlFreeNodeList(cur->childs);
     if (cur->content != NULL) free(cur->content);      if (cur->properties != NULL) xmlFreePropList(cur->properties);
       if (cur->type != XML_ENTITY_REF_NODE)
           if (cur->content != NULL) free(cur->content);
     if (cur->name != NULL) free((char *) cur->name);      if (cur->name != NULL) free((char *) cur->name);
     if (cur->nsDef != NULL) xmlFreeNsList(cur->nsDef);      if (cur->nsDef != NULL) xmlFreeNsList(cur->nsDef);
     memset(cur, -1, sizeof(xmlNode));      memset(cur, -1, sizeof(xmlNode));
Line 630  void xmlFreeNode(xmlNodePtr cur) { Line 1050  void xmlFreeNode(xmlNodePtr cur) {
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
     
 /*  /**
  * Changing the content of a node.   * xmlNodeSetContent:
    * @cur:  the node being modified
    * @content:  the new value of the content
    *
    * Replace the content of a node.
  */   */
 void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content) {  void xmlNodeSetContent(xmlNodePtr cur, const CHAR *content) {
     if (cur == NULL) {      if (cur == NULL) {
Line 645  void xmlNodeSetContent(xmlNodePtr cur, c Line 1069  void xmlNodeSetContent(xmlNodePtr cur, c
         cur->content = NULL;          cur->content = NULL;
 }  }
   
 /*  /**
  * Changing the content of a node.   * xmlNodeSetContentLen:
    * @cur:  the node being modified
    * @content:  the new value of the content
    * @len:  the size of @content
    *
    * Replace the content of a node.
  */   */
 void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len) {  void xmlNodeSetContentLen(xmlNodePtr cur, const CHAR *content, int len) {
     if (cur == NULL) {      if (cur == NULL) {
Line 660  void xmlNodeSetContentLen(xmlNodePtr cur Line 1089  void xmlNodeSetContentLen(xmlNodePtr cur
         cur->content = NULL;          cur->content = NULL;
 }  }
   
 /*  /**
  * Adding content to a node.   * xmlNodeAddContent:
    * @cur:  the node being modified
    * @content:  extra content
    * 
    * Append the extra substring to the node content.
  */   */
 void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content) {  void xmlNodeAddContent(xmlNodePtr cur, const CHAR *content) {
     if (cur == NULL) {      if (cur == NULL) {
Line 671  void xmlNodeAddContent(xmlNodePtr cur, c Line 1104  void xmlNodeAddContent(xmlNodePtr cur, c
     cur->content = xmlStrcat(cur->content, content);      cur->content = xmlStrcat(cur->content, content);
 }  }
   
 /*  /**
  * Adding content to a node.   * xmlNodeAddContentLen:
    * @cur:  the node being modified
    * @content:  extra content
    * @len:  the size of @content
    * 
    * Append the extra substring to the node content.
  */   */
 void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len) {  void xmlNodeAddContentLen(xmlNodePtr cur, const CHAR *content, int len) {
     if (cur == NULL) {      if (cur == NULL) {
Line 682  void xmlNodeAddContentLen(xmlNodePtr cur Line 1120  void xmlNodeAddContentLen(xmlNodePtr cur
     cur->content = xmlStrncat(cur->content, content, len);      cur->content = xmlStrncat(cur->content, content, len);
 }  }
   
 /*  /**
  * Search a Ns registered under a given name space for a document.   * xmlSearchNs:
  *      recurse on the parents until it finds the defined namespace   * @doc:  the document
  *      or return NULL otherwise.   * @node:  the current node
    * @nameSpace:  the namespace string
  *   *
  * Note : nameSpace == NULL is valid, this is a search for the default   * Search a Ns registered under a given name space for a document.
  *        namespace.   * 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.
  */   */
 xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const CHAR *nameSpace) {  xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const CHAR *nameSpace) {
     xmlNsPtr cur;      xmlNsPtr cur;
Line 717  xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlN Line 1159  xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlN
     return(NULL);      return(NULL);
 }  }
   
 /*  /**
  * Search a Ns aliasing a given URI   * xmlSearchNsByHref:
  *      recurse on the parents until it finds the defined namespace   * @doc:  the document
  *      or return NULL otherwise.   * @node:  the current node
    * @href:  the namespace value
    *
    * 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.
  */   */
 xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const CHAR *href) {  xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const CHAR *href) {
     xmlNsPtr cur;      xmlNsPtr cur;
Line 747  xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc Line 1194  xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc
     return(NULL);      return(NULL);
 }  }
   
 /*  /**
  * Reading the content of a given property.   * xmlGetProp:
    * @node:  the node
    * @name:  the attribute name
    *
    * 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.
  */   */
 const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name) {  const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name) {
     xmlAttrPtr prop = node->properties;      xmlAttrPtr prop = node->properties;
   
     while (prop != NULL) {      while (prop != NULL) {
         if (!xmlStrcmp(prop->name, name)) return(prop->value);          if (!xmlStrcmp(prop->name, name)) 
               return(xmlGetPropValueString(node->doc, prop, 1));
         prop = prop->next;          prop = prop->next;
     }      }
     return(NULL);      return(NULL);
 }  }
   
 /*  /**
  * Setting the content of a given property.   * xmlSetProp:
    * @node:  the node
    * @name:  the attribute name
    * @value:  the attribute value
    *
    * Set (or reset) an attribute carried by a node.
    * return values: the attribute pointer.
  */   */
 xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name, const CHAR *value) {  xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name, const CHAR *value) {
     xmlAttrPtr prop = node->properties;      xmlAttrPtr prop = node->properties;
   
     while (prop != NULL) {      while (prop != NULL) {
         if (!xmlStrcmp(prop->name, name)) {          if (!xmlStrcmp(prop->name, name)) {
             if (prop->value != NULL)               if (prop->val != NULL) 
                 free((char *) prop->value);                  xmlFreeNode(prop->val);
             prop->value = NULL;              prop->val = NULL;
             if (value != NULL)              if (value != NULL)
                 prop->value = xmlStrdup(value);                  prop->val = xmlParsePropValue(node->doc, value);
             return(prop);              return(prop);
         }          }
         prop = prop->next;          prop = prop->next;
Line 781  xmlAttrPtr xmlSetProp(xmlNodePtr node, c Line 1241  xmlAttrPtr xmlSetProp(xmlNodePtr node, c
     return(prop);      return(prop);
 }  }
   
 /*  /**
  * Is this node a piece of text   * xmlNodeIsText:
    * @node:  the node
    * 
    * Is this node a Text node ?
    * return values: 1 yes, 0 no
  */   */
 int xmlNodeIsText(xmlNodePtr node) {  int xmlNodeIsText(xmlNodePtr node) {
     if (node == NULL) return(0);      if (node == NULL) return(0);
   
     if (node->type == XML_TYPE_TEXT) return(1);      if (node->type == XML_TEXT_NODE) return(1);
     return(0);      return(0);
 }  }
   
 /*  /**
  * Concat a piece of text to an existing text node   * xmlNodeIsText:
  *   * @node:  the node
  * TODO !!! Should be optimized with a bit of preallocation.   * @content:  the content
    * @len:  @content lenght
    * 
    * Concat the given string at the end of the existing node content
  */   */
   
 void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len) {  void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len) {
     if (node == NULL) return;      if (node == NULL) return;
   
     if (node->type != XML_TYPE_TEXT) {      if (node->type != XML_TEXT_NODE) {
         fprintf(stderr, "xmlTextConcat: node is not text\n");          fprintf(stderr, "xmlTextConcat: node is not text\n");
         return;          return;
     }      }
Line 812  void xmlTextConcat(xmlNodePtr node, cons Line 1280  void xmlTextConcat(xmlNodePtr node, cons
  *                                                                      *   *                                                                      *
  ************************************************************************/   ************************************************************************/
   
 /*  
  * routine which manage and grows an output buffer. One can write  
  * standard char array's (8 bits char) or CHAR's arrays.  
  */  
 static CHAR *buffer = NULL;  static CHAR *buffer = NULL;
 static int buffer_index = 0;  static int buffer_index = 0;
 static int buffer_size = 0;  static int buffer_size = 0;
   
   /**
    * xmlBufferWriteCHAR:
    * @string:  the string to add
    *
    * routine which manage and grows an output buffer. This one add
    * CHARs at the end of the array.
    */
 void xmlBufferWriteCHAR(const CHAR *string) {  void xmlBufferWriteCHAR(const CHAR *string) {
     const CHAR *cur;      const CHAR *cur;
   
Line 847  void xmlBufferWriteCHAR(const CHAR *stri Line 1318  void xmlBufferWriteCHAR(const CHAR *stri
     buffer[buffer_index] = 0;      buffer[buffer_index] = 0;
 }  }
   
   /**
    * xmlBufferWriteChar:
    * @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) {  void xmlBufferWriteChar(const char *string) {
     const char *cur;      const char *cur;
   
Line 874  void xmlBufferWriteChar(const char *stri Line 1352  void xmlBufferWriteChar(const char *stri
     buffer[buffer_index] = 0;      buffer[buffer_index] = 0;
 }  }
   
 /*  /**
  * Dump the global Namespace inherited from the old WD.   * xmlGlobalNsDump:
  * Within the context of the document header.   * @cur:  a namespace
    *
    * Dump a global Namespace, this is the old version based on PIs.
  */   */
 static void xmlGlobalNsDump(xmlNsPtr cur) {  static void xmlGlobalNsDump(xmlNsPtr cur) {
     if (cur == NULL) {      if (cur == NULL) {
Line 899  static void xmlGlobalNsDump(xmlNsPtr cur Line 1379  static void xmlGlobalNsDump(xmlNsPtr cur
     }      }
 }  }
   
 /*  /**
  * Dump an old global XML Namespace list   * xmlGlobalNsListDump:
    * @cur:  the first namespace
    *
    * Dump a list of global Namespace, this is the old version based on PIs.
  */   */
   
 static void xmlGlobalNsListDump(xmlNsPtr cur) {  static void xmlGlobalNsListDump(xmlNsPtr cur) {
     while (cur != NULL) {      while (cur != NULL) {
         xmlGlobalNsDump(cur);          xmlGlobalNsDump(cur);
Line 910  static void xmlGlobalNsListDump(xmlNsPtr Line 1392  static void xmlGlobalNsListDump(xmlNsPtr
     }      }
 }  }
   
 /*  /**
    * xmlNsDump:
    * @cur:  a namespace
    *
  * Dump a local Namespace definition.   * Dump a local Namespace definition.
  * Within the context of an element attributes.   * Should be called in the context of attributes dumps.
  */   */
 static void xmlNsDump(xmlNsPtr cur) {  static void xmlNsDump(xmlNsPtr cur) {
     if (cur == NULL) {      if (cur == NULL) {
Line 932  static void xmlNsDump(xmlNsPtr cur) { Line 1417  static void xmlNsDump(xmlNsPtr cur) {
     }      }
 }  }
   
 /*  /**
  * Dump an XML Namespace list   * xmlNsListDump:
    * @cur:  the first namespace
    *
    * Dump a list of local Namespace definitions.
    * Should be called in the context of attributes dumps.
  */   */
   
 static void xmlNsListDump(xmlNsPtr cur) {  static void xmlNsListDump(xmlNsPtr cur) {
     while (cur != NULL) {      while (cur != NULL) {
         xmlNsDump(cur);          xmlNsDump(cur);
Line 943  static void xmlNsListDump(xmlNsPtr cur) Line 1431  static void xmlNsListDump(xmlNsPtr cur)
     }      }
 }  }
   
 /*  /**
  * Dump an XML DTD   * xmlDtdDump:
    * @doc:  the document
    * 
    * Dump the XML document DTD, if any.
  */   */
   
 static void xmlDtdDump(xmlDocPtr doc) {  static void xmlDtdDump(xmlDocPtr doc) {
     xmlDtdPtr cur = doc->dtd;      xmlDtdPtr cur = doc->dtd;
   
Line 982  static void xmlDtdDump(xmlDocPtr doc) { Line 1472  static void xmlDtdDump(xmlDocPtr doc) {
     xmlBufferWriteChar(">\n");      xmlBufferWriteChar(">\n");
 }  }
   
 /*  /**
  * Dump an XML property   * xmlAttrDump:
    * @doc:  the document
    * @cur:  the attribute pointer
    *
    * Dump an XML attribute
  */   */
   
 static void xmlAttrDump(xmlDocPtr doc, xmlAttrPtr cur) {  static void xmlAttrDump(xmlDocPtr doc, xmlAttrPtr cur) {
       CHAR *value;
   
     if (cur == NULL) {      if (cur == NULL) {
         fprintf(stderr, "xmlAttrDump : property == NULL\n");          fprintf(stderr, "xmlAttrDump : property == NULL\n");
         return;          return;
     }      }
     xmlBufferWriteChar(" ");      xmlBufferWriteChar(" ");
     xmlBufferWriteCHAR(cur->name);      xmlBufferWriteCHAR(cur->name);
     if (cur->value) {      value = xmlGetPropValueString(doc, cur, 0);
       if (value) {
         xmlBufferWriteChar("=\"");          xmlBufferWriteChar("=\"");
         xmlBufferWriteCHAR(xmlEncodeEntities(doc, cur->value));          xmlBufferWriteCHAR(value);
         xmlBufferWriteChar("\"");          xmlBufferWriteChar("\"");
           free(value);
     }      }
 }  }
   
 /*  /**
  * Dump an XML property list   * xmlAttrListDump:
    * @doc:  the document
    * @cur:  the first attribute pointer
    *
    * Dump a list of XML attributes
  */   */
   
 static void xmlAttrListDump(xmlDocPtr doc, xmlAttrPtr cur) {  static void xmlAttrListDump(xmlDocPtr doc, xmlAttrPtr cur) {
     if (cur == NULL) {      if (cur == NULL) {
         fprintf(stderr, "xmlAttrListDump : property == NULL\n");          fprintf(stderr, "xmlAttrListDump : property == NULL\n");
Line 1015  static void xmlAttrListDump(xmlDocPtr do Line 1515  static void xmlAttrListDump(xmlDocPtr do
     }      }
 }  }
   
 /*  
  * Dump an XML node list  
  */  
   
 static void xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level);  static void xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level);
   /**
    * xmlNodeListDump:
    * @doc:  the document
    * @cur:  the first node
    * @level: the imbrication level for indenting
    *
    * Dump an XML node list, recursive behaviour,children are printed too.
    */
 static void xmlNodeListDump(xmlDocPtr doc, xmlNodePtr cur, int level) {  static void xmlNodeListDump(xmlDocPtr doc, xmlNodePtr cur, int level) {
     if (cur == NULL) {      if (cur == NULL) {
         fprintf(stderr, "xmlNodeListDump : node == NULL\n");          fprintf(stderr, "xmlNodeListDump : node == NULL\n");
Line 1031  static void xmlNodeListDump(xmlDocPtr do Line 1536  static void xmlNodeListDump(xmlDocPtr do
     }      }
 }  }
   
 /*  /**
  * Dump an XML node   * xmlNodeListDump:
    * @doc:  the document
    * @cur:  the current node
    * @level: the imbrication level for indenting
    *
    * Dump an XML node, recursive behaviour,children are printed too.
  */   */
   
 static void xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level) {  static void xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level) {
     int i;      int i;
   
Line 1042  static void xmlNodeDump(xmlDocPtr doc, x Line 1551  static void xmlNodeDump(xmlDocPtr doc, x
         fprintf(stderr, "xmlNodeDump : node == NULL\n");          fprintf(stderr, "xmlNodeDump : node == NULL\n");
         return;          return;
     }      }
     if (cur->type == XML_TYPE_TEXT) {      if (cur->type == XML_TEXT_NODE) {
         if (cur->content != NULL)          if (cur->content != NULL)
             xmlBufferWriteCHAR(xmlEncodeEntities(doc, cur->content));              xmlBufferWriteCHAR(xmlEncodeEntities(doc, cur->content));
         return;          return;
     }      }
     if (cur->type == XML_TYPE_COMMENT) {      if (cur->type == XML_COMMENT_NODE) {
         if (cur->content != NULL) {          if (cur->content != NULL) {
             xmlBufferWriteChar("<!--");              xmlBufferWriteChar("<!--");
             xmlBufferWriteCHAR(cur->content);              xmlBufferWriteCHAR(cur->content);
Line 1055  static void xmlNodeDump(xmlDocPtr doc, x Line 1564  static void xmlNodeDump(xmlDocPtr doc, x
         }          }
         return;          return;
     }      }
       if (cur->type == XML_ENTITY_REF_NODE) {
           xmlBufferWriteChar("&");
           xmlBufferWriteCHAR(cur->name);
           xmlBufferWriteChar(";");
           return;
       }
     if (xmlIndentTreeOutput)      if (xmlIndentTreeOutput)
         for (i = 0;i < level;i++)          for (i = 0;i < level;i++)
             xmlBufferWriteChar("  ");              xmlBufferWriteChar("  ");
Line 1095  static void xmlNodeDump(xmlDocPtr doc, x Line 1610  static void xmlNodeDump(xmlDocPtr doc, x
     xmlBufferWriteChar(">\n");      xmlBufferWriteChar(">\n");
 }  }
   
 /*  /**
  * Dump an XML document   * xmlDocContentDump:
    * @cur:  the document
    *
    * Dump an XML document.
  */   */
 static void xmlDocContentDump(xmlDocPtr cur) {  static void xmlDocContentDump(xmlDocPtr cur) {
     if (oldXMLWDcompatibility)      if (oldXMLWDcompatibility)
Line 1131  static void xmlDocContentDump(xmlDocPtr Line 1649  static void xmlDocContentDump(xmlDocPtr
     }      }
 }  }
   
 /*  /**
  * Dump an XML document to memory.   * xmlDocDumpMemory:
    * @cur:  the document
    * @mem:  OUT: the memory pointer
    * @size:  OUT: the memory lenght
    *
    * Dump an XML document in memory and return the CHAR * and it's size.
    * It's up to the caller to free the memory.
  */   */
   
 void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size) {  void xmlDocDumpMemory(xmlDocPtr cur, CHAR**mem, int *size) {
     if (cur == NULL) {      if (cur == NULL) {
         fprintf(stderr, "xmlDocDump : document == NULL\n");          fprintf(stderr, "xmlDocDump : document == NULL\n");
Line 1149  void xmlDocDumpMemory(xmlDocPtr cur, CHA Line 1672  void xmlDocDumpMemory(xmlDocPtr cur, CHA
     *size = buffer_index;      *size = buffer_index;
 }  }
   
 /*  /**
  * Dump an XML document to the given FD   * xmlGetDocCompressMode:
    * @doc:  the document
    *
    * get the compression ratio for a document, ZLIB based
    * return values: 0 (uncompressed) to 9 (max compression)
    */
   int  xmlGetDocCompressMode (xmlDocPtr doc) {
       if (doc == NULL) return(-1);
       return(doc->compression);
   }
   
   /**
    * xmlSetDocCompressMode:
    * @doc:  the document
    * @mode:  the compression ratio
    *
    * set the compression ratio for a document, ZLIB based
    * Correct values: 0 (uncompressed) to 9 (max compression)
    */
   void xmlSetDocCompressMode (xmlDocPtr doc, int mode) {
       if (doc == NULL) return;
       if (mode < 0) doc->compression = 0;
       else if (mode > 9) doc->compression = 9;
       else doc->compression = mode;
   }
   
   /**
    * xmlGetCompressMode:
    *
    * get the default compression mode used, ZLIB based.
    * return values: 0 (uncompressed) to 9 (max compression)
    */
   int  xmlGetCompressMode(void) {
       return(xmlCompressMode);
   }
   
   /**
    * xmlSetCompressMode:
    * @mode:  the compression ratio
    *
    * set the default compression mode used, ZLIB based
    * Correct values: 0 (uncompressed) to 9 (max compression)
  */   */
   void xmlSetCompressMode(int mode) {
       if (mode < 0) xmlCompressMode = 0;
       else if (mode > 9) xmlCompressMode = 9;
       else xmlCompressMode = mode;
   }
   
   /**
    * xmlDocDump:
    * @f:  the FILE*
    * @cur:  the document
    *
    * Dump an XML document to an open FILE.
    */
 void xmlDocDump(FILE *f, xmlDocPtr cur) {  void xmlDocDump(FILE *f, xmlDocPtr cur) {
     if (cur == NULL) {      if (cur == NULL) {
         fprintf(stderr, "xmlDocDump : document == NULL\n");          fprintf(stderr, "xmlDocDump : document == NULL\n");
Line 1164  void xmlDocDump(FILE *f, xmlDocPtr cur) Line 1740  void xmlDocDump(FILE *f, xmlDocPtr cur)
     fwrite(buffer, sizeof(CHAR), buffer_index, f);      fwrite(buffer, sizeof(CHAR), buffer_index, f);
 }  }
   
   /**
    * xmlSaveFile:
    * @filename:  the filename
    * @cur:  the document
    *
    * Dump an XML document to a file. Will use compression if
    * compiled in and enabled.
    * returns: the number of file written or -1 in case of failure.
    */
   int xmlSaveFile(const char *filename, xmlDocPtr cur) {
   #ifdef HAVE_ZLIB_H
       gzFile zoutput = NULL;
       char mode[15];
   #endif
       FILE *output;
       int ret;
   
   #ifdef HAVE_ZLIB_H
       if ((cur->compression > 0) && (cur->compression <= 9)) {
           sprintf(mode, "w%d", cur->compression);
           zoutput = gzopen(filename, mode);
       }
       if (zoutput == NULL) {
   #endif
           output = fopen(filename, "w");
           if (output == NULL) return(-1);
   #ifdef HAVE_ZLIB_H
       }
   #endif
   
       /* 
        * save the content to a temp buffer.
        */
       buffer_index = 0;
       xmlDocContentDump(cur);
   
   #ifdef HAVE_ZLIB_H
       if (zoutput != NULL) {
           ret = gzwrite(zoutput, buffer, sizeof(CHAR) * buffer_index);
           gzclose(zoutput);
           return(ret);
       }
   #endif
       ret = fwrite(buffer, sizeof(CHAR), buffer_index, output);
       fclose(output);
       return(ret * sizeof(CHAR));
   }
   
 /************************************************************************  /************************************************************************
  *                                                                      *   *                                                                      *
  *                              Debug                                   *   *                              Debug                                   *

Removed from v.1.22  
changed lines
  Added in v.1.23


Webmaster