1998-08-13 03:39:55 +00:00
/*
* tree . c : implemetation of access function for an XML tree .
*
* See Copyright for the status of this software .
*
1999-01-17 19:11:59 +00:00
* Daniel . Veillard @ w3 . org
1998-08-13 03:39:55 +00:00
*/
1999-09-22 09:46:25 +00:00
# ifdef WIN32
# define HAVE_FCNTL_H
# include <io.h>
# else
1998-09-23 00:49:46 +00:00
# include "config.h"
1999-09-22 09:46:25 +00:00
# endif
1998-08-13 03:39:55 +00:00
# include <stdio.h>
# include <string.h> /* for memset() only ! */
1999-09-22 09:46:25 +00:00
# ifdef HAVE_CTYPE_H
# include <ctype.h>
# endif
# ifdef HAVE_STDLIB_H
# include <stdlib.h>
# endif
1998-09-23 00:49:46 +00:00
# ifdef HAVE_ZLIB_H
# include <zlib.h>
# endif
1999-09-02 22:04:43 +00:00
# include "xmlmemory.h"
1998-08-13 03:39:55 +00:00
# include "tree.h"
# include "entities.h"
1999-01-31 22:15:06 +00:00
# include "valid.h"
1998-08-13 03:39:55 +00:00
1999-09-23 22:19:22 +00:00
static xmlChar xmlStringText [ ] = { ' t ' , ' e ' , ' x ' , ' t ' , 0 } ;
1998-08-13 03:39:55 +00:00
int oldXMLWDcompatibility = 0 ;
int xmlIndentTreeOutput = 1 ;
1999-12-01 09:51:45 +00:00
xmlBufferAllocationScheme xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT ;
1998-08-13 03:39:55 +00:00
1998-09-24 19:15:06 +00:00
static int xmlCompressMode = 0 ;
1999-12-12 13:03:50 +00:00
static int xmlCheckDTD = 1 ;
1998-09-24 19:15:06 +00:00
1999-01-17 19:11:59 +00:00
# define UPDATE_LAST_CHILD(n) if ((n) != NULL) { \
xmlNodePtr ulccur = ( n ) - > childs ; \
if ( ulccur = = NULL ) { \
( n ) - > last = NULL ; \
} else { \
while ( ulccur - > next ! = NULL ) ulccur = ulccur - > next ; \
( n ) - > last = ulccur ; \
1999-02-22 10:33:01 +00:00
} }
1999-01-17 19:11:59 +00:00
1998-08-13 03:39:55 +00:00
/************************************************************************
* *
* Allocation and deallocation of basic structures *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-01 09:51:45 +00:00
/**
* xmlSetBufferAllocationScheme :
* @ scheme : allocation method to use
*
* Set the buffer allocation method . Types are
* XML_BUFFER_ALLOC_EXACT - use exact sizes , keeps memory usage down
* XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed ,
* improves performance
*/
void
xmlSetBufferAllocationScheme ( xmlBufferAllocationScheme scheme ) {
xmlBufferAllocScheme = scheme ;
}
/**
* xmlGetBufferAllocationScheme :
*
* Types are
* XML_BUFFER_ALLOC_EXACT - use exact sizes , keeps memory usage down
* XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed ,
* improves performance
*
* Returns the current allocation scheme
*/
xmlBufferAllocationScheme
xmlGetBufferAllocationScheme ( ) {
return xmlBufferAllocScheme ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlUpgradeOldNs :
* @ doc : a document pointer
*
* Upgrade old style Namespaces ( PI ) and move them to the root of the document .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
xmlUpgradeOldNs ( xmlDocPtr doc ) {
1998-08-13 03:39:55 +00:00
xmlNsPtr cur ;
if ( ( doc = = NULL ) | | ( doc - > oldNs = = NULL ) ) return ;
if ( doc - > root = = NULL ) {
fprintf ( stderr , " xmlUpgradeOldNs: failed no root ! \n " ) ;
return ;
}
cur = doc - > oldNs ;
while ( cur - > next ! = NULL ) {
cur - > type = XML_LOCAL_NAMESPACE ;
cur = cur - > next ;
}
cur - > type = XML_LOCAL_NAMESPACE ;
cur - > next = doc - > root - > nsDef ;
doc - > root - > nsDef = doc - > oldNs ;
doc - > oldNs = NULL ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlNewNs :
* @ node : the element carrying the namespace
* @ href : the URI associated
* @ prefix : the prefix for the namespace
*
1998-08-13 03:39:55 +00:00
* Creation of a new Namespace .
1999-02-22 10:33:01 +00:00
* Returns returns a new namespace pointer
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNsPtr
1999-09-23 22:19:22 +00:00
xmlNewNs ( xmlNodePtr node , const xmlChar * href , const xmlChar * prefix ) {
1998-08-13 03:39:55 +00:00
xmlNsPtr cur ;
if ( href = = NULL ) {
fprintf ( stderr , " xmlNewNs: href == NULL ! \n " ) ;
return ( NULL ) ;
}
/*
* Allocate a new DTD and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlNsPtr ) xmlMalloc ( sizeof ( xmlNs ) ) ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewNs : malloc failed \n " ) ;
return ( NULL ) ;
}
cur - > type = XML_LOCAL_NAMESPACE ;
if ( href ! = NULL )
cur - > href = xmlStrdup ( href ) ;
else
cur - > href = NULL ;
if ( prefix ! = NULL )
cur - > prefix = xmlStrdup ( prefix ) ;
else
cur - > prefix = NULL ;
/*
* Add it at the end to preserve parsing order . . .
*/
cur - > next = NULL ;
if ( node ! = NULL ) {
if ( node - > nsDef = = NULL ) {
node - > nsDef = cur ;
} else {
xmlNsPtr prev = node - > nsDef ;
while ( prev - > next ! = NULL ) prev = prev - > next ;
prev - > next = cur ;
}
}
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
* 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 .
1999-02-22 10:33:01 +00:00
* Returns returns a new namespace pointer
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNsPtr
1999-09-23 22:19:22 +00:00
xmlNewGlobalNs ( xmlDocPtr doc , const xmlChar * href , const xmlChar * prefix ) {
1998-08-13 03:39:55 +00:00
xmlNsPtr cur ;
/*
* Allocate a new DTD and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlNsPtr ) xmlMalloc ( sizeof ( xmlNs ) ) ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
1998-11-27 06:39:50 +00:00
fprintf ( stderr , " xmlNewGlobalNs : malloc failed \n " ) ;
1998-08-13 03:39:55 +00:00
return ( NULL ) ;
}
cur - > type = XML_GLOBAL_NAMESPACE ;
if ( href ! = NULL )
cur - > href = xmlStrdup ( href ) ;
else
cur - > href = NULL ;
if ( prefix ! = NULL )
cur - > prefix = xmlStrdup ( prefix ) ;
else
cur - > prefix = NULL ;
/*
* Add it at the end to preserve parsing order . . .
*/
cur - > next = NULL ;
if ( doc ! = NULL ) {
if ( doc - > oldNs = = NULL ) {
doc - > oldNs = cur ;
} else {
xmlNsPtr prev = doc - > oldNs ;
while ( prev - > next ! = NULL ) prev = prev - > next ;
prev - > next = cur ;
}
}
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlSetNs :
* @ node : a node in the document
* @ ns : a namespace pointer
*
* Associate a namespace to a node , a posteriori .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
xmlSetNs ( xmlNodePtr node , xmlNsPtr ns ) {
1998-08-13 03:39:55 +00:00
if ( node = = NULL ) {
fprintf ( stderr , " xmlSetNs: node == NULL \n " ) ;
return ;
}
node - > ns = ns ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlFreeNs :
* @ cur : the namespace pointer
*
* Free up the structures associated to a namespace
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
xmlFreeNs ( xmlNsPtr cur ) {
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlFreeNs : ns == NULL \n " ) ;
return ;
}
1999-09-02 22:04:43 +00:00
if ( cur - > href ! = NULL ) xmlFree ( ( char * ) cur - > href ) ;
if ( cur - > prefix ! = NULL ) xmlFree ( ( char * ) cur - > prefix ) ;
1998-08-13 03:39:55 +00:00
memset ( cur , - 1 , sizeof ( xmlNs ) ) ;
1999-09-02 22:04:43 +00:00
xmlFree ( cur ) ;
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
/**
* xmlFreeNsList :
* @ cur : the first namespace pointer
*
* Free up all the structures associated to the chained namespaces .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
xmlFreeNsList ( xmlNsPtr cur ) {
1998-08-13 03:39:55 +00:00
xmlNsPtr next ;
if ( cur = = NULL ) {
fprintf ( stderr , " xmlFreeNsList : ns == NULL \n " ) ;
return ;
}
while ( cur ! = NULL ) {
next = cur - > next ;
xmlFreeNs ( cur ) ;
cur = next ;
}
}
1998-10-20 06:14:16 +00:00
/**
* xmlNewDtd :
* @ doc : the document pointer
* @ name : the DTD name
* @ ExternalID : the external ID
* @ SystemID : the system ID
*
1998-08-13 03:39:55 +00:00
* Creation of a new DTD .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the new DTD structure
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlDtdPtr
1999-09-23 22:19:22 +00:00
xmlNewDtd ( xmlDocPtr doc , const xmlChar * name ,
const xmlChar * ExternalID , const xmlChar * SystemID ) {
1998-08-13 03:39:55 +00:00
xmlDtdPtr cur ;
1999-01-17 19:11:59 +00:00
if ( ( doc ! = NULL ) & & ( doc - > extSubset ! = NULL ) ) {
1998-08-13 03:39:55 +00:00
fprintf ( stderr , " xmlNewDtd(%s): document %s already have a DTD %s \n " ,
1999-01-17 19:11:59 +00:00
/* !!! */ ( char * ) name , doc - > name ,
/* !!! */ ( char * ) doc - > extSubset - > name ) ;
}
/*
* Allocate a new DTD and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlDtdPtr ) xmlMalloc ( sizeof ( xmlDtd ) ) ;
1999-01-17 19:11:59 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewDtd : malloc failed \n " ) ;
return ( NULL ) ;
}
if ( name ! = NULL )
cur - > name = xmlStrdup ( name ) ;
else
cur - > name = NULL ;
if ( ExternalID ! = NULL )
cur - > ExternalID = xmlStrdup ( ExternalID ) ;
else
cur - > ExternalID = NULL ;
if ( SystemID ! = NULL )
cur - > SystemID = xmlStrdup ( SystemID ) ;
else
cur - > SystemID = NULL ;
1999-02-22 10:33:01 +00:00
cur - > notations = NULL ;
1999-01-17 19:11:59 +00:00
cur - > elements = NULL ;
1999-02-22 10:33:01 +00:00
cur - > attributes = NULL ;
1999-01-17 19:11:59 +00:00
cur - > entities = NULL ;
if ( doc ! = NULL )
doc - > extSubset = cur ;
return ( cur ) ;
}
/**
* xmlCreateIntSubset :
* @ doc : the document pointer
* @ name : the DTD name
* @ ExternalID : the external ID
* @ SystemID : the system ID
*
1999-02-22 10:33:01 +00:00
* Create the internal subset of a document
* Returns a pointer to the new DTD structure
1999-01-17 19:11:59 +00:00
*/
xmlDtdPtr
1999-09-23 22:19:22 +00:00
xmlCreateIntSubset ( xmlDocPtr doc , const xmlChar * name ,
const xmlChar * ExternalID , const xmlChar * SystemID ) {
1999-01-17 19:11:59 +00:00
xmlDtdPtr cur ;
if ( ( doc ! = NULL ) & & ( doc - > intSubset ! = NULL ) ) {
fprintf ( stderr ,
" xmlCreateIntSubset(): document %s already have an internal subset \n " ,
doc - > name ) ;
return ( NULL ) ;
1998-08-13 03:39:55 +00:00
}
/*
* Allocate a new DTD and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlDtdPtr ) xmlMalloc ( sizeof ( xmlDtd ) ) ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
1998-11-27 06:39:50 +00:00
fprintf ( stderr , " xmlNewDtd : malloc failed \n " ) ;
1998-08-13 03:39:55 +00:00
return ( NULL ) ;
}
if ( name ! = NULL )
cur - > name = xmlStrdup ( name ) ;
else
cur - > name = NULL ;
if ( ExternalID ! = NULL )
cur - > ExternalID = xmlStrdup ( ExternalID ) ;
else
cur - > ExternalID = NULL ;
if ( SystemID ! = NULL )
cur - > SystemID = xmlStrdup ( SystemID ) ;
else
cur - > SystemID = NULL ;
1999-02-22 10:33:01 +00:00
cur - > notations = NULL ;
1998-08-13 03:39:55 +00:00
cur - > elements = NULL ;
1999-02-22 10:33:01 +00:00
cur - > attributes = NULL ;
1998-08-13 03:39:55 +00:00
cur - > entities = NULL ;
1998-11-27 06:39:50 +00:00
if ( doc ! = NULL )
1999-01-17 19:11:59 +00:00
doc - > intSubset = cur ;
1998-08-13 03:39:55 +00:00
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlFreeDtd :
* @ cur : the DTD structure to free up
*
* Free a DTD structure .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
xmlFreeDtd ( xmlDtdPtr cur ) {
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlFreeDtd : DTD == NULL \n " ) ;
return ;
}
1999-09-02 22:04:43 +00:00
if ( cur - > name ! = NULL ) xmlFree ( ( char * ) cur - > name ) ;
if ( cur - > SystemID ! = NULL ) xmlFree ( ( char * ) cur - > SystemID ) ;
if ( cur - > ExternalID ! = NULL ) xmlFree ( ( char * ) cur - > ExternalID ) ;
1999-02-22 10:33:01 +00:00
if ( cur - > notations ! = NULL )
xmlFreeNotationTable ( ( xmlNotationTablePtr ) cur - > notations ) ;
1998-08-13 03:39:55 +00:00
if ( cur - > elements ! = NULL )
1999-01-31 22:15:06 +00:00
xmlFreeElementTable ( ( xmlElementTablePtr ) cur - > elements ) ;
1999-02-22 10:33:01 +00:00
if ( cur - > attributes ! = NULL )
xmlFreeAttributeTable ( ( xmlAttributeTablePtr ) cur - > attributes ) ;
1998-08-13 03:39:55 +00:00
if ( cur - > entities ! = NULL )
xmlFreeEntitiesTable ( ( xmlEntitiesTablePtr ) cur - > entities ) ;
memset ( cur , - 1 , sizeof ( xmlDtd ) ) ;
1999-09-02 22:04:43 +00:00
xmlFree ( cur ) ;
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
/**
* xmlNewDoc :
1999-09-23 22:19:22 +00:00
* @ version : xmlChar string giving the version of XML " 1.0 "
1998-10-20 06:14:16 +00:00
*
1999-02-22 10:33:01 +00:00
* Returns a new document
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlDocPtr
1999-09-23 22:19:22 +00:00
xmlNewDoc ( const xmlChar * version ) {
1998-08-13 03:39:55 +00:00
xmlDocPtr cur ;
if ( version = = NULL ) {
fprintf ( stderr , " xmlNewDoc : version == NULL \n " ) ;
return ( NULL ) ;
}
/*
* Allocate a new document and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlDocPtr ) xmlMalloc ( sizeof ( xmlDoc ) ) ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewDoc : malloc failed \n " ) ;
return ( NULL ) ;
}
1998-10-18 19:12:41 +00:00
cur - > type = XML_DOCUMENT_NODE ;
1998-08-13 03:39:55 +00:00
cur - > version = xmlStrdup ( version ) ;
cur - > name = NULL ;
cur - > root = NULL ;
1999-01-17 19:11:59 +00:00
cur - > intSubset = NULL ;
cur - > extSubset = NULL ;
1998-08-13 03:39:55 +00:00
cur - > oldNs = NULL ;
cur - > encoding = NULL ;
cur - > standalone = - 1 ;
1999-11-23 10:40:46 +00:00
cur - > compression = - 1 ; /* not initialized */
1999-08-29 21:02:19 +00:00
cur - > ids = NULL ;
1999-09-08 21:35:25 +00:00
cur - > refs = NULL ;
1999-05-29 11:51:49 +00:00
# ifndef XML_WITHOUT_CORBA
1998-10-17 06:47:46 +00:00
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
1998-08-13 03:39:55 +00:00
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlFreeDoc :
* @ cur : pointer to the document
* @ :
*
* Free up all the structures used by a document , tree included .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
xmlFreeDoc ( xmlDocPtr cur ) {
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
1999-01-17 19:11:59 +00:00
# ifdef DEBUG_TREE
1998-08-13 03:39:55 +00:00
fprintf ( stderr , " xmlFreeDoc : document == NULL \n " ) ;
1999-01-17 19:11:59 +00:00
# endif
1998-08-13 03:39:55 +00:00
return ;
}
1999-09-02 22:04:43 +00:00
if ( cur - > version ! = NULL ) xmlFree ( ( char * ) cur - > version ) ;
if ( cur - > name ! = NULL ) xmlFree ( ( char * ) cur - > name ) ;
if ( cur - > encoding ! = NULL ) xmlFree ( ( char * ) cur - > encoding ) ;
if ( cur - > root ! = NULL ) xmlFreeNodeList ( cur - > root ) ;
1999-01-17 19:11:59 +00:00
if ( cur - > intSubset ! = NULL ) xmlFreeDtd ( cur - > intSubset ) ;
if ( cur - > extSubset ! = NULL ) xmlFreeDtd ( cur - > extSubset ) ;
1998-11-27 06:39:50 +00:00
if ( cur - > oldNs ! = NULL ) xmlFreeNsList ( cur - > oldNs ) ;
1999-08-29 21:02:19 +00:00
if ( cur - > ids ! = NULL ) xmlFreeIDTable ( ( xmlIDTablePtr ) cur - > ids ) ;
1999-09-08 21:35:25 +00:00
if ( cur - > refs ! = NULL ) xmlFreeRefTable ( ( xmlRefTablePtr ) cur - > refs ) ;
1998-08-13 03:39:55 +00:00
memset ( cur , - 1 , sizeof ( xmlDoc ) ) ;
1999-09-02 22:04:43 +00:00
xmlFree ( cur ) ;
1998-08-13 03:39:55 +00:00
}
1998-10-28 22:58:05 +00:00
/**
* xmlStringLenGetNodeList :
* @ doc : the document
* @ value : the value of the text
1999-02-22 10:33:01 +00:00
* @ len : the length of the string value
1998-10-28 22:58:05 +00:00
*
* Parse the value string and build the node list associated . Should
* produce a flat tree with only TEXTs and ENTITY_REFs .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the first child
1998-10-28 22:58:05 +00:00
*/
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlStringLenGetNodeList ( xmlDocPtr doc , const xmlChar * value , int len ) {
1998-10-28 22:58:05 +00:00
xmlNodePtr ret = NULL , last = NULL ;
xmlNodePtr node ;
1999-09-23 22:19:22 +00:00
xmlChar * val ;
const xmlChar * cur = value ;
const xmlChar * q ;
1998-10-29 05:51:30 +00:00
xmlEntityPtr ent ;
1998-10-28 22:58:05 +00:00
if ( value = = NULL ) return ( NULL ) ;
q = cur ;
while ( ( * cur ! = 0 ) & & ( cur - value < len ) ) {
if ( * cur = = ' & ' ) {
1998-10-29 05:51:30 +00:00
/*
* Save the current text .
*/
1998-10-28 22:58:05 +00:00
if ( cur ! = q ) {
1998-10-29 05:51:30 +00:00
if ( ( last ! = NULL ) & & ( last - > type = = XML_TEXT_NODE ) ) {
xmlNodeAddContentLen ( last , q , cur - q ) ;
} else {
node = xmlNewDocTextLen ( doc , q , cur - q ) ;
if ( node = = NULL ) return ( ret ) ;
if ( last = = NULL )
last = ret = node ;
else {
last - > next = node ;
node - > prev = last ;
last = node ;
}
1998-10-28 22:58:05 +00:00
}
}
1998-10-29 05:51:30 +00:00
/*
* Read the entity string
*/
1998-10-28 22:58:05 +00:00
cur + + ;
q = cur ;
while ( ( * cur ! = 0 ) & & ( cur - value < len ) & & ( * cur ! = ' ; ' ) ) cur + + ;
if ( ( * cur = = 0 ) | | ( cur - value > = len ) ) {
fprintf ( stderr ,
1999-06-02 17:44:04 +00:00
" xmlStringLenGetNodeList: unterminated entity %30s \n " , q ) ;
1998-10-28 22:58:05 +00:00
return ( ret ) ;
}
if ( cur ! = q ) {
1998-10-29 05:51:30 +00:00
/*
* Predefined entities don ' t generate nodes
*/
1998-10-28 22:58:05 +00:00
val = xmlStrndup ( q , cur - q ) ;
1998-10-29 05:51:30 +00:00
ent = xmlGetDocEntity ( doc , val ) ;
if ( ( ent ! = NULL ) & &
( ent - > type = = XML_INTERNAL_PREDEFINED_ENTITY ) ) {
if ( last = = NULL ) {
node = xmlNewDocText ( doc , ent - > content ) ;
last = ret = node ;
} else
xmlNodeAddContent ( last , ent - > content ) ;
} else {
/*
* Create a new REFERENCE_REF node
*/
node = xmlNewReference ( doc , val ) ;
1998-11-13 18:04:35 +00:00
if ( node = = NULL ) {
1999-09-02 22:04:43 +00:00
if ( val ! = NULL ) xmlFree ( val ) ;
1998-11-13 18:04:35 +00:00
return ( ret ) ;
}
1998-10-29 05:51:30 +00:00
if ( last = = NULL )
last = ret = node ;
else {
last - > next = node ;
node - > prev = last ;
last = node ;
}
1998-10-28 22:58:05 +00:00
}
1999-09-02 22:04:43 +00:00
xmlFree ( val ) ;
1998-10-28 22:58:05 +00:00
}
cur + + ;
q = cur ;
} else
cur + + ;
}
if ( cur ! = q ) {
1998-10-29 05:51:30 +00:00
/*
* Handle the last piece of text .
*/
if ( ( last ! = NULL ) & & ( last - > type = = XML_TEXT_NODE ) ) {
xmlNodeAddContentLen ( last , q , cur - q ) ;
} else {
node = xmlNewDocTextLen ( doc , q , cur - q ) ;
if ( node = = NULL ) return ( ret ) ;
if ( last = = NULL )
last = ret = node ;
else {
last - > next = node ;
node - > prev = last ;
last = node ;
}
1998-10-28 22:58:05 +00:00
}
}
return ( ret ) ;
}
1998-10-27 06:21:04 +00:00
/**
* xmlStringGetNodeList :
* @ doc : the document
* @ value : the value of the attribute
*
* Parse the value string and build the node list associated . Should
* produce a flat tree with only TEXTs and ENTITY_REFs .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the first child
1998-10-27 06:21:04 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlStringGetNodeList ( xmlDocPtr doc , const xmlChar * value ) {
1998-10-27 06:21:04 +00:00
xmlNodePtr ret = NULL , last = NULL ;
xmlNodePtr node ;
1999-09-23 22:19:22 +00:00
xmlChar * val ;
const xmlChar * cur = value ;
const xmlChar * q ;
1998-10-29 05:51:30 +00:00
xmlEntityPtr ent ;
1998-10-27 06:21:04 +00:00
if ( value = = NULL ) return ( NULL ) ;
q = cur ;
while ( * cur ! = 0 ) {
if ( * cur = = ' & ' ) {
1998-10-29 05:51:30 +00:00
/*
* Save the current text .
*/
1998-10-27 06:21:04 +00:00
if ( cur ! = q ) {
1998-10-29 05:51:30 +00:00
if ( ( last ! = NULL ) & & ( last - > type = = XML_TEXT_NODE ) ) {
xmlNodeAddContentLen ( last , q , cur - q ) ;
} else {
node = xmlNewDocTextLen ( doc , q , cur - q ) ;
if ( node = = NULL ) return ( ret ) ;
if ( last = = NULL )
last = ret = node ;
else {
last - > next = node ;
node - > prev = last ;
last = node ;
}
1998-10-27 06:21:04 +00:00
}
}
1998-10-29 05:51:30 +00:00
/*
* Read the entity string
*/
1998-10-27 06:21:04 +00:00
cur + + ;
q = cur ;
while ( ( * cur ! = 0 ) & & ( * cur ! = ' ; ' ) ) cur + + ;
if ( * cur = = 0 ) {
fprintf ( stderr ,
" xmlStringGetNodeList: unterminated entity %30s \n " , q ) ;
return ( ret ) ;
}
if ( cur ! = q ) {
1998-10-29 05:51:30 +00:00
/*
* Predefined entities don ' t generate nodes
*/
1998-10-27 06:21:04 +00:00
val = xmlStrndup ( q , cur - q ) ;
1998-10-29 05:51:30 +00:00
ent = xmlGetDocEntity ( doc , val ) ;
if ( ( ent ! = NULL ) & &
( ent - > type = = XML_INTERNAL_PREDEFINED_ENTITY ) ) {
if ( last = = NULL ) {
node = xmlNewDocText ( doc , ent - > content ) ;
last = ret = node ;
} else
xmlNodeAddContent ( last , ent - > content ) ;
} else {
/*
* Create a new REFERENCE_REF node
*/
node = xmlNewReference ( doc , val ) ;
1998-11-13 18:04:35 +00:00
if ( node = = NULL ) {
1999-09-02 22:04:43 +00:00
if ( val ! = NULL ) xmlFree ( val ) ;
1998-11-13 18:04:35 +00:00
return ( ret ) ;
}
1998-10-29 05:51:30 +00:00
if ( last = = NULL )
last = ret = node ;
else {
last - > next = node ;
node - > prev = last ;
last = node ;
}
1998-10-27 06:21:04 +00:00
}
1999-09-02 22:04:43 +00:00
xmlFree ( val ) ;
1998-10-27 06:21:04 +00:00
}
cur + + ;
q = cur ;
} else
cur + + ;
}
if ( cur ! = q ) {
1998-10-29 05:51:30 +00:00
/*
* Handle the last piece of text .
*/
if ( ( last ! = NULL ) & & ( last - > type = = XML_TEXT_NODE ) ) {
xmlNodeAddContentLen ( last , q , cur - q ) ;
} else {
node = xmlNewDocTextLen ( doc , q , cur - q ) ;
if ( node = = NULL ) return ( ret ) ;
if ( last = = NULL )
last = ret = node ;
else {
last - > next = node ;
node - > prev = last ;
last = node ;
}
1998-10-27 06:21:04 +00:00
}
}
return ( ret ) ;
}
/**
* xmlNodeListGetString :
* @ doc : the document
* @ list : a Node list
* @ inLine : should we replace entity contents or show their external form
*
* Returns the string equivalent to the text contained in the Node list
* made of TEXTs and ENTITY_REFs
1999-02-22 10:33:01 +00:00
* Returns a pointer to the string copy , the calller must free it .
1998-10-27 06:21:04 +00:00
*/
1999-09-23 22:19:22 +00:00
xmlChar *
1998-10-27 22:56:57 +00:00
xmlNodeListGetString ( xmlDocPtr doc , xmlNodePtr list , int inLine ) {
1998-10-27 06:21:04 +00:00
xmlNodePtr node = list ;
1999-09-23 22:19:22 +00:00
xmlChar * ret = NULL ;
1998-10-27 06:21:04 +00:00
xmlEntityPtr ent ;
if ( list = = NULL ) return ( NULL ) ;
while ( node ! = NULL ) {
if ( node - > type = = XML_TEXT_NODE ) {
1999-12-01 09:51:45 +00:00
if ( ( inLine ) | | ( doc - > type = = XML_HTML_DOCUMENT_NODE ) ) {
# ifndef XML_USE_BUFFER_CONTENT
1998-10-27 06:21:04 +00:00
ret = xmlStrcat ( ret , node - > content ) ;
1999-12-01 09:51:45 +00:00
# else
ret = xmlStrcat ( ret , xmlBufferContent ( node - > content ) ) ;
# endif
} else {
1999-09-23 22:19:22 +00:00
xmlChar * buffer ;
1999-06-22 21:49:07 +00:00
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-06-22 21:49:07 +00:00
buffer = xmlEncodeEntitiesReentrant ( doc , node - > content ) ;
1999-12-01 09:51:45 +00:00
# else
buffer = xmlEncodeEntitiesReentrant ( doc ,
xmlBufferContent ( node - > content ) ) ;
# endif
1999-06-22 21:49:07 +00:00
if ( buffer ! = NULL ) {
ret = xmlStrcat ( ret , buffer ) ;
1999-09-02 22:04:43 +00:00
xmlFree ( buffer ) ;
1999-06-22 21:49:07 +00:00
}
}
1998-10-27 06:21:04 +00:00
} else if ( node - > type = = XML_ENTITY_REF_NODE ) {
if ( inLine ) {
ent = xmlGetDocEntity ( doc , node - > name ) ;
if ( ent ! = NULL )
ret = xmlStrcat ( ret , ent - > content ) ;
1999-12-01 09:51:45 +00:00
else {
# ifndef XML_USE_BUFFER_CONTENT
1998-10-27 06:21:04 +00:00
ret = xmlStrcat ( ret , node - > content ) ;
1999-12-01 09:51:45 +00:00
# else
ret = xmlStrcat ( ret , xmlBufferContent ( node - > content ) ) ;
# endif
}
1998-10-27 06:21:04 +00:00
} else {
1999-09-23 22:19:22 +00:00
xmlChar buf [ 2 ] ;
1998-10-27 06:21:04 +00:00
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 ) ;
}
}
#if 0
else {
fprintf ( stderr , " xmlGetNodeListString : invalide node type %d \n " ,
node - > type ) ;
}
# endif
node = node - > next ;
}
return ( ret ) ;
}
1998-10-20 06:14:16 +00:00
/**
* 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 .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the attribute
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlAttrPtr
1999-09-23 22:19:22 +00:00
xmlNewProp ( xmlNodePtr node , const xmlChar * name , const xmlChar * value ) {
1998-08-13 03:39:55 +00:00
xmlAttrPtr cur ;
if ( name = = NULL ) {
fprintf ( stderr , " xmlNewProp : name == NULL \n " ) ;
return ( NULL ) ;
}
/*
* Allocate a new property and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlAttrPtr ) xmlMalloc ( sizeof ( xmlAttr ) ) ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewProp : malloc failed \n " ) ;
return ( NULL ) ;
}
1998-10-18 19:12:41 +00:00
cur - > type = XML_ATTRIBUTE_NODE ;
1998-08-13 03:39:55 +00:00
cur - > node = node ;
1999-08-29 21:02:19 +00:00
cur - > ns = NULL ;
cur - > name = xmlStrdup ( name ) ;
1999-11-12 17:02:31 +00:00
if ( value ! = NULL ) {
xmlChar * buffer ;
buffer = xmlEncodeEntitiesReentrant ( node - > doc , value ) ;
cur - > val = xmlStringGetNodeList ( node - > doc , buffer ) ;
xmlFree ( buffer ) ;
}
1999-08-29 21:02:19 +00:00
else
cur - > val = NULL ;
# ifndef XML_WITHOUT_CORBA
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
/*
* Add it at the end to preserve parsing order . . .
*/
cur - > next = NULL ;
if ( node ! = NULL ) {
if ( node - > properties = = NULL ) {
node - > properties = cur ;
} else {
xmlAttrPtr prev = node - > properties ;
while ( prev - > next ! = NULL ) prev = prev - > next ;
prev - > next = cur ;
}
}
1999-10-08 09:40:39 +00:00
# ifndef XML_WITHOUT_CORBA
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
1999-08-29 21:02:19 +00:00
return ( cur ) ;
}
/**
* xmlNewNsProp :
* @ node : the holding node
* @ ns : the namespace
* @ name : the name of the attribute
* @ value : the value of the attribute
*
* Create a new property tagged with a namespace and carried by a node .
* Returns a pointer to the attribute
*/
xmlAttrPtr
1999-09-23 22:19:22 +00:00
xmlNewNsProp ( xmlNodePtr node , xmlNsPtr ns , const xmlChar * name ,
const xmlChar * value ) {
1999-08-29 21:02:19 +00:00
xmlAttrPtr cur ;
if ( name = = NULL ) {
fprintf ( stderr , " xmlNewProp : name == NULL \n " ) ;
return ( NULL ) ;
}
/*
* Allocate a new property and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlAttrPtr ) xmlMalloc ( sizeof ( xmlAttr ) ) ;
1999-08-29 21:02:19 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewProp : malloc failed \n " ) ;
return ( NULL ) ;
}
cur - > type = XML_ATTRIBUTE_NODE ;
cur - > node = node ;
cur - > ns = ns ;
1998-08-13 03:39:55 +00:00
cur - > name = xmlStrdup ( name ) ;
if ( value ! = NULL )
1998-10-27 06:21:04 +00:00
cur - > val = xmlStringGetNodeList ( node - > doc , value ) ;
1998-08-13 03:39:55 +00:00
else
1998-10-27 06:21:04 +00:00
cur - > val = NULL ;
1999-05-29 11:51:49 +00:00
# ifndef XML_WITHOUT_CORBA
1998-10-17 06:47:46 +00:00
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
1998-08-13 03:39:55 +00:00
/*
* Add it at the end to preserve parsing order . . .
*/
cur - > next = NULL ;
if ( node ! = NULL ) {
if ( node - > properties = = NULL ) {
node - > properties = cur ;
} else {
xmlAttrPtr prev = node - > properties ;
while ( prev - > next ! = NULL ) prev = prev - > next ;
prev - > next = cur ;
}
}
return ( cur ) ;
}
1998-10-27 06:21:04 +00:00
/**
* xmlNewDocProp :
* @ doc : the document
* @ name : the name of the attribute
* @ value : the value of the attribute
*
* Create a new property carried by a document .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the attribute
1998-10-27 06:21:04 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlAttrPtr
1999-09-23 22:19:22 +00:00
xmlNewDocProp ( xmlDocPtr doc , const xmlChar * name , const xmlChar * value ) {
1998-10-27 06:21:04 +00:00
xmlAttrPtr cur ;
if ( name = = NULL ) {
fprintf ( stderr , " xmlNewProp : name == NULL \n " ) ;
return ( NULL ) ;
}
/*
* Allocate a new property and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlAttrPtr ) xmlMalloc ( sizeof ( xmlAttr ) ) ;
1998-10-27 06:21:04 +00:00
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 = xmlStringGetNodeList ( doc , value ) ;
else
cur - > val = NULL ;
1999-05-29 11:51:49 +00:00
# ifndef XML_WITHOUT_CORBA
1998-10-27 06:21:04 +00:00
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
cur - > next = NULL ;
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlFreePropList :
* @ cur : the first property in the list
*
* Free a property and all its siblings , all the childs are freed too .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
xmlFreePropList ( xmlAttrPtr cur ) {
1998-08-13 03:39:55 +00:00
xmlAttrPtr next ;
if ( cur = = NULL ) {
fprintf ( stderr , " xmlFreePropList : property == NULL \n " ) ;
return ;
}
while ( cur ! = NULL ) {
next = cur - > next ;
xmlFreeProp ( cur ) ;
cur = next ;
}
}
1998-10-20 06:14:16 +00:00
/**
* xmlFreeProp :
* @ cur : the first property in the list
*
* Free one property , all the childs are freed too .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
xmlFreeProp ( xmlAttrPtr cur ) {
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlFreeProp : property == NULL \n " ) ;
return ;
}
1999-09-02 22:04:43 +00:00
if ( cur - > name ! = NULL ) xmlFree ( ( char * ) cur - > name ) ;
1998-10-27 06:21:04 +00:00
if ( cur - > val ! = NULL ) xmlFreeNodeList ( cur - > val ) ;
1998-08-13 03:39:55 +00:00
memset ( cur , - 1 , sizeof ( xmlAttr ) ) ;
1999-09-02 22:04:43 +00:00
xmlFree ( cur ) ;
1998-08-13 03:39:55 +00:00
}
1999-08-29 21:02:19 +00:00
/**
* xmlNewPI :
* @ name : the processing instruction name
* @ content : the PI content
*
* Creation of a processing instruction element .
* Returns a pointer to the new node object .
*/
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlNewPI ( const xmlChar * name , const xmlChar * content ) {
1999-08-29 21:02:19 +00:00
xmlNodePtr cur ;
if ( name = = NULL ) {
fprintf ( stderr , " xmlNewPI : name == NULL \n " ) ;
return ( NULL ) ;
}
/*
* Allocate a new node and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlNodePtr ) xmlMalloc ( sizeof ( xmlNode ) ) ;
1999-08-29 21:02:19 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewPI : malloc failed \n " ) ;
return ( NULL ) ;
}
cur - > type = XML_PI_NODE ;
cur - > doc = NULL ;
cur - > parent = NULL ;
cur - > next = NULL ;
cur - > prev = NULL ;
cur - > childs = NULL ;
cur - > last = NULL ;
cur - > properties = NULL ;
cur - > name = xmlStrdup ( name ) ;
cur - > ns = NULL ;
cur - > nsDef = NULL ;
1999-12-01 09:51:45 +00:00
if ( content ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
1999-08-29 21:02:19 +00:00
cur - > content = xmlStrdup ( content ) ;
1999-12-01 09:51:45 +00:00
# else
cur - > content = xmlBufferCreateSize ( 0 ) ;
xmlBufferSetAllocationScheme ( cur - > content ,
xmlGetBufferAllocationScheme ( ) ) ;
xmlBufferAdd ( cur - > content , content , - 1 ) ;
# endif
} else
1999-08-29 21:02:19 +00:00
cur - > content = NULL ;
# ifndef XML_WITHOUT_CORBA
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlNewNode :
* @ ns : namespace if any
* @ name : the node name
*
* Creation of a new node element . @ ns and @ content are optionnal ( NULL ) .
1998-10-27 06:21:04 +00:00
* If content is non NULL , a child list containing the TEXTs and
* ENTITY_REFs node will be created .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the new node object .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlNewNode ( xmlNsPtr ns , const xmlChar * name ) {
1998-08-13 03:39:55 +00:00
xmlNodePtr cur ;
if ( name = = NULL ) {
fprintf ( stderr , " xmlNewNode : name == NULL \n " ) ;
return ( NULL ) ;
}
/*
* Allocate a new node and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlNodePtr ) xmlMalloc ( sizeof ( xmlNode ) ) ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewNode : malloc failed \n " ) ;
return ( NULL ) ;
}
1998-10-18 19:12:41 +00:00
cur - > type = XML_ELEMENT_NODE ;
1998-10-14 02:36:47 +00:00
cur - > doc = NULL ;
1998-08-13 03:39:55 +00:00
cur - > parent = NULL ;
1998-10-14 02:36:47 +00:00
cur - > next = NULL ;
cur - > prev = NULL ;
cur - > childs = NULL ;
1999-01-17 19:11:59 +00:00
cur - > last = NULL ;
1998-10-14 02:36:47 +00:00
cur - > properties = NULL ;
1998-08-13 03:39:55 +00:00
cur - > name = xmlStrdup ( name ) ;
cur - > ns = ns ;
cur - > nsDef = NULL ;
1998-10-27 06:21:04 +00:00
cur - > content = NULL ;
1999-05-29 11:51:49 +00:00
# ifndef XML_WITHOUT_CORBA
1998-10-17 06:47:46 +00:00
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
1998-08-13 03:39:55 +00:00
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlNewDocNode :
* @ doc : the document
* @ ns : namespace if any
* @ name : the node name
1999-11-23 10:40:46 +00:00
* @ content : the XML text content if any
1998-10-20 06:14:16 +00:00
*
* Creation of a new node element within a document . @ ns and @ content
* are optionnal ( NULL ) .
1999-11-23 10:40:46 +00:00
* 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 .
*
1999-02-22 10:33:01 +00:00
* Returns a pointer to the new node object .
1998-10-20 06:14:16 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
xmlNewDocNode ( xmlDocPtr doc , xmlNsPtr ns ,
1999-11-23 10:40:46 +00:00
const xmlChar * name , const xmlChar * content ) {
1998-10-14 02:36:47 +00:00
xmlNodePtr cur ;
1998-10-27 06:21:04 +00:00
cur = xmlNewNode ( ns , name ) ;
if ( cur ! = NULL ) {
cur - > doc = doc ;
1999-01-17 19:11:59 +00:00
if ( content ! = NULL ) {
1998-10-27 06:21:04 +00:00
cur - > childs = xmlStringGetNodeList ( doc , content ) ;
1999-02-22 10:33:01 +00:00
UPDATE_LAST_CHILD ( cur )
1999-01-17 19:11:59 +00:00
}
1998-10-27 06:21:04 +00:00
}
1998-10-14 02:36:47 +00:00
return ( cur ) ;
}
1999-11-23 10:40:46 +00:00
/**
* 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 ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlNewText :
* @ content : the text content
*
* Creation of a new text node .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the new node object .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlNewText ( const xmlChar * content ) {
1998-08-13 03:39:55 +00:00
xmlNodePtr cur ;
/*
* Allocate a new node and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlNodePtr ) xmlMalloc ( sizeof ( xmlNode ) ) ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewText : malloc failed \n " ) ;
return ( NULL ) ;
}
1998-10-18 19:12:41 +00:00
cur - > type = XML_TEXT_NODE ;
1998-10-14 02:36:47 +00:00
cur - > doc = NULL ;
1998-08-13 03:39:55 +00:00
cur - > parent = NULL ;
cur - > next = NULL ;
1998-10-14 02:36:47 +00:00
cur - > prev = NULL ;
1998-08-13 03:39:55 +00:00
cur - > childs = NULL ;
1999-01-17 19:11:59 +00:00
cur - > last = NULL ;
1998-08-13 03:39:55 +00:00
cur - > properties = NULL ;
1998-10-14 02:36:47 +00:00
cur - > type = XML_TEXT_NODE ;
1998-08-13 03:39:55 +00:00
cur - > name = xmlStrdup ( xmlStringText ) ;
cur - > ns = NULL ;
cur - > nsDef = NULL ;
1999-12-01 09:51:45 +00:00
if ( content ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
1998-08-13 03:39:55 +00:00
cur - > content = xmlStrdup ( content ) ;
1999-12-01 09:51:45 +00:00
# else
cur - > content = xmlBufferCreateSize ( 0 ) ;
xmlBufferSetAllocationScheme ( cur - > content ,
xmlGetBufferAllocationScheme ( ) ) ;
xmlBufferAdd ( cur - > content , content , - 1 ) ;
# endif
} else
1998-08-13 03:39:55 +00:00
cur - > content = NULL ;
1999-10-08 09:40:39 +00:00
# ifndef XML_WITHOUT_CORBA
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
1998-08-13 03:39:55 +00:00
return ( cur ) ;
}
1999-11-23 10:40:46 +00:00
/**
* 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 ) ;
}
1998-10-27 06:21:04 +00:00
/**
* xmlNewReference :
* @ doc : the document
* @ name : the reference name , or the reference string with & and ;
*
* Creation of a new reference node .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the new node object .
1998-10-27 06:21:04 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlNewReference ( xmlDocPtr doc , const xmlChar * name ) {
1998-10-27 06:21:04 +00:00
xmlNodePtr cur ;
xmlEntityPtr ent ;
/*
* Allocate a new node and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlNodePtr ) xmlMalloc ( sizeof ( xmlNode ) ) ;
1998-10-27 06:21:04 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewText : malloc failed \n " ) ;
return ( NULL ) ;
}
cur - > type = XML_ENTITY_REF_NODE ;
1998-10-28 01:00:12 +00:00
cur - > doc = doc ;
1998-10-27 06:21:04 +00:00
cur - > parent = NULL ;
cur - > next = NULL ;
cur - > prev = NULL ;
cur - > childs = NULL ;
1999-01-17 19:11:59 +00:00
cur - > last = NULL ;
1998-10-27 06:21:04 +00:00
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 ) ;
1999-12-01 09:51:45 +00:00
if ( ent ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
1998-10-27 06:21:04 +00:00
cur - > content = ent - > content ;
1999-12-01 09:51:45 +00:00
# else
/*
* CJN 11.18 .99 this might be a problem , since the xmlBuffer gets
* a copy of this pointer . Let ' s hope we don ' t manipulate it
* later
*/
cur - > content = xmlBufferCreateSize ( 0 ) ;
xmlBufferSetAllocationScheme ( cur - > content ,
xmlGetBufferAllocationScheme ( ) ) ;
if ( ent - > content ! = NULL )
xmlBufferAdd ( cur - > content , ent - > content , - 1 ) ;
# endif
} else
1998-10-27 06:21:04 +00:00
cur - > content = NULL ;
1999-10-08 09:40:39 +00:00
# ifndef XML_WITHOUT_CORBA
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
1998-10-27 06:21:04 +00:00
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlNewDocText :
* @ doc : the document
* @ content : the text content
*
* Creation of a new text node within a document .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the new node object .
1998-10-20 06:14:16 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlNewDocText ( xmlDocPtr doc , const xmlChar * content ) {
1998-10-14 02:36:47 +00:00
xmlNodePtr cur ;
cur = xmlNewText ( content ) ;
if ( cur ! = NULL ) cur - > doc = doc ;
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
1998-10-27 06:21:04 +00:00
* xmlNewTextLen :
1998-10-20 06:14:16 +00:00
* @ content : the text content
* @ len : the text len .
*
* Creation of a new text node with an extra parameter for the content ' s lenght
1999-02-22 10:33:01 +00:00
* Returns a pointer to the new node object .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlNewTextLen ( const xmlChar * content , int len ) {
1998-08-13 03:39:55 +00:00
xmlNodePtr cur ;
/*
* Allocate a new node and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlNodePtr ) xmlMalloc ( sizeof ( xmlNode ) ) ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewText : malloc failed \n " ) ;
return ( NULL ) ;
}
1998-10-18 19:12:41 +00:00
cur - > type = XML_TEXT_NODE ;
1998-10-14 02:36:47 +00:00
cur - > doc = NULL ;
1998-08-13 03:39:55 +00:00
cur - > parent = NULL ;
1998-10-14 02:36:47 +00:00
cur - > prev = NULL ;
1998-08-13 03:39:55 +00:00
cur - > next = NULL ;
cur - > childs = NULL ;
1999-01-17 19:11:59 +00:00
cur - > last = NULL ;
1998-08-13 03:39:55 +00:00
cur - > properties = NULL ;
1998-10-14 02:36:47 +00:00
cur - > type = XML_TEXT_NODE ;
1998-08-13 03:39:55 +00:00
cur - > name = xmlStrdup ( xmlStringText ) ;
cur - > ns = NULL ;
cur - > nsDef = NULL ;
1999-12-01 09:51:45 +00:00
if ( content ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
1998-08-13 03:39:55 +00:00
cur - > content = xmlStrndup ( content , len ) ;
1999-12-01 09:51:45 +00:00
# else
cur - > content = xmlBufferCreateSize ( len ) ;
xmlBufferSetAllocationScheme ( cur - > content ,
xmlGetBufferAllocationScheme ( ) ) ;
xmlBufferAdd ( cur - > content , content , len ) ;
# endif
} else
1998-08-13 03:39:55 +00:00
cur - > content = NULL ;
1999-10-08 09:40:39 +00:00
# ifndef XML_WITHOUT_CORBA
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
1998-08-13 03:39:55 +00:00
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
* 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 .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the new node object .
1998-10-20 06:14:16 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlNewDocTextLen ( xmlDocPtr doc , const xmlChar * content , int len ) {
1998-10-14 02:36:47 +00:00
xmlNodePtr cur ;
cur = xmlNewTextLen ( content , len ) ;
if ( cur ! = NULL ) cur - > doc = doc ;
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlNewComment :
* @ content : the comment content
*
* Creation of a new node containing a comment .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the new node object .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlNewComment ( const xmlChar * content ) {
1998-08-13 03:39:55 +00:00
xmlNodePtr cur ;
/*
* Allocate a new node and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlNodePtr ) xmlMalloc ( sizeof ( xmlNode ) ) ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewComment : malloc failed \n " ) ;
return ( NULL ) ;
}
1998-10-18 19:12:41 +00:00
cur - > type = XML_COMMENT_NODE ;
1998-10-14 02:36:47 +00:00
cur - > doc = NULL ;
1998-08-13 03:39:55 +00:00
cur - > parent = NULL ;
1998-10-14 02:36:47 +00:00
cur - > prev = NULL ;
1998-08-13 03:39:55 +00:00
cur - > next = NULL ;
cur - > childs = NULL ;
1999-01-17 19:11:59 +00:00
cur - > last = NULL ;
1998-08-13 03:39:55 +00:00
cur - > properties = NULL ;
1998-10-14 02:36:47 +00:00
cur - > type = XML_COMMENT_NODE ;
1998-08-13 03:39:55 +00:00
cur - > name = xmlStrdup ( xmlStringText ) ;
cur - > ns = NULL ;
cur - > nsDef = NULL ;
1999-12-01 09:51:45 +00:00
if ( content ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
1998-08-13 03:39:55 +00:00
cur - > content = xmlStrdup ( content ) ;
1999-12-01 09:51:45 +00:00
# else
cur - > content = xmlBufferCreateSize ( 0 ) ;
xmlBufferSetAllocationScheme ( cur - > content ,
xmlGetBufferAllocationScheme ( ) ) ;
xmlBufferAdd ( cur - > content , content , - 1 ) ;
# endif
} else
1998-08-13 03:39:55 +00:00
cur - > content = NULL ;
1999-10-08 09:40:39 +00:00
# ifndef XML_WITHOUT_CORBA
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
1998-08-13 03:39:55 +00:00
return ( cur ) ;
}
1999-08-10 19:04:08 +00:00
/**
* xmlNewCDataBlock :
* @ doc : the document
* @ content : the CData block content content
* @ len : the length of the block
*
* Creation of a new node containing a CData block .
* Returns a pointer to the new node object .
*/
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlNewCDataBlock ( xmlDocPtr doc , const xmlChar * content , int len ) {
1999-08-10 19:04:08 +00:00
xmlNodePtr cur ;
/*
* Allocate a new node and fill the fields .
*/
1999-09-02 22:04:43 +00:00
cur = ( xmlNodePtr ) xmlMalloc ( sizeof ( xmlNode ) ) ;
1999-08-10 19:04:08 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNewCDataBlock : malloc failed \n " ) ;
return ( NULL ) ;
}
cur - > type = XML_CDATA_SECTION_NODE ;
cur - > doc = NULL ;
cur - > parent = NULL ;
cur - > prev = NULL ;
cur - > next = NULL ;
cur - > childs = NULL ;
cur - > last = NULL ;
cur - > properties = NULL ;
cur - > name = xmlStrdup ( xmlStringText ) ;
cur - > ns = NULL ;
cur - > nsDef = NULL ;
1999-12-01 09:51:45 +00:00
if ( content ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
1999-08-10 19:04:08 +00:00
cur - > content = xmlStrndup ( content , len ) ;
1999-12-01 09:51:45 +00:00
# else
cur - > content = xmlBufferCreateSize ( len ) ;
xmlBufferSetAllocationScheme ( cur - > content ,
xmlGetBufferAllocationScheme ( ) ) ;
xmlBufferAdd ( cur - > content , content , len ) ;
# endif
1999-08-10 19:04:08 +00:00
} else
cur - > content = NULL ;
1999-10-08 09:40:39 +00:00
# ifndef XML_WITHOUT_CORBA
cur - > _private = NULL ;
cur - > vepv = NULL ;
# endif
1999-08-10 19:04:08 +00:00
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
1999-02-22 10:33:01 +00:00
* xmlNewDocComment :
1998-10-20 06:14:16 +00:00
* @ doc : the document
* @ content : the comment content
*
* Creation of a new node containing a commentwithin a document .
1999-02-22 10:33:01 +00:00
* Returns a pointer to the new node object .
1998-10-20 06:14:16 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
1999-09-23 22:19:22 +00:00
xmlNewDocComment ( xmlDocPtr doc , const xmlChar * content ) {
1998-10-14 02:36:47 +00:00
xmlNodePtr cur ;
cur = xmlNewComment ( content ) ;
if ( cur ! = NULL ) cur - > doc = doc ;
return ( cur ) ;
}
1999-11-23 10:40:46 +00:00
1998-10-20 06:14:16 +00:00
/**
* xmlNewChild :
* @ parent : the parent node
* @ ns : a namespace if any
* @ name : the name of the child
1999-11-23 10:40:46 +00:00
* @ content : the XML content of the child if any .
1998-10-20 06:14:16 +00:00
*
* Creation of a new child element , added at the end of @ parent childs list .
1998-10-27 06:21:04 +00:00
* @ 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 .
1999-11-23 10:40:46 +00:00
* 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 .
*
1999-02-22 10:33:01 +00:00
* Returns a pointer to the new node object .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
xmlNewChild ( xmlNodePtr parent , xmlNsPtr ns ,
1999-11-23 10:40:46 +00:00
const xmlChar * name , const xmlChar * content ) {
1998-08-13 03:39:55 +00:00
xmlNodePtr cur , prev ;
if ( parent = = NULL ) {
fprintf ( stderr , " xmlNewChild : parent == NULL \n " ) ;
return ( NULL ) ;
}
if ( name = = NULL ) {
fprintf ( stderr , " xmlNewChild : name == NULL \n " ) ;
return ( NULL ) ;
}
/*
* Allocate a new node
*/
if ( ns = = NULL )
1998-10-27 06:21:04 +00:00
cur = xmlNewDocNode ( parent - > doc , parent - > ns , name , content ) ;
1998-08-13 03:39:55 +00:00
else
1998-10-27 06:21:04 +00:00
cur = xmlNewDocNode ( parent - > doc , ns , name , content ) ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) return ( NULL ) ;
/*
* add the new element at the end of the childs list .
*/
1998-10-27 06:21:04 +00:00
cur - > type = XML_ELEMENT_NODE ;
1998-08-13 03:39:55 +00:00
cur - > parent = parent ;
1998-10-14 02:36:47 +00:00
cur - > doc = parent - > doc ;
1998-08-13 03:39:55 +00:00
if ( parent - > childs = = NULL ) {
parent - > childs = cur ;
1999-01-17 19:11:59 +00:00
parent - > last = cur ;
1998-08-13 03:39:55 +00:00
} else {
1999-01-17 19:11:59 +00:00
prev = parent - > last ;
1998-08-13 03:39:55 +00:00
prev - > next = cur ;
1998-10-14 02:36:47 +00:00
cur - > prev = prev ;
1999-01-17 19:11:59 +00:00
parent - > last = cur ;
1998-08-13 03:39:55 +00:00
}
return ( cur ) ;
}
1999-08-29 21:02:19 +00:00
/**
* xmlAddSibling :
* @ cur : the child node
* @ elem : the new node
*
* Add a new element to the list of siblings of @ cur
* Returns the element or NULL in case of error .
*/
xmlNodePtr
xmlAddSibling ( xmlNodePtr cur , xmlNodePtr elem ) {
xmlNodePtr parent ;
if ( cur = = NULL ) {
fprintf ( stderr , " xmlAddSibling : cur == NULL \n " ) ;
return ( NULL ) ;
}
if ( elem = = NULL ) {
fprintf ( stderr , " xmlAddSibling : elem == NULL \n " ) ;
return ( NULL ) ;
}
if ( ( cur - > doc ! = NULL ) & & ( elem - > doc ! = NULL ) & &
( cur - > doc ! = elem - > doc ) ) {
fprintf ( stderr ,
" xmlAddSibling: Elements moved to a different document \n " ) ;
}
while ( cur - > next ! = NULL ) cur = cur - > next ;
if ( elem - > doc = = NULL )
elem - > doc = cur - > doc ; /* the parent may not be linked to a doc ! */
parent = cur - > parent ;
elem - > prev = cur ;
elem - > next = NULL ;
elem - > parent = parent ;
cur - > next = elem ;
if ( parent ! = NULL )
parent - > last = elem ;
return ( elem ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlAddChild :
* @ parent : the parent node
* @ cur : the child node
*
* Add a new child element , to @ parent , at the end of the child list .
1999-02-22 10:33:01 +00:00
* Returns the child or NULL in case of error .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
xmlAddChild ( xmlNodePtr parent , xmlNodePtr cur ) {
1998-08-13 03:39:55 +00:00
xmlNodePtr prev ;
if ( parent = = NULL ) {
1999-12-12 13:03:50 +00:00
fprintf ( stderr , " xmlAddChild : parent == NULL \n " ) ;
1998-08-13 03:39:55 +00:00
return ( NULL ) ;
}
if ( cur = = NULL ) {
1999-12-12 13:03:50 +00:00
fprintf ( stderr , " xmlAddChild : child == NULL \n " ) ;
1998-08-13 03:39:55 +00:00
return ( NULL ) ;
}
1998-10-14 02:36:47 +00:00
if ( ( cur - > doc ! = NULL ) & & ( parent - > doc ! = NULL ) & &
( cur - > doc ! = parent - > doc ) ) {
fprintf ( stderr , " Elements moved to a different document \n " ) ;
}
1998-08-13 03:39:55 +00:00
/*
* add the new element at the end of the childs list .
*/
cur - > parent = parent ;
1998-10-14 02:36:47 +00:00
cur - > doc = parent - > doc ; /* the parent may not be linked to a doc ! */
1999-01-17 19:11:59 +00:00
1998-10-27 06:21:04 +00:00
/*
* Handle the case where parent - > content ! = NULL , in that case it will
* create a intermediate TEXT node .
*/
if ( parent - > content ! = NULL ) {
xmlNodePtr text ;
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1998-10-27 06:21:04 +00:00
text = xmlNewDocText ( parent - > doc , parent - > content ) ;
1999-12-01 09:51:45 +00:00
# else
text = xmlNewDocText ( parent - > doc , xmlBufferContent ( parent - > content ) ) ;
# endif
1998-10-27 06:21:04 +00:00
if ( text ! = NULL ) {
text - > next = parent - > childs ;
if ( text - > next ! = NULL )
text - > next - > prev = text ;
parent - > childs = text ;
1999-02-22 10:33:01 +00:00
UPDATE_LAST_CHILD ( parent )
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-09-02 22:04:43 +00:00
xmlFree ( parent - > content ) ;
1999-12-01 09:51:45 +00:00
# else
xmlBufferFree ( parent - > content ) ;
# endif
1998-10-27 06:21:04 +00:00
parent - > content = NULL ;
}
}
1998-08-13 03:39:55 +00:00
if ( parent - > childs = = NULL ) {
parent - > childs = cur ;
1999-01-17 19:11:59 +00:00
parent - > last = cur ;
1998-08-13 03:39:55 +00:00
} else {
1999-01-17 19:11:59 +00:00
prev = parent - > last ;
1998-08-13 03:39:55 +00:00
prev - > next = cur ;
1998-10-14 02:36:47 +00:00
cur - > prev = prev ;
1999-01-17 19:11:59 +00:00
parent - > last = cur ;
1998-08-13 03:39:55 +00:00
}
return ( cur ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlGetLastChild :
* @ parent : the parent node
*
* Search the last child of a node .
1999-02-22 10:33:01 +00:00
* Returns the last child or NULL if none .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNodePtr
xmlGetLastChild ( xmlNodePtr parent ) {
1998-08-13 03:39:55 +00:00
if ( parent = = NULL ) {
fprintf ( stderr , " xmlGetLastChild : parent == NULL \n " ) ;
return ( NULL ) ;
}
1999-01-17 19:11:59 +00:00
return ( parent - > last ) ;
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
/**
* xmlFreeNodeList :
* @ cur : the first node in the list
*
* Free a node and all its siblings , this is a recursive behaviour , all
* the childs are freed too .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
xmlFreeNodeList ( xmlNodePtr cur ) {
1998-08-13 03:39:55 +00:00
xmlNodePtr next ;
if ( cur = = NULL ) {
fprintf ( stderr , " xmlFreeNodeList : node == NULL \n " ) ;
return ;
}
while ( cur ! = NULL ) {
next = cur - > next ;
xmlFreeNode ( cur ) ;
cur = next ;
}
}
1998-10-20 06:14:16 +00:00
/**
* xmlFreeNode :
* @ cur : the node
*
* Free a node , this is a recursive behaviour , all the childs are freed too .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
xmlFreeNode ( xmlNodePtr cur ) {
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlFreeNode : node == NULL \n " ) ;
return ;
}
1998-10-27 06:21:04 +00:00
cur - > doc = NULL ;
cur - > parent = NULL ;
cur - > next = NULL ;
cur - > prev = NULL ;
1998-08-13 03:39:55 +00:00
if ( cur - > childs ! = NULL ) xmlFreeNodeList ( cur - > childs ) ;
1998-10-27 06:21:04 +00:00
if ( cur - > properties ! = NULL ) xmlFreePropList ( cur - > properties ) ;
if ( cur - > type ! = XML_ENTITY_REF_NODE )
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-09-02 22:04:43 +00:00
if ( cur - > content ! = NULL ) xmlFree ( cur - > content ) ;
1999-12-01 09:51:45 +00:00
# else
if ( cur - > content ! = NULL ) xmlBufferFree ( cur - > content ) ;
# endif
1999-09-02 22:04:43 +00:00
if ( cur - > name ! = NULL ) xmlFree ( ( char * ) cur - > name ) ;
1998-08-13 03:39:55 +00:00
if ( cur - > nsDef ! = NULL ) xmlFreeNsList ( cur - > nsDef ) ;
memset ( cur , - 1 , sizeof ( xmlNode ) ) ;
1999-09-02 22:04:43 +00:00
xmlFree ( cur ) ;
1998-08-13 03:39:55 +00:00
}
1998-10-28 22:58:05 +00:00
/**
* xmlUnlinkNode :
* @ cur : the node
*
* Unlink a node from it ' s current context , the node is not freed
*/
void
xmlUnlinkNode ( xmlNodePtr cur ) {
if ( cur = = NULL ) {
fprintf ( stderr , " xmlUnlinkNode : node == NULL \n " ) ;
return ;
}
if ( ( cur - > parent ! = NULL ) & & ( cur - > parent - > childs = = cur ) )
cur - > parent - > childs = cur - > next ;
1999-01-17 19:11:59 +00:00
if ( ( cur - > parent ! = NULL ) & & ( cur - > parent - > last = = cur ) )
cur - > parent - > last = cur - > prev ;
1998-10-28 22:58:05 +00:00
if ( cur - > next ! = NULL )
cur - > next - > prev = cur - > prev ;
if ( cur - > prev ! = NULL )
cur - > prev - > next = cur - > next ;
cur - > next = cur - > prev = NULL ;
cur - > parent = NULL ;
}
1998-11-27 06:39:50 +00:00
/************************************************************************
* *
* Copy operations *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* xmlCopyNamespace :
* @ cur : the namespace
*
* Do a copy of the namespace .
*
* Returns : a new xmlNsPtr , or NULL in case of error .
*/
xmlNsPtr
xmlCopyNamespace ( xmlNsPtr cur ) {
xmlNsPtr ret ;
if ( cur = = NULL ) return ( NULL ) ;
switch ( cur - > type ) {
case XML_GLOBAL_NAMESPACE :
ret = xmlNewGlobalNs ( NULL , cur - > href , cur - > prefix ) ;
break ;
case XML_LOCAL_NAMESPACE :
ret = xmlNewNs ( NULL , cur - > href , cur - > prefix ) ;
break ;
default :
fprintf ( stderr , " xmlCopyNamespace: unknown type %d \n " , cur - > type ) ;
return ( NULL ) ;
}
return ( ret ) ;
}
/**
* xmlCopyNamespaceList :
* @ cur : the first namespace
*
* Do a copy of an namespace list .
*
* Returns : a new xmlNsPtr , or NULL in case of error .
*/
xmlNsPtr
xmlCopyNamespaceList ( xmlNsPtr cur ) {
xmlNsPtr ret = NULL ;
xmlNsPtr p = NULL , q ;
while ( cur ! = NULL ) {
q = xmlCopyNamespace ( cur ) ;
if ( p = = NULL ) {
ret = p = q ;
} else {
p - > next = q ;
p = q ;
}
cur = cur - > next ;
}
return ( ret ) ;
}
/**
* xmlCopyProp :
1999-08-29 21:02:19 +00:00
* @ target : the element where the attribute will be grafted
1998-11-27 06:39:50 +00:00
* @ cur : the attribute
*
* Do a copy of the attribute .
*
* Returns : a new xmlAttrPtr , or NULL in case of error .
*/
xmlAttrPtr
1999-08-29 21:02:19 +00:00
xmlCopyProp ( xmlNodePtr target , xmlAttrPtr cur ) {
1998-11-27 06:39:50 +00:00
xmlAttrPtr ret ;
if ( cur = = NULL ) return ( NULL ) ;
if ( cur - > val ! = NULL )
ret = xmlNewDocProp ( cur - > val - > doc , cur - > name , NULL ) ;
else
ret = xmlNewDocProp ( NULL , cur - > name , NULL ) ;
if ( ret = = NULL ) return ( NULL ) ;
1999-08-29 21:02:19 +00:00
if ( ( cur - > ns ! = NULL ) & & ( target ! = NULL ) ) {
xmlNsPtr ns ;
ns = xmlSearchNs ( target - > doc , target , cur - > ns - > prefix ) ;
ret - > ns = ns ;
} else
ret - > ns = NULL ;
1998-11-27 06:39:50 +00:00
if ( cur - > val ! = NULL )
ret - > val = xmlCopyNodeList ( cur - > val ) ;
return ( ret ) ;
}
/**
* xmlCopyPropList :
1999-08-29 21:02:19 +00:00
* @ target : the element where the attributes will be grafted
1998-11-27 06:39:50 +00:00
* @ cur : the first attribute
*
* Do a copy of an attribute list .
*
* Returns : a new xmlAttrPtr , or NULL in case of error .
*/
xmlAttrPtr
1999-08-29 21:02:19 +00:00
xmlCopyPropList ( xmlNodePtr target , xmlAttrPtr cur ) {
1998-11-27 06:39:50 +00:00
xmlAttrPtr ret = NULL ;
xmlAttrPtr p = NULL , q ;
while ( cur ! = NULL ) {
1999-08-29 21:02:19 +00:00
q = xmlCopyProp ( target , cur ) ;
1998-11-27 06:39:50 +00:00
if ( p = = NULL ) {
ret = p = q ;
} else {
p - > next = q ;
p = q ;
}
cur = cur - > next ;
}
return ( ret ) ;
}
/*
1999-11-23 10:40:46 +00:00
* NOTE abeut the CopyNode operations !
1998-11-27 06:39:50 +00:00
*
* They are splitted into external and internal parts for one
* tricky reason : namespaces . Doing a direct copy of a node
* say RPM : Copyright without changing the namespace pointer to
* something else can produce stale links . One way to do it is
* to keep a reference counter but this doesn ' t work as soon
* as one move the element or the subtree out of the scope of
* the existing namespace . The actual solution seems to add
* a copy of the namespace at the top of the copied tree if
* not available in the subtree .
* Hence two functions , the public front - end call the inner ones
*/
static xmlNodePtr
xmlStaticCopyNodeList ( xmlNodePtr node , xmlDocPtr doc , xmlNodePtr parent ) ;
static xmlNodePtr
xmlStaticCopyNode ( xmlNodePtr node , xmlDocPtr doc , xmlNodePtr parent ,
int recursive ) {
xmlNodePtr ret ;
if ( node = = NULL ) return ( NULL ) ;
/*
* Allocate a new node and fill the fields .
*/
1999-09-02 22:04:43 +00:00
ret = ( xmlNodePtr ) xmlMalloc ( sizeof ( xmlNode ) ) ;
1998-11-27 06:39:50 +00:00
if ( ret = = NULL ) {
fprintf ( stderr , " xmlStaticCopyNode : malloc failed \n " ) ;
return ( NULL ) ;
}
ret - > type = node - > type ;
ret - > doc = doc ;
ret - > parent = parent ;
ret - > next = NULL ;
ret - > prev = NULL ;
ret - > childs = NULL ;
1999-01-17 19:11:59 +00:00
ret - > last = NULL ;
1998-11-27 06:39:50 +00:00
ret - > properties = NULL ;
if ( node - > name ! = NULL )
ret - > name = xmlStrdup ( node - > name ) ;
else
ret - > name = NULL ;
ret - > ns = NULL ;
ret - > nsDef = NULL ;
1999-12-01 09:51:45 +00:00
if ( ( node - > content ! = NULL ) & & ( node - > type ! = XML_ENTITY_REF_NODE ) ) {
# ifndef XML_USE_BUFFER_CONTENT
1998-11-27 06:39:50 +00:00
ret - > content = xmlStrdup ( node - > content ) ;
1999-12-01 09:51:45 +00:00
# else
ret - > content = xmlBufferCreateSize ( xmlBufferLength ( node - > content ) ) ;
xmlBufferSetAllocationScheme ( ret - > content ,
xmlGetBufferAllocationScheme ( ) ) ;
xmlBufferAdd ( ret - > content ,
xmlBufferContent ( node - > content ) ,
xmlBufferLength ( node - > content ) ) ;
# endif
} else
1998-11-27 06:39:50 +00:00
ret - > content = NULL ;
1999-05-29 11:51:49 +00:00
# ifndef XML_WITHOUT_CORBA
1998-11-27 06:39:50 +00:00
ret - > _private = NULL ;
ret - > vepv = NULL ;
# endif
if ( parent ! = NULL )
xmlAddChild ( parent , ret ) ;
if ( ! recursive ) return ( ret ) ;
if ( node - > nsDef ! = NULL )
ret - > nsDef = xmlCopyNamespaceList ( node - > nsDef ) ;
if ( node - > ns ! = NULL ) {
xmlNsPtr ns ;
ns = xmlSearchNs ( doc , ret , node - > ns - > prefix ) ;
if ( ns = = NULL ) {
/*
* Humm , we are copying an element whose namespace is defined
* out of the new tree scope . Search it in the original tree
* and add it at the top of the new tree
*/
ns = xmlSearchNs ( node - > doc , node , node - > ns - > prefix ) ;
if ( ns ! = NULL ) {
xmlNodePtr root = ret ;
while ( root - > parent ! = NULL ) root = root - > parent ;
xmlNewNs ( root , ns - > href , ns - > prefix ) ;
}
} else {
/*
* reference the existing namespace definition in our own tree .
*/
ret - > ns = ns ;
}
}
1999-08-29 21:02:19 +00:00
if ( node - > properties ! = NULL )
ret - > properties = xmlCopyPropList ( ret , node - > properties ) ;
1998-11-27 06:39:50 +00:00
if ( node - > childs ! = NULL )
ret - > childs = xmlStaticCopyNodeList ( node - > childs , doc , ret ) ;
1999-02-22 10:33:01 +00:00
UPDATE_LAST_CHILD ( ret )
1998-11-27 06:39:50 +00:00
return ( ret ) ;
}
static xmlNodePtr
xmlStaticCopyNodeList ( xmlNodePtr node , xmlDocPtr doc , xmlNodePtr parent ) {
xmlNodePtr ret = NULL ;
xmlNodePtr p = NULL , q ;
while ( node ! = NULL ) {
q = xmlStaticCopyNode ( node , doc , parent , 1 ) ;
if ( parent = = NULL ) {
if ( ret = = NULL ) ret = q ;
} else {
if ( ret = = NULL ) {
q - > prev = NULL ;
ret = p = q ;
} else {
p - > next = q ;
q - > prev = p ;
p = q ;
}
}
node = node - > next ;
}
return ( ret ) ;
}
/**
* xmlCopyNode :
* @ node : the node
* @ recursive : if 1 do a recursive copy .
*
* Do a copy of the node .
*
* Returns : a new xmlNodePtr , or NULL in case of error .
*/
xmlNodePtr
xmlCopyNode ( xmlNodePtr node , int recursive ) {
xmlNodePtr ret ;
ret = xmlStaticCopyNode ( node , NULL , NULL , recursive ) ;
return ( ret ) ;
}
/**
* xmlCopyNodeList :
* @ node : the first node in the list .
*
* Do a recursive copy of the node list .
*
* Returns : a new xmlNodePtr , or NULL in case of error .
*/
xmlNodePtr xmlCopyNodeList ( xmlNodePtr node ) {
xmlNodePtr ret = xmlStaticCopyNodeList ( node , NULL , NULL ) ;
return ( ret ) ;
}
/**
* xmlCopyElement :
* @ elem : the element
*
* Do a copy of the element definition .
*
* Returns : a new xmlElementPtr , or NULL in case of error .
xmlElementPtr
xmlCopyElement ( xmlElementPtr elem ) {
xmlElementPtr ret ;
if ( elem = = NULL ) return ( NULL ) ;
ret = xmlNewDocElement ( elem - > doc , elem - > ns , elem - > name , elem - > content ) ;
if ( ret = = NULL ) return ( NULL ) ;
if ( ! recursive ) return ( ret ) ;
if ( elem - > properties ! = NULL )
ret - > properties = xmlCopyPropList ( elem - > properties ) ;
if ( elem - > nsDef ! = NULL )
ret - > nsDef = xmlCopyNamespaceList ( elem - > nsDef ) ;
if ( elem - > childs ! = NULL )
ret - > childs = xmlCopyElementList ( elem - > childs ) ;
return ( ret ) ;
}
*/
/**
* xmlCopyDtd :
* @ dtd : the dtd
*
* Do a copy of the dtd .
*
* Returns : a new xmlDtdPtr , or NULL in case of error .
*/
xmlDtdPtr
xmlCopyDtd ( xmlDtdPtr dtd ) {
xmlDtdPtr ret ;
if ( dtd = = NULL ) return ( NULL ) ;
ret = xmlNewDtd ( NULL , dtd - > name , dtd - > ExternalID , dtd - > SystemID ) ;
if ( ret = = NULL ) return ( NULL ) ;
if ( dtd - > entities ! = NULL )
ret - > entities = ( void * ) xmlCopyEntitiesTable (
( xmlEntitiesTablePtr ) dtd - > entities ) ;
1999-02-22 10:33:01 +00:00
if ( dtd - > notations ! = NULL )
ret - > notations = ( void * ) xmlCopyNotationTable (
( xmlNotationTablePtr ) dtd - > notations ) ;
if ( dtd - > elements ! = NULL )
ret - > elements = ( void * ) xmlCopyElementTable (
( xmlElementTablePtr ) dtd - > elements ) ;
if ( dtd - > attributes ! = NULL )
ret - > attributes = ( void * ) xmlCopyAttributeTable (
( xmlAttributeTablePtr ) dtd - > attributes ) ;
1998-11-27 06:39:50 +00:00
return ( ret ) ;
}
/**
* xmlCopyDoc :
* @ doc : the document
* @ recursive : if 1 do a recursive copy .
*
* Do a copy of the document info . If recursive , the content tree will
* be copied too as well as Dtd , namespaces and entities .
*
* Returns : a new xmlDocPtr , or NULL in case of error .
*/
xmlDocPtr
xmlCopyDoc ( xmlDocPtr doc , int recursive ) {
xmlDocPtr ret ;
if ( doc = = NULL ) return ( NULL ) ;
ret = xmlNewDoc ( doc - > version ) ;
if ( ret = = NULL ) return ( NULL ) ;
if ( doc - > name ! = NULL )
1999-09-02 22:04:43 +00:00
ret - > name = xmlMemStrdup ( doc - > name ) ;
1998-11-27 06:39:50 +00:00
if ( doc - > encoding ! = NULL )
ret - > encoding = xmlStrdup ( doc - > encoding ) ;
ret - > compression = doc - > compression ;
ret - > standalone = doc - > standalone ;
if ( ! recursive ) return ( ret ) ;
1999-01-17 19:11:59 +00:00
if ( doc - > intSubset ! = NULL )
ret - > intSubset = xmlCopyDtd ( doc - > intSubset ) ;
1998-11-27 06:39:50 +00:00
if ( doc - > oldNs ! = NULL )
ret - > oldNs = xmlCopyNamespaceList ( doc - > oldNs ) ;
if ( doc - > root ! = NULL )
ret - > root = xmlStaticCopyNodeList ( doc - > root , ret , NULL ) ;
return ( ret ) ;
}
1998-08-13 03:39:55 +00:00
/************************************************************************
* *
* Content access functions *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-08-29 21:02:19 +00:00
/**
* xmlNodeSetLang :
* @ cur : the node being changed
* @ lang : the langage description
*
* Searches the language of a node , i . e . the values of the xml : lang
* attribute or the one carried by the nearest ancestor .
*/
void
1999-09-23 22:19:22 +00:00
xmlNodeSetLang ( xmlNodePtr cur , const xmlChar * lang ) {
1999-08-29 21:02:19 +00:00
/* TODO xmlNodeSetLang check against the production [33] LanguageID */
xmlSetProp ( cur , BAD_CAST " xml:lang " , lang ) ;
}
/**
* xmlNodeGetLang :
* @ cur : the node being checked
*
* Searches the language of a node , i . e . the values of the xml : lang
* attribute or the one carried by the nearest ancestor .
*
* Returns a pointer to the lang value , or NULL if not found
1999-11-24 18:04:22 +00:00
* It ' s up to the caller to free the memory .
1999-08-29 21:02:19 +00:00
*/
1999-11-24 18:04:22 +00:00
xmlChar *
1999-08-29 21:02:19 +00:00
xmlNodeGetLang ( xmlNodePtr cur ) {
1999-11-24 18:04:22 +00:00
xmlChar * lang ;
1999-08-29 21:02:19 +00:00
while ( cur ! = NULL ) {
lang = xmlGetProp ( cur , BAD_CAST " xml:lang " ) ;
if ( lang ! = NULL )
return ( lang ) ;
cur = cur - > parent ;
}
return ( NULL ) ;
}
1999-12-12 13:03:50 +00:00
/**
* xmlNodeGetBase :
* @ doc : the document the node pertains to
* @ cur : the node being checked
*
* Searches for the BASE URL . The code should work on both XML
* and HTML document even if base mechanisms are completely different .
*
* Returns a pointer to the base URL , or NULL if not found
* It ' s up to the caller to free the memory .
*/
xmlChar *
xmlNodeGetBase ( xmlDocPtr doc , xmlNodePtr cur ) {
xmlChar * base ;
if ( ( cur = = NULL ) & & ( doc = = NULL ) )
return ( NULL ) ;
if ( doc = = NULL ) doc = cur - > doc ;
if ( ( doc ! = NULL ) & & ( doc - > type = = XML_HTML_DOCUMENT_NODE ) ) {
cur = doc - > root ;
while ( ( cur ! = NULL ) & & ( cur - > name ! = NULL ) ) {
if ( cur - > type ! = XML_ELEMENT_NODE ) {
cur = cur - > next ;
continue ;
}
if ( ( ! xmlStrcmp ( cur - > name , BAD_CAST " html " ) ) | |
( ! xmlStrcmp ( cur - > name , BAD_CAST " HTML " ) ) ) {
cur = cur - > childs ;
continue ;
}
if ( ( ! xmlStrcmp ( cur - > name , BAD_CAST " head " ) ) | |
( ! xmlStrcmp ( cur - > name , BAD_CAST " HEAD " ) ) ) {
cur = cur - > childs ;
continue ;
}
if ( ( ! xmlStrcmp ( cur - > name , BAD_CAST " base " ) ) | |
( ! xmlStrcmp ( cur - > name , BAD_CAST " BASE " ) ) ) {
base = xmlGetProp ( cur , BAD_CAST " href " ) ;
if ( base ! = NULL ) return ( base ) ;
return ( xmlGetProp ( cur , BAD_CAST " HREF " ) ) ;
}
}
return ( NULL ) ;
}
while ( cur ! = NULL ) {
base = xmlGetProp ( cur , BAD_CAST " xml:base " ) ;
if ( base ! = NULL )
return ( base ) ;
cur = cur - > parent ;
}
return ( NULL ) ;
}
1998-10-28 22:58:05 +00:00
/**
* xmlNodeGetContent :
* @ cur : the node being read
*
* Read the value of a node , this can be either the text carried
* directly by this node if it ' s a TEXT node or the aggregate string
* of the values carried by this node child ' s ( TEXT and ENTITY_REF ) .
* Entity references are substitued .
1999-09-23 22:19:22 +00:00
* Returns a new xmlChar * or NULL if no content is available .
1999-04-21 20:12:07 +00:00
* It ' s up to the caller to free the memory .
1998-10-28 22:58:05 +00:00
*/
1999-09-23 22:19:22 +00:00
xmlChar *
1998-10-28 22:58:05 +00:00
xmlNodeGetContent ( xmlNodePtr cur ) {
if ( cur = = NULL ) return ( NULL ) ;
switch ( cur - > type ) {
case XML_DOCUMENT_FRAG_NODE :
case XML_ELEMENT_NODE :
return ( xmlNodeListGetString ( cur - > doc , cur - > childs , 1 ) ) ;
break ;
1999-08-29 21:02:19 +00:00
case XML_ATTRIBUTE_NODE : {
xmlAttrPtr attr = ( xmlAttrPtr ) cur ;
if ( attr - > node ! = NULL )
return ( xmlNodeListGetString ( attr - > node - > doc , attr - > val , 1 ) ) ;
else
return ( xmlNodeListGetString ( NULL , attr - > val , 1 ) ) ;
break ;
}
case XML_PI_NODE :
if ( cur - > content ! = NULL )
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-08-29 21:02:19 +00:00
return ( xmlStrdup ( cur - > content ) ) ;
1999-12-01 09:51:45 +00:00
# else
return ( xmlStrdup ( xmlBufferContent ( cur - > content ) ) ) ;
# endif
1999-08-29 21:02:19 +00:00
return ( NULL ) ;
1998-10-28 22:58:05 +00:00
case XML_ENTITY_REF_NODE :
case XML_ENTITY_NODE :
case XML_COMMENT_NODE :
case XML_DOCUMENT_NODE :
1999-10-14 09:10:25 +00:00
case XML_HTML_DOCUMENT_NODE :
1998-10-28 22:58:05 +00:00
case XML_DOCUMENT_TYPE_NODE :
case XML_NOTATION_NODE :
return ( NULL ) ;
1999-08-10 19:04:08 +00:00
case XML_CDATA_SECTION_NODE :
1998-10-28 22:58:05 +00:00
case XML_TEXT_NODE :
if ( cur - > content ! = NULL )
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1998-10-28 22:58:05 +00:00
return ( xmlStrdup ( cur - > content ) ) ;
1999-12-01 09:51:45 +00:00
# else
return ( xmlStrdup ( xmlBufferContent ( cur - > content ) ) ) ;
# endif
1998-10-28 22:58:05 +00:00
return ( NULL ) ;
}
return ( NULL ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlNodeSetContent :
* @ cur : the node being modified
* @ content : the new value of the content
*
* Replace the content of a node .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
1999-09-23 22:19:22 +00:00
xmlNodeSetContent ( xmlNodePtr cur , const xmlChar * content ) {
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNodeSetContent : node == NULL \n " ) ;
return ;
}
1998-10-28 22:58:05 +00:00
switch ( cur - > type ) {
case XML_DOCUMENT_FRAG_NODE :
case XML_ELEMENT_NODE :
if ( cur - > content ! = NULL ) {
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-09-02 22:04:43 +00:00
xmlFree ( cur - > content ) ;
1999-12-01 09:51:45 +00:00
# else
xmlBufferFree ( cur - > content ) ;
# endif
1998-10-28 22:58:05 +00:00
cur - > content = NULL ;
}
1999-09-02 22:04:43 +00:00
if ( cur - > childs ! = NULL ) xmlFreeNodeList ( cur - > childs ) ;
1998-10-28 22:58:05 +00:00
cur - > childs = xmlStringGetNodeList ( cur - > doc , content ) ;
1999-02-22 10:33:01 +00:00
UPDATE_LAST_CHILD ( cur )
1998-10-28 22:58:05 +00:00
break ;
case XML_ATTRIBUTE_NODE :
break ;
case XML_TEXT_NODE :
case XML_CDATA_SECTION_NODE :
case XML_ENTITY_REF_NODE :
case XML_ENTITY_NODE :
case XML_PI_NODE :
case XML_COMMENT_NODE :
1999-12-01 09:51:45 +00:00
if ( cur - > content ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
xmlFree ( cur - > content ) ;
# else
xmlBufferFree ( cur - > content ) ;
# endif
}
1999-09-02 22:04:43 +00:00
if ( cur - > childs ! = NULL ) xmlFreeNodeList ( cur - > childs ) ;
1999-01-17 19:11:59 +00:00
cur - > last = cur - > childs = NULL ;
1999-12-01 09:51:45 +00:00
if ( content ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
1998-10-28 22:58:05 +00:00
cur - > content = xmlStrdup ( content ) ;
1999-12-01 09:51:45 +00:00
# else
cur - > content = xmlBufferCreateSize ( 0 ) ;
xmlBufferSetAllocationScheme ( cur - > content ,
xmlGetBufferAllocationScheme ( ) ) ;
xmlBufferAdd ( cur - > content , content , - 1 ) ;
# endif
} else
1998-10-28 22:58:05 +00:00
cur - > content = NULL ;
1999-08-29 21:02:19 +00:00
break ;
1998-10-28 22:58:05 +00:00
case XML_DOCUMENT_NODE :
1999-10-14 09:10:25 +00:00
case XML_HTML_DOCUMENT_NODE :
1998-10-28 22:58:05 +00:00
case XML_DOCUMENT_TYPE_NODE :
break ;
case XML_NOTATION_NODE :
break ;
}
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
/**
* xmlNodeSetContentLen :
* @ cur : the node being modified
* @ content : the new value of the content
* @ len : the size of @ content
*
* Replace the content of a node .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
1999-09-23 22:19:22 +00:00
xmlNodeSetContentLen ( xmlNodePtr cur , const xmlChar * content , int len ) {
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
1998-10-28 22:58:05 +00:00
fprintf ( stderr , " xmlNodeSetContentLen : node == NULL \n " ) ;
1998-08-13 03:39:55 +00:00
return ;
}
1998-10-28 22:58:05 +00:00
switch ( cur - > type ) {
case XML_DOCUMENT_FRAG_NODE :
case XML_ELEMENT_NODE :
if ( cur - > content ! = NULL ) {
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-09-02 22:04:43 +00:00
xmlFree ( cur - > content ) ;
1999-12-01 09:51:45 +00:00
# else
xmlBufferFree ( cur - > content ) ;
# endif
1998-10-28 22:58:05 +00:00
cur - > content = NULL ;
}
1999-09-02 22:04:43 +00:00
if ( cur - > childs ! = NULL ) xmlFreeNodeList ( cur - > childs ) ;
1998-10-28 22:58:05 +00:00
cur - > childs = xmlStringLenGetNodeList ( cur - > doc , content , len ) ;
1999-02-22 10:33:01 +00:00
UPDATE_LAST_CHILD ( cur )
1998-10-28 22:58:05 +00:00
break ;
case XML_ATTRIBUTE_NODE :
break ;
case XML_TEXT_NODE :
case XML_CDATA_SECTION_NODE :
case XML_ENTITY_REF_NODE :
case XML_ENTITY_NODE :
case XML_PI_NODE :
case XML_COMMENT_NODE :
1999-12-01 09:51:45 +00:00
case XML_NOTATION_NODE :
if ( cur - > content ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
xmlFree ( cur - > content ) ;
# else
xmlBufferFree ( cur - > content ) ;
# endif
}
1999-09-02 22:04:43 +00:00
if ( cur - > childs ! = NULL ) xmlFreeNodeList ( cur - > childs ) ;
1999-01-17 19:11:59 +00:00
cur - > childs = cur - > last = NULL ;
1999-12-01 09:51:45 +00:00
if ( content ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
1998-10-28 22:58:05 +00:00
cur - > content = xmlStrndup ( content , len ) ;
1999-12-01 09:51:45 +00:00
# else
cur - > content = xmlBufferCreateSize ( len ) ;
xmlBufferSetAllocationScheme ( cur - > content ,
xmlGetBufferAllocationScheme ( ) ) ;
xmlBufferAdd ( cur - > content , content , len ) ;
# endif
} else
1998-10-28 22:58:05 +00:00
cur - > content = NULL ;
1999-08-29 21:02:19 +00:00
break ;
1998-10-28 22:58:05 +00:00
case XML_DOCUMENT_NODE :
1999-10-14 09:10:25 +00:00
case XML_HTML_DOCUMENT_NODE :
1998-10-28 22:58:05 +00:00
case XML_DOCUMENT_TYPE_NODE :
break ;
}
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
/**
1998-10-28 22:58:05 +00:00
* xmlNodeAddContentLen :
1998-10-20 06:14:16 +00:00
* @ cur : the node being modified
* @ content : extra content
1998-10-28 22:58:05 +00:00
* @ len : the size of @ content
1998-10-20 06:14:16 +00:00
*
* Append the extra substring to the node content .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
1999-09-23 22:19:22 +00:00
xmlNodeAddContentLen ( xmlNodePtr cur , const xmlChar * content , int len ) {
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
1998-10-28 22:58:05 +00:00
fprintf ( stderr , " xmlNodeAddContentLen : node == NULL \n " ) ;
1998-08-13 03:39:55 +00:00
return ;
}
1998-10-28 22:58:05 +00:00
if ( len < = 0 ) return ;
switch ( cur - > type ) {
case XML_DOCUMENT_FRAG_NODE :
case XML_ELEMENT_NODE : {
xmlNodePtr last = NULL , new ;
if ( cur - > childs ! = NULL ) {
1999-01-17 19:11:59 +00:00
last = cur - > last ;
1998-10-28 22:58:05 +00:00
} else {
if ( cur - > content ! = NULL ) {
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1998-10-28 22:58:05 +00:00
cur - > childs = xmlStringGetNodeList ( cur - > doc , cur - > content ) ;
1999-12-01 09:51:45 +00:00
# else
cur - > childs = xmlStringGetNodeList ( cur - > doc ,
xmlBufferContent ( cur - > content ) ) ;
# endif
1999-02-22 10:33:01 +00:00
UPDATE_LAST_CHILD ( cur )
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-09-02 22:04:43 +00:00
xmlFree ( cur - > content ) ;
1999-12-01 09:51:45 +00:00
# else
xmlBufferFree ( cur - > content ) ;
# endif
1998-10-28 22:58:05 +00:00
cur - > content = NULL ;
1999-01-17 19:11:59 +00:00
last = cur - > last ;
1998-10-28 22:58:05 +00:00
}
}
1999-01-17 19:11:59 +00:00
new = xmlNewTextLen ( content , len ) ;
1998-10-28 22:58:05 +00:00
if ( new ! = NULL ) {
xmlAddChild ( cur , new ) ;
1999-01-17 19:11:59 +00:00
if ( ( last ! = NULL ) & & ( last - > next = = new ) ) {
1998-10-28 22:58:05 +00:00
xmlTextMerge ( last , new ) ;
1999-01-17 19:11:59 +00:00
}
1998-10-28 22:58:05 +00:00
}
break ;
}
case XML_ATTRIBUTE_NODE :
break ;
case XML_TEXT_NODE :
case XML_CDATA_SECTION_NODE :
case XML_ENTITY_REF_NODE :
case XML_ENTITY_NODE :
case XML_PI_NODE :
case XML_COMMENT_NODE :
1999-12-01 09:51:45 +00:00
case XML_NOTATION_NODE :
if ( content ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
1998-10-28 22:58:05 +00:00
cur - > content = xmlStrncat ( cur - > content , content , len ) ;
1999-12-01 09:51:45 +00:00
# else
xmlBufferAdd ( cur - > content , content , len ) ;
# endif
}
1998-10-28 22:58:05 +00:00
case XML_DOCUMENT_NODE :
1999-10-14 09:10:25 +00:00
case XML_HTML_DOCUMENT_NODE :
1998-10-28 22:58:05 +00:00
case XML_DOCUMENT_TYPE_NODE :
break ;
}
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
/**
1998-10-28 22:58:05 +00:00
* xmlNodeAddContent :
1998-10-20 06:14:16 +00:00
* @ cur : the node being modified
* @ content : extra content
*
* Append the extra substring to the node content .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
1999-09-23 22:19:22 +00:00
xmlNodeAddContent ( xmlNodePtr cur , const xmlChar * content ) {
1998-10-28 22:58:05 +00:00
int len ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNodeAddContent : node == NULL \n " ) ;
return ;
}
1998-10-28 22:58:05 +00:00
if ( content = = NULL ) return ;
len = xmlStrlen ( content ) ;
xmlNodeAddContentLen ( cur , content , len ) ;
}
/**
* xmlTextMerge :
* @ first : the first text node
* @ second : the second text node being merged
*
* Merge two text nodes into one
1999-02-22 10:33:01 +00:00
* Returns the first text node augmented
1998-10-28 22:58:05 +00:00
*/
xmlNodePtr
xmlTextMerge ( xmlNodePtr first , xmlNodePtr second ) {
if ( first = = NULL ) return ( second ) ;
if ( second = = NULL ) return ( first ) ;
if ( first - > type ! = XML_TEXT_NODE ) return ( first ) ;
if ( second - > type ! = XML_TEXT_NODE ) return ( first ) ;
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1998-10-28 22:58:05 +00:00
xmlNodeAddContent ( first , second - > content ) ;
1999-12-01 09:51:45 +00:00
# else
xmlNodeAddContent ( first , xmlBufferContent ( second - > content ) ) ;
# endif
1998-10-28 22:58:05 +00:00
xmlUnlinkNode ( second ) ;
xmlFreeNode ( second ) ;
return ( first ) ;
1998-08-13 03:39:55 +00:00
}
1999-08-29 21:02:19 +00:00
/**
* xmlGetNsList :
* @ doc : the document
* @ node : the current node
*
* Search all the namespace applying to a given element .
* Returns an NULL terminated array of all the xmlNsPtr found
* that need to be freed by the caller or NULL if no
* namespace if defined
*/
xmlNsPtr *
xmlGetNsList ( xmlDocPtr doc , xmlNodePtr node ) {
xmlNsPtr cur ;
xmlNsPtr * ret = NULL ;
int nbns = 0 ;
int maxns = 10 ;
int i ;
while ( node ! = NULL ) {
cur = node - > nsDef ;
while ( cur ! = NULL ) {
if ( ret = = NULL ) {
1999-09-02 22:04:43 +00:00
ret = ( xmlNsPtr * ) xmlMalloc ( ( maxns + 1 ) * sizeof ( xmlNsPtr ) ) ;
1999-08-29 21:02:19 +00:00
if ( ret = = NULL ) {
fprintf ( stderr , " xmlGetNsList : out of memory! \n " ) ;
return ( NULL ) ;
}
ret [ nbns ] = NULL ;
}
for ( i = 0 ; i < nbns ; i + + ) {
if ( ( cur - > prefix = = ret [ i ] - > prefix ) | |
( ! xmlStrcmp ( cur - > prefix , ret [ i ] - > prefix ) ) ) break ;
}
if ( i > = nbns ) {
if ( nbns > = maxns ) {
maxns * = 2 ;
1999-09-02 22:04:43 +00:00
ret = ( xmlNsPtr * ) xmlRealloc ( ret ,
1999-08-29 21:02:19 +00:00
( maxns + 1 ) * sizeof ( xmlNsPtr ) ) ;
if ( ret = = NULL ) {
fprintf ( stderr , " xmlGetNsList : realloc failed! \n " ) ;
return ( NULL ) ;
}
}
ret [ nbns + + ] = cur ;
ret [ nbns ] = NULL ;
}
cur = cur - > next ;
}
node = node - > parent ;
}
return ( ret ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlSearchNs :
* @ doc : the document
* @ node : the current node
* @ nameSpace : the namespace string
1998-08-13 03:39:55 +00:00
*
1998-10-20 06:14:16 +00:00
* Search a Ns registered under a given name space for a document .
* 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 .
1999-02-22 10:33:01 +00:00
* Returns the namespace pointer or NULL .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNsPtr
1999-09-23 22:19:22 +00:00
xmlSearchNs ( xmlDocPtr doc , xmlNodePtr node , const xmlChar * nameSpace ) {
1998-08-13 03:39:55 +00:00
xmlNsPtr cur ;
1999-12-12 13:03:50 +00:00
if ( ( node = = NULL ) | | ( nameSpace = = NULL ) ) return ( NULL ) ;
1998-08-13 03:39:55 +00:00
while ( node ! = NULL ) {
cur = node - > nsDef ;
while ( cur ! = NULL ) {
if ( ( cur - > prefix = = NULL ) & & ( nameSpace = = NULL ) )
return ( cur ) ;
if ( ( cur - > prefix ! = NULL ) & & ( nameSpace ! = NULL ) & &
( ! xmlStrcmp ( cur - > prefix , nameSpace ) ) )
return ( cur ) ;
cur = cur - > next ;
}
node = node - > parent ;
}
1999-12-12 13:03:50 +00:00
#if 0
/* Removed support for old namespaces */
1998-08-13 03:39:55 +00:00
if ( doc ! = NULL ) {
cur = doc - > oldNs ;
while ( cur ! = NULL ) {
if ( ( cur - > prefix ! = NULL ) & & ( nameSpace ! = NULL ) & &
( ! xmlStrcmp ( cur - > prefix , nameSpace ) ) )
return ( cur ) ;
cur = cur - > next ;
}
}
1999-12-12 13:03:50 +00:00
# endif
1998-08-13 03:39:55 +00:00
return ( NULL ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlSearchNsByHref :
* @ doc : the document
* @ 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 .
1999-02-22 10:33:01 +00:00
* Returns the namespace pointer or NULL .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlNsPtr
1999-09-23 22:19:22 +00:00
xmlSearchNsByHref ( xmlDocPtr doc , xmlNodePtr node , const xmlChar * href ) {
1998-08-13 03:39:55 +00:00
xmlNsPtr cur ;
1999-12-12 13:03:50 +00:00
if ( ( node = = NULL ) | | ( href = = NULL ) ) return ( NULL ) ;
1998-08-13 03:39:55 +00:00
while ( node ! = NULL ) {
cur = node - > nsDef ;
while ( cur ! = NULL ) {
if ( ( cur - > href ! = NULL ) & & ( href ! = NULL ) & &
( ! xmlStrcmp ( cur - > href , href ) ) )
return ( cur ) ;
cur = cur - > next ;
}
node = node - > parent ;
}
1999-12-12 13:03:50 +00:00
#if 0
/* Removed support for old namespaces */
1998-08-13 03:39:55 +00:00
if ( doc ! = NULL ) {
cur = doc - > oldNs ;
while ( cur ! = NULL ) {
if ( ( cur - > href ! = NULL ) & & ( href ! = NULL ) & &
( ! xmlStrcmp ( cur - > href , href ) ) )
return ( cur ) ;
cur = cur - > next ;
}
}
1999-12-12 13:03:50 +00:00
# endif
1998-08-13 03:39:55 +00:00
return ( NULL ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlGetProp :
* @ node : the node
* @ name : the attribute name
*
* Search and get the value of an attribute associated to a node
1998-10-27 06:21:04 +00:00
* This does the entity substitution .
1999-12-12 13:03:50 +00:00
* This function looks in DTD attribute declaration for # FIXED or
* default declaration values unless DTD use has been turned off .
*
1999-02-22 10:33:01 +00:00
* Returns the attribute value or NULL if not found .
1999-11-24 18:04:22 +00:00
* It ' s up to the caller to free the memory .
1998-08-13 03:39:55 +00:00
*/
1999-11-24 18:04:22 +00:00
xmlChar *
xmlGetProp ( xmlNodePtr node , const xmlChar * name ) {
1999-12-12 13:03:50 +00:00
xmlAttrPtr prop ;
xmlDocPtr doc ;
1998-08-13 03:39:55 +00:00
1999-12-12 13:03:50 +00:00
if ( ( node = = NULL ) | | ( name = = NULL ) ) return ( NULL ) ;
/*
* Check on the properties attached to the node
*/
prop = node - > properties ;
1998-08-13 03:39:55 +00:00
while ( prop ! = NULL ) {
1999-02-08 18:34:36 +00:00
if ( ! xmlStrcmp ( prop - > name , name ) ) {
1999-09-23 22:19:22 +00:00
xmlChar * ret ;
1999-02-08 18:33:22 +00:00
ret = xmlNodeListGetString ( node - > doc , prop - > val , 1 ) ;
1999-09-23 22:19:22 +00:00
if ( ret = = NULL ) return ( xmlStrdup ( ( xmlChar * ) " " ) ) ;
1999-02-08 18:33:22 +00:00
return ( ret ) ;
1999-02-08 18:34:36 +00:00
}
1998-08-13 03:39:55 +00:00
prop = prop - > next ;
}
1999-12-12 13:03:50 +00:00
if ( ! xmlCheckDTD ) return ( NULL ) ;
/*
* Check if there is a default declaration in the internal
* or external subsets
*/
doc = node - > doc ;
if ( doc ! = NULL ) {
xmlAttributePtr attrDecl ;
if ( doc - > intSubset ! = NULL ) {
attrDecl = xmlGetDtdAttrDesc ( doc - > intSubset , node - > name , name ) ;
if ( ( attrDecl = = NULL ) & & ( doc - > extSubset ! = NULL ) )
attrDecl = xmlGetDtdAttrDesc ( doc - > extSubset , node - > name , name ) ;
return ( xmlStrdup ( attrDecl - > defaultValue ) ) ;
}
}
return ( NULL ) ;
}
/**
* xmlGetNsProp :
* @ node : the node
* @ name : the attribute name
* @ namespace : the URI of the namespace
*
* Search and get the value of an attribute associated to a node
* This attribute has to be anchored in the namespace specified .
* This does the entity substitution .
* This function looks in DTD attribute declaration for # FIXED or
* default declaration values unless DTD use has been turned off .
*
* Returns the attribute value or NULL if not found .
* It ' s up to the caller to free the memory .
*/
xmlChar *
xmlGetNsProp ( xmlNodePtr node , const xmlChar * name , const xmlChar * namespace ) {
xmlAttrPtr prop = node - > properties ;
xmlDocPtr doc ;
xmlNsPtr ns ;
if ( namespace = = NULL )
return ( xmlGetProp ( node , name ) ) ;
while ( prop ! = NULL ) {
if ( ( ! xmlStrcmp ( prop - > name , name ) ) & &
( prop - > ns ! = NULL ) & & ( ! xmlStrcmp ( prop - > ns - > href , namespace ) ) ) {
xmlChar * ret ;
ret = xmlNodeListGetString ( node - > doc , prop - > val , 1 ) ;
if ( ret = = NULL ) return ( xmlStrdup ( ( xmlChar * ) " " ) ) ;
return ( ret ) ;
}
prop = prop - > next ;
}
if ( ! xmlCheckDTD ) return ( NULL ) ;
/*
* Check if there is a default declaration in the internal
* or external subsets
*/
doc = node - > doc ;
if ( doc ! = NULL ) {
xmlAttributePtr attrDecl ;
if ( doc - > intSubset ! = NULL ) {
attrDecl = xmlGetDtdAttrDesc ( doc - > intSubset , node - > name , name ) ;
if ( ( attrDecl = = NULL ) & & ( doc - > extSubset ! = NULL ) )
attrDecl = xmlGetDtdAttrDesc ( doc - > extSubset , node - > name , name ) ;
if ( attrDecl - > prefix ! = NULL ) {
/*
* The DTD declaration only allows a prefix search
*/
ns = xmlSearchNs ( doc , node , attrDecl - > prefix ) ;
if ( ( ns ! = NULL ) & & ( ! xmlStrcmp ( ns - > href , namespace ) ) )
return ( xmlStrdup ( attrDecl - > defaultValue ) ) ;
}
}
}
1998-08-13 03:39:55 +00:00
return ( NULL ) ;
}
1998-10-20 06:14:16 +00:00
/**
1998-10-27 06:21:04 +00:00
* xmlSetProp :
1998-10-20 06:14:16 +00:00
* @ node : the node
* @ name : the attribute name
* @ value : the attribute value
*
* Set ( or reset ) an attribute carried by a node .
1999-02-22 10:33:01 +00:00
* Returns the attribute pointer .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
xmlAttrPtr
1999-09-23 22:19:22 +00:00
xmlSetProp ( xmlNodePtr node , const xmlChar * name , const xmlChar * value ) {
1998-08-13 03:39:55 +00:00
xmlAttrPtr prop = node - > properties ;
while ( prop ! = NULL ) {
if ( ! xmlStrcmp ( prop - > name , name ) ) {
1998-10-27 06:21:04 +00:00
if ( prop - > val ! = NULL )
1999-09-02 22:04:43 +00:00
xmlFreeNodeList ( prop - > val ) ;
1998-10-27 06:21:04 +00:00
prop - > val = NULL ;
1999-11-12 17:02:31 +00:00
if ( value ! = NULL ) {
xmlChar * buffer ;
buffer = xmlEncodeEntitiesReentrant ( node - > doc , value ) ;
prop - > val = xmlStringGetNodeList ( node - > doc , buffer ) ;
xmlFree ( buffer ) ;
}
1998-08-13 03:39:55 +00:00
return ( prop ) ;
}
prop = prop - > next ;
}
prop = xmlNewProp ( node , name , value ) ;
return ( prop ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlNodeIsText :
* @ node : the node
*
* Is this node a Text node ?
1999-02-22 10:33:01 +00:00
* Returns 1 yes , 0 no
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
int
xmlNodeIsText ( xmlNodePtr node ) {
1998-08-13 03:39:55 +00:00
if ( node = = NULL ) return ( 0 ) ;
1998-10-14 02:36:47 +00:00
if ( node - > type = = XML_TEXT_NODE ) return ( 1 ) ;
1998-08-13 03:39:55 +00:00
return ( 0 ) ;
}
1998-10-20 06:14:16 +00:00
/**
1999-02-22 10:33:01 +00:00
* xmlTextConcat :
1998-10-20 06:14:16 +00:00
* @ node : the node
* @ content : the content
* @ len : @ content lenght
*
* Concat the given string at the end of the existing node content
1998-08-13 03:39:55 +00:00
*/
1998-10-20 06:14:16 +00:00
1998-10-27 22:56:57 +00:00
void
1999-09-23 22:19:22 +00:00
xmlTextConcat ( xmlNodePtr node , const xmlChar * content , int len ) {
1998-08-13 03:39:55 +00:00
if ( node = = NULL ) return ;
1998-10-14 02:36:47 +00:00
if ( node - > type ! = XML_TEXT_NODE ) {
1998-08-13 03:39:55 +00:00
fprintf ( stderr , " xmlTextConcat: node is not text \n " ) ;
return ;
}
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1998-08-13 03:39:55 +00:00
node - > content = xmlStrncat ( node - > content , content , len ) ;
1999-12-01 09:51:45 +00:00
# else
xmlBufferAdd ( node - > content , content , len ) ;
# endif
1998-08-13 03:39:55 +00:00
}
/************************************************************************
* *
* Output : to a FILE or in memory *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-04-21 20:12:07 +00:00
# define BASE_BUFFER_SIZE 4000
1998-08-13 03:39:55 +00:00
1998-10-20 06:14:16 +00:00
/**
1999-04-21 20:12:07 +00:00
* xmlBufferCreate :
1998-10-20 06:14:16 +00:00
*
1999-04-21 20:12:07 +00:00
* routine to create an XML buffer .
* returns the new structure .
*/
xmlBufferPtr
xmlBufferCreate ( void ) {
xmlBufferPtr ret ;
1999-09-02 22:04:43 +00:00
ret = ( xmlBufferPtr ) xmlMalloc ( sizeof ( xmlBuffer ) ) ;
1999-04-21 20:12:07 +00:00
if ( ret = = NULL ) {
fprintf ( stderr , " xmlBufferCreate : out of memory! \n " ) ;
return ( NULL ) ;
}
ret - > use = 0 ;
ret - > size = BASE_BUFFER_SIZE ;
1999-12-12 13:03:50 +00:00
ret - > alloc = xmlBufferAllocScheme ;
1999-09-23 22:19:22 +00:00
ret - > content = ( xmlChar * ) xmlMalloc ( ret - > size * sizeof ( xmlChar ) ) ;
1999-04-21 20:12:07 +00:00
if ( ret - > content = = NULL ) {
fprintf ( stderr , " xmlBufferCreate : out of memory! \n " ) ;
1999-09-02 22:04:43 +00:00
xmlFree ( ret ) ;
1999-04-21 20:12:07 +00:00
return ( NULL ) ;
}
ret - > content [ 0 ] = 0 ;
return ( ret ) ;
}
1999-12-01 09:51:45 +00:00
/**
* xmlBufferCreateSize :
* @ size : initial size of buffer
*
* routine to create an XML buffer .
* returns the new structure .
*/
xmlBufferPtr
xmlBufferCreateSize ( size_t size ) {
xmlBufferPtr ret ;
ret = ( xmlBufferPtr ) xmlMalloc ( sizeof ( xmlBuffer ) ) ;
if ( ret = = NULL ) {
fprintf ( stderr , " xmlBufferCreate : out of memory! \n " ) ;
return ( NULL ) ;
}
ret - > use = 0 ;
1999-12-12 13:03:50 +00:00
ret - > alloc = xmlBufferAllocScheme ;
1999-12-01 09:51:45 +00:00
ret - > size = ( size ? size + 2 : 0 ) ; /* +1 for ending null */
1999-12-12 13:03:50 +00:00
if ( ret - > size ) {
1999-12-01 09:51:45 +00:00
ret - > content = ( xmlChar * ) xmlMalloc ( ret - > size * sizeof ( xmlChar ) ) ;
if ( ret - > content = = NULL ) {
fprintf ( stderr , " xmlBufferCreate : out of memory! \n " ) ;
xmlFree ( ret ) ;
return ( NULL ) ;
}
ret - > content [ 0 ] = 0 ;
} else
ret - > content = NULL ;
return ( ret ) ;
}
/**
* xmlBufferAllocationScheme :
* @ buf : the buffer to free
* @ scheme : allocation scheme to use
*
* Sets the allocation scheme for this buffer
*/
void
xmlBufferSetAllocationScheme ( xmlBufferPtr buf ,
xmlBufferAllocationScheme scheme ) {
if ( buf = = NULL ) {
fprintf ( stderr , " xmlBufferSetAllocationScheme: buf == NULL \n " ) ;
return ;
}
buf - > alloc = scheme ;
}
1999-04-21 20:12:07 +00:00
/**
* xmlBufferFree :
* @ buf : the buffer to free
*
* Frees an XML buffer .
1998-10-20 06:14:16 +00:00
*/
1998-10-27 22:56:57 +00:00
void
1999-04-21 20:12:07 +00:00
xmlBufferFree ( xmlBufferPtr buf ) {
if ( buf = = NULL ) {
fprintf ( stderr , " xmlBufferFree: buf == NULL \n " ) ;
return ;
}
1999-12-01 09:51:45 +00:00
if ( buf - > content ! = NULL ) {
# ifndef XML_USE_BUFFER_CONTENT
1999-04-21 20:12:07 +00:00
memset ( buf - > content , - 1 , BASE_BUFFER_SIZE ) ;
1999-12-01 09:51:45 +00:00
# else
memset ( buf - > content , - 1 , buf - > size ) ;
# endif
1999-09-02 22:04:43 +00:00
xmlFree ( buf - > content ) ;
1999-04-21 20:12:07 +00:00
}
memset ( buf , - 1 , sizeof ( xmlBuffer ) ) ;
1999-09-02 22:04:43 +00:00
xmlFree ( buf ) ;
1999-04-21 20:12:07 +00:00
}
1999-07-27 19:52:06 +00:00
/**
* xmlBufferEmpty :
* @ buf : the buffer
*
* empty a buffer .
*/
void
xmlBufferEmpty ( xmlBufferPtr buf ) {
buf - > use = 0 ;
memset ( buf - > content , - 1 , buf - > size ) ; /* just for debug */
}
/**
* xmlBufferShrink :
* @ buf : the buffer to dump
1999-09-23 22:19:22 +00:00
* @ len : the number of xmlChar to remove
1999-07-27 19:52:06 +00:00
*
* Remove the beginning of an XML buffer .
*
1999-09-23 22:19:22 +00:00
* Returns the number of xmlChar removed , or - 1 in case of failure .
1999-07-27 19:52:06 +00:00
*/
int
xmlBufferShrink ( xmlBufferPtr buf , int len ) {
if ( len = = 0 ) return ( 0 ) ;
if ( len > buf - > use ) return ( - 1 ) ;
buf - > use - = len ;
1999-09-23 22:19:22 +00:00
memmove ( buf - > content , & buf - > content [ len ] , buf - > use * sizeof ( xmlChar ) ) ;
1999-07-27 19:52:06 +00:00
buf - > content [ buf - > use ] = 0 ;
return ( len ) ;
}
1999-04-21 20:12:07 +00:00
/**
* xmlBufferDump :
* @ file : the file output
* @ buf : the buffer to dump
*
* Dumps an XML buffer to a FILE * .
1999-09-23 22:19:22 +00:00
* Returns the number of xmlChar written
1999-04-21 20:12:07 +00:00
*/
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 ;
1999-09-23 22:19:22 +00:00
ret = fwrite ( buf - > content , sizeof ( xmlChar ) , buf - > use , file ) ;
1999-04-21 20:12:07 +00:00
return ( ret ) ;
}
1999-12-01 09:51:45 +00:00
/**
* xmlBufferContent :
* @ buf : the buffer to resize
*
* Returns the internal content
*/
const xmlChar *
xmlBufferContent ( const xmlBufferPtr buf )
{
if ( ! buf )
return NULL ;
return buf - > content ;
}
/**
* xmlBufferLength :
* @ buf : the buffer
*
* Returns the length of data in the internal content
*/
int
xmlBufferLength ( const xmlBufferPtr buf )
{
if ( ! buf )
return 0 ;
return buf - > use ;
}
/**
* xmlBufferResize :
* @ buf : the buffer to resize
* @ len : the desired size
*
* Resize a buffer to accomodate minimum size of < len > .
*
* Returns 0 in case of problems , 1 otherwise
*/
int
xmlBufferResize ( xmlBufferPtr buf , int size )
{
int newSize = ( buf - > size ? buf - > size * 2 : size ) ; /*take care of empty case*/
xmlChar * rebuf = NULL ;
/* Don't resize if we don't have to */
if ( size < buf - > size )
return 1 ;
/* figure out new size */
switch ( buf - > alloc ) {
case XML_BUFFER_ALLOC_DOUBLEIT :
while ( size > newSize ) newSize * = 2 ;
break ;
case XML_BUFFER_ALLOC_EXACT :
newSize = size + 10 ;
break ;
default :
newSize = size + 10 ;
break ;
}
if ( buf - > content = = NULL )
rebuf = ( xmlChar * ) xmlMalloc ( newSize * sizeof ( xmlChar ) ) ;
else
rebuf = ( xmlChar * ) xmlRealloc ( buf - > content ,
newSize * sizeof ( xmlChar ) ) ;
if ( rebuf = = NULL ) {
fprintf ( stderr , " xmlBufferAdd : out of memory! \n " ) ;
return 0 ;
}
buf - > content = rebuf ;
buf - > size = newSize ;
return 1 ;
}
1999-04-21 20:12:07 +00:00
/**
* xmlBufferAdd :
* @ buf : the buffer to dump
1999-09-23 22:19:22 +00:00
* @ str : the xmlChar string
* @ len : the number of xmlChar to add
1999-04-21 20:12:07 +00:00
*
1999-12-12 13:03:50 +00:00
* Add a string range to an XML buffer . if len = = - 1 , the lenght of
* str is recomputed .
1999-04-21 20:12:07 +00:00
*/
void
1999-09-23 22:19:22 +00:00
xmlBufferAdd ( xmlBufferPtr buf , const xmlChar * str , int len ) {
1999-12-01 09:51:45 +00:00
int l , needSize ;
1998-08-13 03:39:55 +00:00
1999-04-21 20:12:07 +00:00
if ( str = = NULL ) {
fprintf ( stderr , " xmlBufferAdd: str == NULL \n " ) ;
return ;
}
1999-12-12 13:03:50 +00:00
if ( len < - 1 ) {
fprintf ( stderr , " xmlBufferAdd: len < 0 \n " ) ;
return ;
}
if ( len = = 0 ) return ;
1999-12-01 09:51:45 +00:00
/* CJN What's this for??? */
1999-07-27 19:52:06 +00:00
l = xmlStrlen ( str ) ;
1999-12-01 09:51:45 +00:00
if ( l < len ) { len = l ; printf ( " xmlBufferAdd bad length \n " ) ; }
1999-04-21 20:12:07 +00:00
1999-12-01 09:51:45 +00:00
/* CJN 11.18.99 okay, now I'm using the length */
if ( len = = - 1 ) len = l ;
1999-07-27 19:52:06 +00:00
1999-12-01 09:51:45 +00:00
if ( len < = 0 ) return ;
needSize = buf - > use + len + 2 ;
if ( needSize > buf - > size ) {
if ( ! xmlBufferResize ( buf , needSize ) ) {
fprintf ( stderr , " xmlBufferAdd : out of memory! \n " ) ;
return ;
}
1998-08-13 03:39:55 +00:00
}
1999-12-01 09:51:45 +00:00
memmove ( & buf - > content [ buf - > use ] , str , len * sizeof ( xmlChar ) ) ;
1999-07-27 19:52:06 +00:00
buf - > use + = len ;
buf - > content [ buf - > use ] = 0 ;
1999-04-21 20:12:07 +00:00
}
/**
* xmlBufferCat :
* @ buf : the buffer to dump
1999-09-23 22:19:22 +00:00
* @ str : the xmlChar string
1999-04-21 20:12:07 +00:00
*
* Append a zero terminated string to an XML buffer .
*/
void
1999-09-23 22:19:22 +00:00
xmlBufferCat ( xmlBufferPtr buf , const xmlChar * str ) {
1999-12-01 09:51:45 +00:00
if ( str ! = NULL )
xmlBufferAdd ( buf , str , - 1 ) ;
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
/**
1999-04-21 20:12:07 +00:00
* xmlBufferCCat :
* @ buf : the buffer to dump
* @ str : the C char string
1998-10-20 06:14:16 +00:00
*
1999-04-21 20:12:07 +00:00
* Append a zero terminated C string to an XML buffer .
1998-10-20 06:14:16 +00:00
*/
1998-10-27 22:56:57 +00:00
void
1999-04-21 20:12:07 +00:00
xmlBufferCCat ( xmlBufferPtr buf , const char * str ) {
1998-08-13 03:39:55 +00:00
const char * cur ;
1999-04-21 20:12:07 +00:00
if ( str = = NULL ) {
fprintf ( stderr , " xmlBufferAdd: str == NULL \n " ) ;
return ;
1998-08-13 03:39:55 +00:00
}
1999-04-21 20:12:07 +00:00
for ( cur = str ; * cur ! = 0 ; cur + + ) {
if ( buf - > use + 10 > = buf - > size ) {
1999-12-01 09:51:45 +00:00
if ( ! xmlBufferResize ( buf , buf - > use + 10 ) ) {
fprintf ( stderr , " xmlBufferCCat : out of memory! \n " ) ;
return ;
}
}
1999-04-21 20:12:07 +00:00
buf - > content [ buf - > use + + ] = * cur ;
1998-08-13 03:39:55 +00:00
}
}
1999-04-21 20:12:07 +00:00
/**
* xmlBufferWriteCHAR :
* @ buf : the XML buffer
* @ string : the string to add
*
* routine which manage and grows an output buffer . This one add
1999-09-23 22:19:22 +00:00
* xmlChars at the end of the buffer .
1999-04-21 20:12:07 +00:00
*/
void
1999-09-23 22:19:22 +00:00
xmlBufferWriteCHAR ( xmlBufferPtr buf , const xmlChar * string ) {
1999-04-21 20:12:07 +00:00
xmlBufferCat ( buf , string ) ;
}
/**
* xmlBufferWriteChar :
1999-06-02 17:44:04 +00:00
* @ buf : the XML buffer output
1999-04-21 20:12:07 +00:00
* @ 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 ( xmlBufferPtr buf , const char * string ) {
xmlBufferCCat ( buf , string ) ;
}
1999-06-02 17:44:04 +00:00
/**
* xmlBufferWriteQuotedString :
* @ buf : the XML buffer output
* @ string : the string to add
*
* routine which manage and grows an output buffer . This one writes
1999-09-23 22:19:22 +00:00
* a quoted or double quoted xmlChar string , checking first if it holds
1999-06-02 17:44:04 +00:00
* quote or double - quotes internally
*/
void
1999-09-23 22:19:22 +00:00
xmlBufferWriteQuotedString ( xmlBufferPtr buf , const xmlChar * string ) {
1999-08-29 21:02:19 +00:00
if ( xmlStrchr ( string , ' " ' ) ) {
if ( xmlStrchr ( string , ' \' ' ) ) {
1999-06-02 17:44:04 +00:00
fprintf ( stderr ,
" xmlBufferWriteQuotedString: string contains quote and double-quotes ! \n " ) ;
}
xmlBufferCCat ( buf , " ' " ) ;
xmlBufferCat ( buf , string ) ;
xmlBufferCCat ( buf , " ' " ) ;
} else {
xmlBufferCCat ( buf , " \" " ) ;
xmlBufferCat ( buf , string ) ;
xmlBufferCCat ( buf , " \" " ) ;
}
}
1998-10-20 06:14:16 +00:00
/**
* xmlGlobalNsDump :
1999-06-02 17:44:04 +00:00
* @ buf : the XML buffer output
1998-10-20 06:14:16 +00:00
* @ cur : a namespace
*
* Dump a global Namespace , this is the old version based on PIs .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
static void
1999-04-21 20:12:07 +00:00
xmlGlobalNsDump ( xmlBufferPtr buf , xmlNsPtr cur ) {
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlGlobalNsDump : Ns == NULL \n " ) ;
return ;
}
if ( cur - > type = = XML_GLOBAL_NAMESPACE ) {
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " <?namespace " ) ;
1998-08-13 03:39:55 +00:00
if ( cur - > href ! = NULL ) {
1999-06-02 17:44:04 +00:00
xmlBufferWriteChar ( buf , " href= " ) ;
xmlBufferWriteQuotedString ( buf , cur - > href ) ;
1998-08-13 03:39:55 +00:00
}
if ( cur - > prefix ! = NULL ) {
1999-06-02 17:44:04 +00:00
xmlBufferWriteChar ( buf , " AS= " ) ;
xmlBufferWriteQuotedString ( buf , cur - > prefix ) ;
1998-08-13 03:39:55 +00:00
}
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " ?> \n " ) ;
1998-08-13 03:39:55 +00:00
}
}
1998-10-20 06:14:16 +00:00
/**
* xmlGlobalNsListDump :
1999-06-02 17:44:04 +00:00
* @ buf : the XML buffer output
1998-10-20 06:14:16 +00:00
* @ cur : the first namespace
*
* Dump a list of global Namespace , this is the old version based on PIs .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
static void
1999-04-21 20:12:07 +00:00
xmlGlobalNsListDump ( xmlBufferPtr buf , xmlNsPtr cur ) {
1998-08-13 03:39:55 +00:00
while ( cur ! = NULL ) {
1999-04-21 20:12:07 +00:00
xmlGlobalNsDump ( buf , cur ) ;
1998-08-13 03:39:55 +00:00
cur = cur - > next ;
}
}
1998-10-20 06:14:16 +00:00
/**
* xmlNsDump :
1999-06-02 17:44:04 +00:00
* @ buf : the XML buffer output
1998-10-20 06:14:16 +00:00
* @ cur : a namespace
*
1998-08-13 03:39:55 +00:00
* Dump a local Namespace definition .
1998-10-20 06:14:16 +00:00
* Should be called in the context of attributes dumps .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
static void
1999-04-21 20:12:07 +00:00
xmlNsDump ( xmlBufferPtr buf , xmlNsPtr cur ) {
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNsDump : Ns == NULL \n " ) ;
return ;
}
if ( cur - > type = = XML_LOCAL_NAMESPACE ) {
/* Within the context of an element attributes */
if ( cur - > prefix ! = NULL ) {
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " xmlns: " ) ;
xmlBufferWriteCHAR ( buf , cur - > prefix ) ;
1998-08-13 03:39:55 +00:00
} else
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " xmlns " ) ;
1999-06-02 17:44:04 +00:00
xmlBufferWriteChar ( buf , " = " ) ;
xmlBufferWriteQuotedString ( buf , cur - > href ) ;
1998-08-13 03:39:55 +00:00
}
}
1998-10-20 06:14:16 +00:00
/**
* xmlNsListDump :
1999-06-02 17:44:04 +00:00
* @ buf : the XML buffer output
1998-10-20 06:14:16 +00:00
* @ cur : the first namespace
*
* Dump a list of local Namespace definitions .
* Should be called in the context of attributes dumps .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
static void
1999-04-21 20:12:07 +00:00
xmlNsListDump ( xmlBufferPtr buf , xmlNsPtr cur ) {
1998-08-13 03:39:55 +00:00
while ( cur ! = NULL ) {
1999-04-21 20:12:07 +00:00
xmlNsDump ( buf , cur ) ;
1998-08-13 03:39:55 +00:00
cur = cur - > next ;
}
}
1998-10-20 06:14:16 +00:00
/**
* xmlDtdDump :
1999-06-02 17:44:04 +00:00
* @ buf : the XML buffer output
1998-10-20 06:14:16 +00:00
* @ doc : the document
*
* Dump the XML document DTD , if any .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
static void
1999-04-21 20:12:07 +00:00
xmlDtdDump ( xmlBufferPtr buf , xmlDocPtr doc ) {
1999-01-17 19:11:59 +00:00
xmlDtdPtr cur = doc - > intSubset ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
1999-01-17 19:11:59 +00:00
fprintf ( stderr , " xmlDtdDump : no internal subset \n " ) ;
1998-08-13 03:39:55 +00:00
return ;
}
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " <!DOCTYPE " ) ;
xmlBufferWriteCHAR ( buf , cur - > name ) ;
1998-08-13 03:39:55 +00:00
if ( cur - > ExternalID ! = NULL ) {
1999-06-02 17:44:04 +00:00
xmlBufferWriteChar ( buf , " PUBLIC " ) ;
xmlBufferWriteQuotedString ( buf , cur - > ExternalID ) ;
xmlBufferWriteChar ( buf , " " ) ;
xmlBufferWriteQuotedString ( buf , cur - > SystemID ) ;
1998-08-13 03:39:55 +00:00
} else if ( cur - > SystemID ! = NULL ) {
1999-06-02 17:44:04 +00:00
xmlBufferWriteChar ( buf , " SYSTEM " ) ;
xmlBufferWriteQuotedString ( buf , cur - > SystemID ) ;
1998-08-13 03:39:55 +00:00
}
1999-02-22 10:33:01 +00:00
if ( ( cur - > entities = = NULL ) & & ( cur - > elements = = NULL ) & &
( cur - > attributes = = NULL ) & & ( cur - > notations = = NULL ) ) {
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " > \n " ) ;
1998-08-13 03:39:55 +00:00
return ;
}
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " [ \n " ) ;
1998-08-13 03:39:55 +00:00
if ( cur - > entities ! = NULL )
1999-04-21 20:12:07 +00:00
xmlDumpEntitiesTable ( buf , ( xmlEntitiesTablePtr ) cur - > entities ) ;
1999-02-22 10:33:01 +00:00
if ( cur - > notations ! = NULL )
1999-04-21 20:12:07 +00:00
xmlDumpNotationTable ( buf , ( xmlNotationTablePtr ) cur - > notations ) ;
1999-01-31 22:15:06 +00:00
if ( cur - > elements ! = NULL )
1999-04-21 20:12:07 +00:00
xmlDumpElementTable ( buf , ( xmlElementTablePtr ) cur - > elements ) ;
1999-02-22 10:33:01 +00:00
if ( cur - > attributes ! = NULL )
1999-04-21 20:12:07 +00:00
xmlDumpAttributeTable ( buf , ( xmlAttributeTablePtr ) cur - > attributes ) ;
xmlBufferWriteChar ( buf , " ] " ) ;
1998-08-13 03:39:55 +00:00
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " > \n " ) ;
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
/**
* xmlAttrDump :
1999-06-02 17:44:04 +00:00
* @ buf : the XML buffer output
1998-10-20 06:14:16 +00:00
* @ doc : the document
* @ cur : the attribute pointer
*
* Dump an XML attribute
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
static void
1999-04-21 20:12:07 +00:00
xmlAttrDump ( xmlBufferPtr buf , xmlDocPtr doc , xmlAttrPtr cur ) {
1999-09-23 22:19:22 +00:00
xmlChar * value ;
1998-10-27 06:21:04 +00:00
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlAttrDump : property == NULL \n " ) ;
return ;
}
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " " ) ;
1999-08-29 21:02:19 +00:00
if ( ( cur - > ns ! = NULL ) & & ( cur - > ns - > prefix ! = NULL ) ) {
xmlBufferWriteCHAR ( buf , cur - > ns - > prefix ) ;
xmlBufferWriteChar ( buf , " : " ) ;
}
1999-04-21 20:12:07 +00:00
xmlBufferWriteCHAR ( buf , cur - > name ) ;
1998-10-27 06:21:04 +00:00
value = xmlNodeListGetString ( doc , cur - > val , 0 ) ;
if ( value ) {
1999-06-02 17:44:04 +00:00
xmlBufferWriteChar ( buf , " = " ) ;
xmlBufferWriteQuotedString ( buf , value ) ;
1999-09-02 22:04:43 +00:00
xmlFree ( value ) ;
1999-02-08 15:13:10 +00:00
} else {
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " = \" \" " ) ;
1998-08-13 03:39:55 +00:00
}
}
1998-10-20 06:14:16 +00:00
/**
* xmlAttrListDump :
1999-06-02 17:44:04 +00:00
* @ buf : the XML buffer output
1998-10-20 06:14:16 +00:00
* @ doc : the document
* @ cur : the first attribute pointer
*
* Dump a list of XML attributes
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
static void
1999-04-21 20:12:07 +00:00
xmlAttrListDump ( xmlBufferPtr buf , xmlDocPtr doc , xmlAttrPtr cur ) {
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlAttrListDump : property == NULL \n " ) ;
return ;
}
while ( cur ! = NULL ) {
1999-04-21 20:12:07 +00:00
xmlAttrDump ( buf , doc , cur ) ;
1998-08-13 03:39:55 +00:00
cur = cur - > next ;
}
}
1998-10-27 22:56:57 +00:00
static void
1999-10-11 15:09:51 +00:00
xmlNodeDump ( xmlBufferPtr buf , xmlDocPtr doc , xmlNodePtr cur , int level ,
int format ) ;
1998-10-20 06:14:16 +00:00
/**
* xmlNodeListDump :
1999-06-02 17:44:04 +00:00
* @ buf : the XML buffer output
1998-10-20 06:14:16 +00:00
* @ doc : the document
* @ cur : the first node
* @ level : the imbrication level for indenting
1999-10-11 15:09:51 +00:00
* @ format : is formatting allowed
1998-10-20 06:14:16 +00:00
*
* Dump an XML node list , recursive behaviour , children are printed too .
*/
1998-10-27 22:56:57 +00:00
static void
1999-10-11 15:09:51 +00:00
xmlNodeListDump ( xmlBufferPtr buf , xmlDocPtr doc , xmlNodePtr cur , int level ,
int format ) {
int i ;
1998-10-27 06:21:04 +00:00
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNodeListDump : node == NULL \n " ) ;
return ;
}
while ( cur ! = NULL ) {
1999-10-11 15:09:51 +00:00
if ( ( format ) & & ( xmlIndentTreeOutput ) & &
( cur - > type = = XML_ELEMENT_NODE ) )
for ( i = 0 ; i < level ; i + + )
xmlBufferWriteChar ( buf , " " ) ;
xmlNodeDump ( buf , doc , cur , level , format ) ;
if ( format ) {
xmlBufferWriteChar ( buf , " \n " ) ;
1998-10-27 06:21:04 +00:00
}
1998-08-13 03:39:55 +00:00
cur = cur - > next ;
}
}
1998-10-20 06:14:16 +00:00
/**
1998-10-27 06:21:04 +00:00
* xmlNodeDump :
1999-06-02 17:44:04 +00:00
* @ buf : the XML buffer output
1998-10-20 06:14:16 +00:00
* @ doc : the document
* @ cur : the current node
* @ level : the imbrication level for indenting
1999-10-11 15:09:51 +00:00
* @ format : is formatting allowed
1998-10-20 06:14:16 +00:00
*
* Dump an XML node , recursive behaviour , children are printed too .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
static void
1999-10-11 15:09:51 +00:00
xmlNodeDump ( xmlBufferPtr buf , xmlDocPtr doc , xmlNodePtr cur , int level ,
int format ) {
1998-08-13 03:39:55 +00:00
int i ;
1999-10-11 15:09:51 +00:00
xmlNodePtr tmp ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
fprintf ( stderr , " xmlNodeDump : node == NULL \n " ) ;
return ;
}
1998-10-14 02:36:47 +00:00
if ( cur - > type = = XML_TEXT_NODE ) {
1999-06-22 21:49:07 +00:00
if ( cur - > content ! = NULL ) {
1999-09-23 22:19:22 +00:00
xmlChar * buffer ;
1999-06-22 21:49:07 +00:00
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-06-22 21:49:07 +00:00
buffer = xmlEncodeEntitiesReentrant ( doc , cur - > content ) ;
1999-12-01 09:51:45 +00:00
# else
buffer = xmlEncodeEntitiesReentrant ( doc ,
xmlBufferContent ( cur - > content ) ) ;
# endif
1999-06-22 21:49:07 +00:00
if ( buffer ! = NULL ) {
xmlBufferWriteCHAR ( buf , buffer ) ;
1999-09-02 22:04:43 +00:00
xmlFree ( buffer ) ;
1999-06-22 21:49:07 +00:00
}
}
1998-08-13 03:39:55 +00:00
return ;
}
1999-08-29 21:02:19 +00:00
if ( cur - > type = = XML_PI_NODE ) {
if ( cur - > content ! = NULL ) {
xmlBufferWriteChar ( buf , " <? " ) ;
xmlBufferWriteCHAR ( buf , cur - > name ) ;
if ( cur - > content ! = NULL ) {
xmlBufferWriteChar ( buf , " " ) ;
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-08-29 21:02:19 +00:00
xmlBufferWriteCHAR ( buf , cur - > content ) ;
1999-12-01 09:51:45 +00:00
# else
xmlBufferWriteCHAR ( buf , xmlBufferContent ( cur - > content ) ) ;
# endif
1999-08-29 21:02:19 +00:00
}
1999-10-11 15:09:51 +00:00
xmlBufferWriteChar ( buf , " ?> " ) ;
1999-08-29 21:02:19 +00:00
}
return ;
}
1998-10-14 02:36:47 +00:00
if ( cur - > type = = XML_COMMENT_NODE ) {
1998-08-13 03:39:55 +00:00
if ( cur - > content ! = NULL ) {
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " <!-- " ) ;
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-04-21 20:12:07 +00:00
xmlBufferWriteCHAR ( buf , cur - > content ) ;
1999-12-01 09:51:45 +00:00
# else
xmlBufferWriteCHAR ( buf , xmlBufferContent ( cur - > content ) ) ;
# endif
1999-10-11 15:09:51 +00:00
xmlBufferWriteChar ( buf , " --> " ) ;
1998-08-13 03:39:55 +00:00
}
return ;
}
1998-10-27 06:21:04 +00:00
if ( cur - > type = = XML_ENTITY_REF_NODE ) {
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " & " ) ;
xmlBufferWriteCHAR ( buf , cur - > name ) ;
xmlBufferWriteChar ( buf , " ; " ) ;
1998-10-27 06:21:04 +00:00
return ;
}
1999-08-10 19:04:08 +00:00
if ( cur - > type = = XML_CDATA_SECTION_NODE ) {
xmlBufferWriteChar ( buf , " <![CDATA[ " ) ;
if ( cur - > content ! = NULL )
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-08-10 19:04:08 +00:00
xmlBufferWriteCHAR ( buf , cur - > content ) ;
1999-12-01 09:51:45 +00:00
# else
xmlBufferWriteCHAR ( buf , xmlBufferContent ( cur - > content ) ) ;
# endif
1999-08-10 19:04:08 +00:00
xmlBufferWriteChar ( buf , " ]]> " ) ;
return ;
}
1998-08-13 03:39:55 +00:00
1999-10-11 15:09:51 +00:00
if ( format = = 1 ) {
tmp = cur - > childs ;
while ( tmp ! = NULL ) {
if ( ( tmp - > type = = XML_TEXT_NODE ) | |
( tmp - > type = = XML_ENTITY_REF_NODE ) ) {
format = 0 ;
break ;
}
tmp = tmp - > next ;
}
}
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " < " ) ;
1998-08-13 03:39:55 +00:00
if ( ( cur - > ns ! = NULL ) & & ( cur - > ns - > prefix ! = NULL ) ) {
1999-04-21 20:12:07 +00:00
xmlBufferWriteCHAR ( buf , cur - > ns - > prefix ) ;
xmlBufferWriteChar ( buf , " : " ) ;
1998-08-13 03:39:55 +00:00
}
1999-04-21 20:12:07 +00:00
xmlBufferWriteCHAR ( buf , cur - > name ) ;
1998-08-13 03:39:55 +00:00
if ( cur - > nsDef )
1999-04-21 20:12:07 +00:00
xmlNsListDump ( buf , cur - > nsDef ) ;
1998-08-13 03:39:55 +00:00
if ( cur - > properties ! = NULL )
1999-04-21 20:12:07 +00:00
xmlAttrListDump ( buf , doc , cur - > properties ) ;
1998-08-13 03:39:55 +00:00
if ( ( cur - > content = = NULL ) & & ( cur - > childs = = NULL ) ) {
1999-10-11 15:09:51 +00:00
xmlBufferWriteChar ( buf , " /> " ) ;
1998-08-13 03:39:55 +00:00
return ;
}
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " > " ) ;
1999-06-22 21:49:07 +00:00
if ( cur - > content ! = NULL ) {
1999-09-23 22:19:22 +00:00
xmlChar * buffer ;
1999-06-22 21:49:07 +00:00
1999-12-01 09:51:45 +00:00
# ifndef XML_USE_BUFFER_CONTENT
1999-06-22 21:49:07 +00:00
buffer = xmlEncodeEntitiesReentrant ( doc , cur - > content ) ;
1999-12-01 09:51:45 +00:00
# else
buffer = xmlEncodeEntitiesReentrant ( doc ,
xmlBufferContent ( cur - > content ) ) ;
# endif
1999-06-22 21:49:07 +00:00
if ( buffer ! = NULL ) {
xmlBufferWriteCHAR ( buf , buffer ) ;
1999-09-02 22:04:43 +00:00
xmlFree ( buffer ) ;
1999-06-22 21:49:07 +00:00
}
}
1998-08-13 03:39:55 +00:00
if ( cur - > childs ! = NULL ) {
1999-10-11 15:09:51 +00:00
if ( format ) xmlBufferWriteChar ( buf , " \n " ) ;
xmlNodeListDump ( buf , doc , cur - > childs , level + 1 , format ) ;
if ( ( xmlIndentTreeOutput ) & & ( format ) )
for ( i = 0 ; i < level ; i + + )
xmlBufferWriteChar ( buf , " " ) ;
1998-08-13 03:39:55 +00:00
}
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " </ " ) ;
1998-08-13 03:39:55 +00:00
if ( ( cur - > ns ! = NULL ) & & ( cur - > ns - > prefix ! = NULL ) ) {
1999-04-21 20:12:07 +00:00
xmlBufferWriteCHAR ( buf , cur - > ns - > prefix ) ;
xmlBufferWriteChar ( buf , " : " ) ;
1998-08-13 03:39:55 +00:00
}
1999-04-21 20:12:07 +00:00
xmlBufferWriteCHAR ( buf , cur - > name ) ;
1999-10-11 15:09:51 +00:00
xmlBufferWriteChar ( buf , " > " ) ;
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
/**
* xmlDocContentDump :
1999-06-02 17:44:04 +00:00
* @ buf : the XML buffer output
1998-10-20 06:14:16 +00:00
* @ cur : the document
*
* Dump an XML document .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
static void
1999-04-21 20:12:07 +00:00
xmlDocContentDump ( xmlBufferPtr buf , xmlDocPtr cur ) {
1999-07-05 16:50:46 +00:00
xmlBufferWriteChar ( buf , " <?xml version= " ) ;
if ( cur - > version ! = NULL )
xmlBufferWriteQuotedString ( buf , cur - > version ) ;
else
xmlBufferWriteChar ( buf , " \" 1.0 \" " ) ;
1998-08-13 03:39:55 +00:00
if ( cur - > encoding ! = NULL ) {
1999-06-02 17:44:04 +00:00
xmlBufferWriteChar ( buf , " encoding= " ) ;
xmlBufferWriteQuotedString ( buf , cur - > encoding ) ;
1998-08-13 03:39:55 +00:00
}
switch ( cur - > standalone ) {
case 0 :
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " standalone= \" no \" " ) ;
1998-08-13 03:39:55 +00:00
break ;
case 1 :
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " standalone= \" yes \" " ) ;
1998-08-13 03:39:55 +00:00
break ;
}
1999-04-21 20:12:07 +00:00
xmlBufferWriteChar ( buf , " ?> \n " ) ;
1999-01-17 19:11:59 +00:00
if ( cur - > intSubset ! = NULL )
1999-04-21 20:12:07 +00:00
xmlDtdDump ( buf , cur ) ;
1998-08-13 03:39:55 +00:00
if ( cur - > root ! = NULL ) {
1999-08-29 21:02:19 +00:00
xmlNodePtr child = cur - > root ;
1998-08-13 03:39:55 +00:00
/* global namespace definitions, the old way */
if ( oldXMLWDcompatibility )
1999-04-21 20:12:07 +00:00
xmlGlobalNsListDump ( buf , cur - > oldNs ) ;
1998-08-13 03:39:55 +00:00
else
xmlUpgradeOldNs ( cur ) ;
1999-08-29 21:02:19 +00:00
while ( child ! = NULL ) {
1999-10-11 15:09:51 +00:00
xmlNodeDump ( buf , cur , child , 0 , 1 ) ;
xmlBufferWriteChar ( buf , " \n " ) ;
1999-08-29 21:02:19 +00:00
child = child - > next ;
}
1998-08-13 03:39:55 +00:00
}
}
1998-10-20 06:14:16 +00:00
/**
* xmlDocDumpMemory :
* @ cur : the document
* @ mem : OUT : the memory pointer
* @ size : OUT : the memory lenght
*
1999-09-23 22:19:22 +00:00
* Dump an XML document in memory and return the xmlChar * and it ' s size .
1998-10-20 06:14:16 +00:00
* It ' s up to the caller to free the memory .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
1999-09-23 22:19:22 +00:00
xmlDocDumpMemory ( xmlDocPtr cur , xmlChar * * mem , int * size ) {
1999-04-21 20:12:07 +00:00
xmlBufferPtr buf ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
1999-01-17 19:11:59 +00:00
# ifdef DEBUG_TREE
fprintf ( stderr , " xmlDocDumpMemory : document == NULL \n " ) ;
# endif
1998-08-13 03:39:55 +00:00
* mem = NULL ;
* size = 0 ;
return ;
}
1999-04-21 20:12:07 +00:00
buf = xmlBufferCreate ( ) ;
if ( buf = = NULL ) {
* mem = NULL ;
* size = 0 ;
return ;
}
xmlDocContentDump ( buf , cur ) ;
1999-08-10 19:04:08 +00:00
* mem = xmlStrndup ( buf - > content , buf - > use ) ;
1999-04-21 20:12:07 +00:00
* size = buf - > use ;
1999-08-10 19:04:08 +00:00
xmlBufferFree ( buf ) ;
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
/**
* xmlGetDocCompressMode :
* @ doc : the document
*
* get the compression ratio for a document , ZLIB based
1999-02-22 10:33:01 +00:00
* Returns 0 ( uncompressed ) to 9 ( max compression )
1998-09-23 00:49:46 +00:00
*/
1998-10-27 22:56:57 +00:00
int
xmlGetDocCompressMode ( xmlDocPtr doc ) {
1998-09-24 19:15:06 +00:00
if ( doc = = NULL ) return ( - 1 ) ;
return ( doc - > compression ) ;
}
1998-10-20 06:14:16 +00:00
/**
* 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 )
*/
1998-10-27 22:56:57 +00:00
void
xmlSetDocCompressMode ( xmlDocPtr doc , int mode ) {
1998-09-24 19:15:06 +00:00
if ( doc = = NULL ) return ;
if ( mode < 0 ) doc - > compression = 0 ;
else if ( mode > 9 ) doc - > compression = 9 ;
else doc - > compression = mode ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlGetCompressMode :
*
* get the default compression mode used , ZLIB based .
1999-02-22 10:33:01 +00:00
* Returns 0 ( uncompressed ) to 9 ( max compression )
1998-09-24 19:15:06 +00:00
*/
1998-10-27 22:56:57 +00:00
int
xmlGetCompressMode ( void ) {
1998-09-23 00:49:46 +00:00
return ( xmlCompressMode ) ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlSetCompressMode :
* @ mode : the compression ratio
*
* set the default compression mode used , ZLIB based
* Correct values : 0 ( uncompressed ) to 9 ( max compression )
*/
1998-10-27 22:56:57 +00:00
void
xmlSetCompressMode ( int mode ) {
1998-09-23 00:49:46 +00:00
if ( mode < 0 ) xmlCompressMode = 0 ;
1998-09-24 19:15:06 +00:00
else if ( mode > 9 ) xmlCompressMode = 9 ;
1998-09-23 00:49:46 +00:00
else xmlCompressMode = mode ;
}
1998-10-20 06:14:16 +00:00
/**
* xmlDocDump :
* @ f : the FILE *
* @ cur : the document
*
* Dump an XML document to an open FILE .
1998-08-13 03:39:55 +00:00
*/
1998-10-27 22:56:57 +00:00
void
xmlDocDump ( FILE * f , xmlDocPtr cur ) {
1999-04-21 20:12:07 +00:00
xmlBufferPtr buf ;
1998-08-13 03:39:55 +00:00
if ( cur = = NULL ) {
1999-01-17 19:11:59 +00:00
# ifdef DEBUG_TREE
1998-08-13 03:39:55 +00:00
fprintf ( stderr , " xmlDocDump : document == NULL \n " ) ;
1999-01-17 19:11:59 +00:00
# endif
1998-08-13 03:39:55 +00:00
return ;
}
1999-04-21 20:12:07 +00:00
buf = xmlBufferCreate ( ) ;
if ( buf = = NULL ) return ;
xmlDocContentDump ( buf , cur ) ;
xmlBufferDump ( f , buf ) ;
xmlBufferFree ( buf ) ;
1998-08-13 03:39:55 +00:00
}
1998-10-20 06:14:16 +00:00
/**
* xmlSaveFile :
* @ filename : the filename
* @ cur : the document
*
* Dump an XML document to a file . Will use compression if
1999-11-23 10:40:46 +00:00
* compiled in and enabled . If @ filename is " - " the stdout file is
* used .
1998-10-20 06:14:16 +00:00
* returns : the number of file written or - 1 in case of failure .
1998-09-23 00:49:46 +00:00
*/
1998-10-27 22:56:57 +00:00
int
xmlSaveFile ( const char * filename , xmlDocPtr cur ) {
1999-04-21 20:12:07 +00:00
xmlBufferPtr buf ;
1998-09-23 00:49:46 +00:00
# ifdef HAVE_ZLIB_H
gzFile zoutput = NULL ;
char mode [ 15 ] ;
# endif
1998-10-27 06:21:04 +00:00
FILE * output = NULL ;
1998-09-23 00:49:46 +00:00
int ret ;
1999-04-21 20:12:07 +00:00
/*
* save the content to a temp buffer .
*/
buf = xmlBufferCreate ( ) ;
if ( buf = = NULL ) return ( 0 ) ;
xmlDocContentDump ( buf , cur ) ;
1998-09-23 00:49:46 +00:00
# ifdef HAVE_ZLIB_H
1999-11-23 10:40:46 +00:00
if ( cur - > compression < 0 ) cur - > compression = xmlCompressMode ;
1998-09-24 19:25:54 +00:00
if ( ( cur - > compression > 0 ) & & ( cur - > compression < = 9 ) ) {
sprintf ( mode , " w%d " , cur - > compression ) ;
1999-11-23 10:40:46 +00:00
if ( ! strcmp ( filename , " - " ) )
zoutput = gzdopen ( 1 , mode ) ;
else
zoutput = gzopen ( filename , mode ) ;
1998-09-23 00:49:46 +00:00
}
if ( zoutput = = NULL ) {
# endif
output = fopen ( filename , " w " ) ;
1999-12-12 13:03:50 +00:00
if ( output = = NULL ) {
xmlBufferFree ( buf ) ;
return ( - 1 ) ;
}
1998-09-23 00:49:46 +00:00
# ifdef HAVE_ZLIB_H
}
if ( zoutput ! = NULL ) {
1999-09-23 22:19:22 +00:00
ret = gzwrite ( zoutput , buf - > content , sizeof ( xmlChar ) * buf - > use ) ;
1998-09-23 00:49:46 +00:00
gzclose ( zoutput ) ;
1999-04-21 20:12:07 +00:00
} else {
# endif
ret = xmlBufferDump ( output , buf ) ;
fclose ( output ) ;
# ifdef HAVE_ZLIB_H
1998-09-23 00:49:46 +00:00
}
# endif
1999-05-29 03:04:30 +00:00
xmlBufferFree ( buf ) ;
1999-09-23 22:19:22 +00:00
return ( ret * sizeof ( xmlChar ) ) ;
1998-09-23 00:49:46 +00:00
}