| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1 | /* | 
|  | 2 | * xmlreader.c: implements the xmlTextReader streaming node API | 
|  | 3 | * | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 4 | * NOTE: | 
|  | 5 | *   XmlTextReader.Normalization Property won't be supported, since | 
|  | 6 | *     it makes the parser non compliant to the XML recommendation | 
|  | 7 | * | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 8 | * See Copyright for the status of this software. | 
|  | 9 | * | 
|  | 10 | * daniel@veillard.com | 
|  | 11 | */ | 
|  | 12 |  | 
| Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 13 | /* | 
|  | 14 | * TODOs: | 
| Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 15 | *   - provide an API to preserve part of the tree | 
|  | 16 | *   - Streaming XInclude support | 
| Daniel Veillard | 067bae5 | 2003-01-05 01:27:54 +0000 | [diff] [blame] | 17 | *   - XML Schemas validation | 
| Daniel Veillard | 7704fb1 | 2003-01-03 16:19:51 +0000 | [diff] [blame] | 18 | *   - setting(s) for NoBlanks | 
|  | 19 | *   - performances and tuning ... | 
|  | 20 | */ | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 21 | #define IN_LIBXML | 
|  | 22 | #include "libxml.h" | 
|  | 23 |  | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 24 | #ifdef LIBXML_READER_ENABLED | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 25 | #include <string.h> /* for memset() only ! */ | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 26 | #include <stdarg.h> | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 27 |  | 
|  | 28 | #ifdef HAVE_CTYPE_H | 
|  | 29 | #include <ctype.h> | 
|  | 30 | #endif | 
|  | 31 | #ifdef HAVE_STDLIB_H | 
|  | 32 | #include <stdlib.h> | 
|  | 33 | #endif | 
|  | 34 |  | 
|  | 35 | #include <libxml/xmlmemory.h> | 
|  | 36 | #include <libxml/xmlIO.h> | 
|  | 37 | #include <libxml/xmlreader.h> | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 38 | #include <libxml/parserInternals.h> | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 39 | #include <libxml/relaxng.h> | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 40 | #include <libxml/uri.h> | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 41 | #ifdef LIBXML_XINCLUDE_ENABLED | 
|  | 42 | #include <libxml/xinclude.h> | 
|  | 43 | #endif | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 44 | #ifdef LIBXML_PATTERN_ENABLED | 
|  | 45 | #include <libxml/pattern.h> | 
|  | 46 | #endif | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 47 |  | 
|  | 48 | /* #define DEBUG_CALLBACKS */ | 
|  | 49 | /* #define DEBUG_READER */ | 
|  | 50 |  | 
|  | 51 | /** | 
|  | 52 | * TODO: | 
|  | 53 | * | 
|  | 54 | * macro to flag unimplemented blocks | 
|  | 55 | */ | 
|  | 56 | #define TODO 								\ | 
|  | 57 | xmlGenericError(xmlGenericErrorContext,				\ | 
|  | 58 | "Unimplemented block at %s:%d\n",				\ | 
|  | 59 | __FILE__, __LINE__); | 
|  | 60 |  | 
|  | 61 | #ifdef DEBUG_READER | 
|  | 62 | #define DUMP_READER xmlTextReaderDebug(reader); | 
|  | 63 | #else | 
|  | 64 | #define DUMP_READER | 
|  | 65 | #endif | 
|  | 66 |  | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 67 | #define CHUNK_SIZE 512 | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 68 | /************************************************************************ | 
|  | 69 | *									* | 
|  | 70 | *	The parser: maps the Text Reader API on top of the existing	* | 
|  | 71 | *		parsing routines building a tree			* | 
|  | 72 | *									* | 
|  | 73 | ************************************************************************/ | 
|  | 74 |  | 
|  | 75 | #define XML_TEXTREADER_INPUT	1 | 
|  | 76 | #define XML_TEXTREADER_CTXT	2 | 
|  | 77 |  | 
|  | 78 | typedef enum { | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 79 | XML_TEXTREADER_MODE_INITIAL = 0, | 
|  | 80 | XML_TEXTREADER_MODE_INTERACTIVE = 1, | 
|  | 81 | XML_TEXTREADER_MODE_ERROR = 2, | 
|  | 82 | XML_TEXTREADER_MODE_EOF =3, | 
|  | 83 | XML_TEXTREADER_MODE_CLOSED = 4, | 
|  | 84 | XML_TEXTREADER_MODE_READING = 5 | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 85 | } xmlTextReaderMode; | 
|  | 86 |  | 
|  | 87 | typedef enum { | 
|  | 88 | XML_TEXTREADER_NONE = -1, | 
|  | 89 | XML_TEXTREADER_START= 0, | 
|  | 90 | XML_TEXTREADER_ELEMENT= 1, | 
|  | 91 | XML_TEXTREADER_END= 2, | 
|  | 92 | XML_TEXTREADER_EMPTY= 3, | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 93 | XML_TEXTREADER_BACKTRACK= 4, | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 94 | XML_TEXTREADER_DONE= 5, | 
|  | 95 | XML_TEXTREADER_ERROR= 6 | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 96 | } xmlTextReaderState; | 
|  | 97 |  | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 98 | typedef enum { | 
|  | 99 | XML_TEXTREADER_NOT_VALIDATE = 0, | 
|  | 100 | XML_TEXTREADER_VALIDATE_DTD = 1, | 
|  | 101 | XML_TEXTREADER_VALIDATE_RNG = 2 | 
|  | 102 | } xmlTextReaderValidate; | 
|  | 103 |  | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 104 | struct _xmlTextReader { | 
|  | 105 | int				mode;	/* the parsing mode */ | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 106 | xmlDocPtr			doc;    /* when walking an existing doc */ | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 107 | xmlTextReaderValidate       validate;/* is there any validation */ | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 108 | int				allocs;	/* what structure were deallocated */ | 
|  | 109 | xmlTextReaderState		state; | 
|  | 110 | xmlParserCtxtPtr		ctxt;	/* the parser context */ | 
|  | 111 | xmlSAXHandlerPtr		sax;	/* the parser SAX callbacks */ | 
|  | 112 | xmlParserInputBufferPtr	input;	/* the input */ | 
|  | 113 | startElementSAXFunc		startElement;/* initial SAX callbacks */ | 
|  | 114 | endElementSAXFunc		endElement;  /* idem */ | 
| Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 115 | startElementNsSAX2Func	startElementNs;/* idem */ | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 116 | endElementNsSAX2Func	endElementNs;  /* idem */ | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 117 | charactersSAXFunc		characters; | 
|  | 118 | cdataBlockSAXFunc		cdataBlock; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 119 | unsigned int 		base;	/* base of the segment in the input */ | 
|  | 120 | unsigned int 		cur;	/* current position in the input */ | 
|  | 121 | xmlNodePtr			node;	/* current node */ | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 122 | xmlNodePtr			curnode;/* current attribute node */ | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 123 | int				depth;  /* depth of the current node */ | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 124 | xmlNodePtr			faketext;/* fake xmlNs chld */ | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 125 | int				preserve;/* preserve the resulting document */ | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 126 | xmlBufferPtr		buffer; /* used to return const xmlChar * */ | 
|  | 127 | xmlDictPtr			dict;	/* the context dictionnary */ | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 128 |  | 
|  | 129 | /* entity stack when traversing entities content */ | 
|  | 130 | xmlNodePtr         ent;          /* Current Entity Ref Node */ | 
|  | 131 | int                entNr;        /* Depth of the entities stack */ | 
|  | 132 | int                entMax;       /* Max depth of the entities stack */ | 
|  | 133 | xmlNodePtr        *entTab;       /* array of entities */ | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 134 |  | 
|  | 135 | /* error handling */ | 
|  | 136 | xmlTextReaderErrorFunc errorFunc;    /* callback function */ | 
|  | 137 | void                  *errorFuncArg; /* callback function user argument */ | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 138 |  | 
|  | 139 | #ifdef LIBXML_SCHEMAS_ENABLED | 
|  | 140 | /* Handling of RelaxNG validation */ | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 141 | xmlRelaxNGPtr          rngSchemas;	/* The Relax NG schemas */ | 
|  | 142 | xmlRelaxNGValidCtxtPtr rngValidCtxt;/* The Relax NG validation context */ | 
|  | 143 | int                  rngValidErrors;/* The number of errors detected */ | 
|  | 144 | xmlNodePtr             rngFullNode;	/* the node if RNG not progressive */ | 
|  | 145 | #endif | 
|  | 146 | #ifdef LIBXML_XINCLUDE_ENABLED | 
|  | 147 | /* Handling of XInclude processing */ | 
|  | 148 | int                xinclude;	/* is xinclude asked for */ | 
|  | 149 | const xmlChar *    xinclude_name;	/* the xinclude name from dict */ | 
|  | 150 | xmlXIncludeCtxtPtr xincctxt;	/* the xinclude context */ | 
|  | 151 | int                in_xinclude;	/* counts for xinclude */ | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 152 | #endif | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 153 | #ifdef LIBXML_PATTERN_ENABLED | 
|  | 154 | int                patternNr;       /* number of preserve patterns */ | 
|  | 155 | int                patternMax;      /* max preserve patterns */ | 
|  | 156 | xmlPatternPtr     *patternTab;      /* array of preserve patterns */ | 
|  | 157 | #endif | 
|  | 158 | int                preserves;	/* level of preserves */ | 
| Daniel Veillard | e74d2e1 | 2003-12-09 11:35:37 +0000 | [diff] [blame] | 159 | int                parserFlags;	/* the set of options set */ | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 160 | }; | 
|  | 161 |  | 
| Daniel Veillard | e8039df | 2003-10-27 11:25:13 +0000 | [diff] [blame] | 162 | #define NODE_IS_EMPTY		0x1 | 
|  | 163 | #define NODE_IS_PRESERVED	0x2 | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 164 | #define NODE_IS_SPRESERVED	0x4 | 
| Daniel Veillard | 067bae5 | 2003-01-05 01:27:54 +0000 | [diff] [blame] | 165 |  | 
| Daniel Veillard | e72c508 | 2003-09-19 12:44:05 +0000 | [diff] [blame] | 166 | /** | 
|  | 167 | * CONSTSTR: | 
|  | 168 | * | 
|  | 169 | * Macro used to return an interned string | 
|  | 170 | */ | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 171 | #define CONSTSTR(str) xmlDictLookup(reader->dict, (str), -1) | 
|  | 172 | #define CONSTQSTR(p, str) xmlDictQLookup(reader->dict, (p), (str)) | 
|  | 173 |  | 
|  | 174 | static int xmlTextReaderReadTree(xmlTextReaderPtr reader); | 
|  | 175 | static int xmlTextReaderNextTree(xmlTextReaderPtr reader); | 
| Daniel Veillard | e72c508 | 2003-09-19 12:44:05 +0000 | [diff] [blame] | 176 |  | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 177 | /************************************************************************ | 
|  | 178 | *									* | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 179 | *	Our own version of the freeing routines as we recycle nodes	* | 
|  | 180 | *									* | 
|  | 181 | ************************************************************************/ | 
|  | 182 | /** | 
|  | 183 | * DICT_FREE: | 
|  | 184 | * @str:  a string | 
|  | 185 | * | 
|  | 186 | * Free a string if it is not owned by the "dict" dictionnary in the | 
|  | 187 | * current scope | 
|  | 188 | */ | 
|  | 189 | #define DICT_FREE(str)						\ | 
|  | 190 | if ((str) && ((!dict) || 				\ | 
|  | 191 | (xmlDictOwns(dict, (const xmlChar *)(str)) == 0)))	\ | 
|  | 192 | xmlFree((char *)(str)); | 
|  | 193 |  | 
|  | 194 | static void xmlTextReaderFreeNode(xmlTextReaderPtr reader, xmlNodePtr cur); | 
|  | 195 | static void xmlTextReaderFreeNodeList(xmlTextReaderPtr reader, xmlNodePtr cur); | 
|  | 196 |  | 
|  | 197 | /** | 
| Daniel Veillard | 8d7b5c7 | 2003-11-15 18:24:36 +0000 | [diff] [blame] | 198 | * xmlFreeID: | 
|  | 199 | * @not:  A id | 
|  | 200 | * | 
|  | 201 | * Deallocate the memory used by an id definition | 
|  | 202 | */ | 
|  | 203 | static void | 
|  | 204 | xmlFreeID(xmlIDPtr id) { | 
|  | 205 | xmlDictPtr dict = NULL; | 
|  | 206 |  | 
|  | 207 | if (id == NULL) return; | 
|  | 208 |  | 
|  | 209 | if (id->doc != NULL) | 
|  | 210 | dict = id->doc->dict; | 
|  | 211 |  | 
|  | 212 | if (id->value != NULL) | 
|  | 213 | DICT_FREE(id->value) | 
|  | 214 | xmlFree(id); | 
|  | 215 | } | 
|  | 216 |  | 
|  | 217 | /** | 
|  | 218 | * xmlTextReaderRemoveID: | 
|  | 219 | * @doc:  the document | 
|  | 220 | * @attr:  the attribute | 
|  | 221 | * | 
|  | 222 | * Remove the given attribute from the ID table maintained internally. | 
|  | 223 | * | 
|  | 224 | * Returns -1 if the lookup failed and 0 otherwise | 
|  | 225 | */ | 
|  | 226 | static int | 
|  | 227 | xmlTextReaderRemoveID(xmlDocPtr doc, xmlAttrPtr attr) { | 
|  | 228 | xmlIDTablePtr table; | 
|  | 229 | xmlIDPtr id; | 
|  | 230 | xmlChar *ID; | 
|  | 231 |  | 
|  | 232 | if (doc == NULL) return(-1); | 
|  | 233 | if (attr == NULL) return(-1); | 
|  | 234 | table = (xmlIDTablePtr) doc->ids; | 
|  | 235 | if (table == NULL) | 
|  | 236 | return(-1); | 
|  | 237 |  | 
|  | 238 | if (attr == NULL) | 
|  | 239 | return(-1); | 
|  | 240 | ID = xmlNodeListGetString(doc, attr->children, 1); | 
|  | 241 | if (ID == NULL) | 
|  | 242 | return(-1); | 
|  | 243 | id = xmlHashLookup(table, ID); | 
|  | 244 | xmlFree(ID); | 
|  | 245 | if (id == NULL || id->attr != attr) { | 
|  | 246 | return(-1); | 
|  | 247 | } | 
|  | 248 | id->name = attr->name; | 
|  | 249 | id->attr = NULL; | 
|  | 250 | return(0); | 
|  | 251 | } | 
|  | 252 |  | 
|  | 253 | /** | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 254 | * xmlTextReaderFreeProp: | 
|  | 255 | * @reader:  the xmlTextReaderPtr used | 
|  | 256 | * @cur:  the node | 
|  | 257 | * | 
|  | 258 | * Free a node. | 
|  | 259 | */ | 
|  | 260 | static void | 
|  | 261 | xmlTextReaderFreeProp(xmlTextReaderPtr reader, xmlAttrPtr cur) { | 
|  | 262 | xmlDictPtr dict; | 
|  | 263 |  | 
|  | 264 | dict = reader->ctxt->dict; | 
|  | 265 | if (cur == NULL) return; | 
|  | 266 |  | 
|  | 267 | /* Check for ID removal -> leading to invalid references ! */ | 
|  | 268 | if ((cur->parent != NULL) && (cur->parent->doc != NULL) && | 
|  | 269 | ((cur->parent->doc->intSubset != NULL) || | 
|  | 270 | (cur->parent->doc->extSubset != NULL))) { | 
|  | 271 | if (xmlIsID(cur->parent->doc, cur->parent, cur)) | 
| Daniel Veillard | 8d7b5c7 | 2003-11-15 18:24:36 +0000 | [diff] [blame] | 272 | xmlTextReaderRemoveID(cur->parent->doc, cur); | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 273 | } | 
|  | 274 | if (cur->children != NULL) | 
|  | 275 | xmlTextReaderFreeNodeList(reader, cur->children); | 
|  | 276 |  | 
|  | 277 | DICT_FREE(cur->name); | 
|  | 278 | if ((reader != NULL) && (reader->ctxt != NULL) && | 
|  | 279 | (reader->ctxt->freeAttrsNr < 100)) { | 
|  | 280 | cur->next = reader->ctxt->freeAttrs; | 
|  | 281 | reader->ctxt->freeAttrs = cur; | 
|  | 282 | reader->ctxt->freeAttrsNr++; | 
|  | 283 | } else { | 
|  | 284 | xmlFree(cur); | 
|  | 285 | } | 
|  | 286 | } | 
|  | 287 |  | 
|  | 288 | /** | 
|  | 289 | * xmlTextReaderFreePropList: | 
|  | 290 | * @reader:  the xmlTextReaderPtr used | 
|  | 291 | * @cur:  the first property in the list | 
|  | 292 | * | 
|  | 293 | * Free a property and all its siblings, all the children are freed too. | 
|  | 294 | */ | 
|  | 295 | static void | 
|  | 296 | xmlTextReaderFreePropList(xmlTextReaderPtr reader, xmlAttrPtr cur) { | 
|  | 297 | xmlAttrPtr next; | 
|  | 298 | if (cur == NULL) return; | 
|  | 299 | while (cur != NULL) { | 
|  | 300 | next = cur->next; | 
|  | 301 | xmlTextReaderFreeProp(reader, cur); | 
|  | 302 | cur = next; | 
|  | 303 | } | 
|  | 304 | } | 
|  | 305 |  | 
|  | 306 | /** | 
|  | 307 | * xmlTextReaderFreeNodeList: | 
|  | 308 | * @reader:  the xmlTextReaderPtr used | 
|  | 309 | * @cur:  the first node in the list | 
|  | 310 | * | 
|  | 311 | * Free a node and all its siblings, this is a recursive behaviour, all | 
|  | 312 | * the children are freed too. | 
|  | 313 | */ | 
|  | 314 | static void | 
|  | 315 | xmlTextReaderFreeNodeList(xmlTextReaderPtr reader, xmlNodePtr cur) { | 
|  | 316 | xmlNodePtr next; | 
|  | 317 | xmlDictPtr dict; | 
|  | 318 |  | 
|  | 319 | dict = reader->ctxt->dict; | 
|  | 320 | if (cur == NULL) return; | 
|  | 321 | if (cur->type == XML_NAMESPACE_DECL) { | 
|  | 322 | xmlFreeNsList((xmlNsPtr) cur); | 
|  | 323 | return; | 
|  | 324 | } | 
|  | 325 | if ((cur->type == XML_DOCUMENT_NODE) || | 
|  | 326 | (cur->type == XML_HTML_DOCUMENT_NODE)) { | 
|  | 327 | xmlFreeDoc((xmlDocPtr) cur); | 
|  | 328 | return; | 
|  | 329 | } | 
|  | 330 | while (cur != NULL) { | 
|  | 331 | next = cur->next; | 
|  | 332 | /* unroll to speed up freeing the document */ | 
|  | 333 | if (cur->type != XML_DTD_NODE) { | 
|  | 334 |  | 
|  | 335 | if ((cur->children != NULL) && | 
| Daniel Veillard | 1d211e2 | 2003-10-20 22:32:39 +0000 | [diff] [blame] | 336 | (cur->type != XML_ENTITY_REF_NODE)) { | 
|  | 337 | if (cur->children->parent == cur) | 
|  | 338 | xmlTextReaderFreeNodeList(reader, cur->children); | 
|  | 339 | cur->children = NULL; | 
|  | 340 | } | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 341 | if (((cur->type == XML_ELEMENT_NODE) || | 
|  | 342 | (cur->type == XML_XINCLUDE_START) || | 
|  | 343 | (cur->type == XML_XINCLUDE_END)) && | 
|  | 344 | (cur->properties != NULL)) | 
|  | 345 | xmlTextReaderFreePropList(reader, cur->properties); | 
|  | 346 | if ((cur->type != XML_ELEMENT_NODE) && | 
|  | 347 | (cur->type != XML_XINCLUDE_START) && | 
|  | 348 | (cur->type != XML_XINCLUDE_END) && | 
|  | 349 | (cur->type != XML_ENTITY_REF_NODE)) { | 
|  | 350 | DICT_FREE(cur->content); | 
|  | 351 | } | 
|  | 352 | if (((cur->type == XML_ELEMENT_NODE) || | 
|  | 353 | (cur->type == XML_XINCLUDE_START) || | 
|  | 354 | (cur->type == XML_XINCLUDE_END)) && | 
|  | 355 | (cur->nsDef != NULL)) | 
|  | 356 | xmlFreeNsList(cur->nsDef); | 
|  | 357 |  | 
|  | 358 | /* | 
|  | 359 | * we don't free element names here they are interned now | 
|  | 360 | */ | 
|  | 361 | if ((cur->type != XML_TEXT_NODE) && | 
|  | 362 | (cur->type != XML_COMMENT_NODE)) | 
|  | 363 | DICT_FREE(cur->name); | 
|  | 364 | if (((cur->type == XML_ELEMENT_NODE) || | 
|  | 365 | (cur->type == XML_TEXT_NODE)) && | 
|  | 366 | (reader != NULL) && (reader->ctxt != NULL) && | 
|  | 367 | (reader->ctxt->freeElemsNr < 100)) { | 
|  | 368 | cur->next = reader->ctxt->freeElems; | 
|  | 369 | reader->ctxt->freeElems = cur; | 
|  | 370 | reader->ctxt->freeElemsNr++; | 
|  | 371 | } else { | 
|  | 372 | xmlFree(cur); | 
|  | 373 | } | 
|  | 374 | } | 
|  | 375 | cur = next; | 
|  | 376 | } | 
|  | 377 | } | 
|  | 378 |  | 
|  | 379 | /** | 
|  | 380 | * xmlTextReaderFreeNode: | 
|  | 381 | * @reader:  the xmlTextReaderPtr used | 
|  | 382 | * @cur:  the node | 
|  | 383 | * | 
|  | 384 | * Free a node, this is a recursive behaviour, all the children are freed too. | 
|  | 385 | * This doesn't unlink the child from the list, use xmlUnlinkNode() first. | 
|  | 386 | */ | 
|  | 387 | static void | 
|  | 388 | xmlTextReaderFreeNode(xmlTextReaderPtr reader, xmlNodePtr cur) { | 
|  | 389 | xmlDictPtr dict; | 
|  | 390 |  | 
|  | 391 | dict = reader->ctxt->dict; | 
|  | 392 | if (cur->type == XML_DTD_NODE) { | 
|  | 393 | xmlFreeDtd((xmlDtdPtr) cur); | 
|  | 394 | return; | 
|  | 395 | } | 
|  | 396 | if (cur->type == XML_NAMESPACE_DECL) { | 
|  | 397 | xmlFreeNs((xmlNsPtr) cur); | 
|  | 398 | return; | 
|  | 399 | } | 
|  | 400 | if (cur->type == XML_ATTRIBUTE_NODE) { | 
|  | 401 | xmlTextReaderFreeProp(reader, (xmlAttrPtr) cur); | 
|  | 402 | return; | 
|  | 403 | } | 
|  | 404 |  | 
|  | 405 | if ((cur->children != NULL) && | 
| Daniel Veillard | 1d211e2 | 2003-10-20 22:32:39 +0000 | [diff] [blame] | 406 | (cur->type != XML_ENTITY_REF_NODE)) { | 
|  | 407 | if (cur->children->parent == cur) | 
|  | 408 | xmlTextReaderFreeNodeList(reader, cur->children); | 
|  | 409 | cur->children = NULL; | 
|  | 410 | } | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 411 | if (((cur->type == XML_ELEMENT_NODE) || | 
|  | 412 | (cur->type == XML_XINCLUDE_START) || | 
|  | 413 | (cur->type == XML_XINCLUDE_END)) && | 
|  | 414 | (cur->properties != NULL)) | 
|  | 415 | xmlTextReaderFreePropList(reader, cur->properties); | 
|  | 416 | if ((cur->type != XML_ELEMENT_NODE) && | 
|  | 417 | (cur->type != XML_XINCLUDE_START) && | 
|  | 418 | (cur->type != XML_XINCLUDE_END) && | 
|  | 419 | (cur->type != XML_ENTITY_REF_NODE)) { | 
|  | 420 | DICT_FREE(cur->content); | 
|  | 421 | } | 
|  | 422 | if (((cur->type == XML_ELEMENT_NODE) || | 
|  | 423 | (cur->type == XML_XINCLUDE_START) || | 
|  | 424 | (cur->type == XML_XINCLUDE_END)) && | 
|  | 425 | (cur->nsDef != NULL)) | 
|  | 426 | xmlFreeNsList(cur->nsDef); | 
|  | 427 |  | 
|  | 428 | /* | 
|  | 429 | * we don't free names here they are interned now | 
|  | 430 | */ | 
|  | 431 | if ((cur->type != XML_TEXT_NODE) && | 
|  | 432 | (cur->type != XML_COMMENT_NODE)) | 
|  | 433 | DICT_FREE(cur->name); | 
|  | 434 | if (((cur->type == XML_ELEMENT_NODE) || | 
|  | 435 | (cur->type == XML_TEXT_NODE)) && | 
|  | 436 | (reader != NULL) && (reader->ctxt != NULL) && | 
|  | 437 | (reader->ctxt->freeElemsNr < 100)) { | 
|  | 438 | cur->next = reader->ctxt->freeElems; | 
|  | 439 | reader->ctxt->freeElems = cur; | 
|  | 440 | reader->ctxt->freeElemsNr++; | 
|  | 441 | } else { | 
|  | 442 | xmlFree(cur); | 
|  | 443 | } | 
|  | 444 | } | 
|  | 445 |  | 
|  | 446 | /** | 
| Daniel Veillard | 8d7b5c7 | 2003-11-15 18:24:36 +0000 | [diff] [blame] | 447 | * xmlTextReaderFreeIDTable: | 
|  | 448 | * @table:  An id table | 
|  | 449 | * | 
|  | 450 | * Deallocate the memory used by an ID hash table. | 
|  | 451 | */ | 
| William M. Brack | 60f394e | 2003-11-16 06:25:42 +0000 | [diff] [blame] | 452 | static void | 
| Daniel Veillard | 8d7b5c7 | 2003-11-15 18:24:36 +0000 | [diff] [blame] | 453 | xmlTextReaderFreeIDTable(xmlIDTablePtr table) { | 
|  | 454 | xmlHashFree(table, (xmlHashDeallocator) xmlFreeID); | 
|  | 455 | } | 
|  | 456 |  | 
|  | 457 | /** | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 458 | * xmlTextReaderFreeDoc: | 
|  | 459 | * @reader:  the xmlTextReaderPtr used | 
|  | 460 | * @cur:  pointer to the document | 
|  | 461 | * | 
|  | 462 | * Free up all the structures used by a document, tree included. | 
|  | 463 | */ | 
|  | 464 | static void | 
|  | 465 | xmlTextReaderFreeDoc(xmlTextReaderPtr reader, xmlDocPtr cur) { | 
|  | 466 | xmlDtdPtr extSubset, intSubset; | 
|  | 467 |  | 
|  | 468 | if (cur == NULL) return; | 
|  | 469 |  | 
|  | 470 | /* | 
|  | 471 | * Do this before freeing the children list to avoid ID lookups | 
|  | 472 | */ | 
| Daniel Veillard | 8d7b5c7 | 2003-11-15 18:24:36 +0000 | [diff] [blame] | 473 | if (cur->ids != NULL) xmlTextReaderFreeIDTable((xmlIDTablePtr) cur->ids); | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 474 | cur->ids = NULL; | 
|  | 475 | if (cur->refs != NULL) xmlFreeRefTable((xmlRefTablePtr) cur->refs); | 
|  | 476 | cur->refs = NULL; | 
|  | 477 | extSubset = cur->extSubset; | 
|  | 478 | intSubset = cur->intSubset; | 
|  | 479 | if (intSubset == extSubset) | 
|  | 480 | extSubset = NULL; | 
|  | 481 | if (extSubset != NULL) { | 
|  | 482 | xmlUnlinkNode((xmlNodePtr) cur->extSubset); | 
|  | 483 | cur->extSubset = NULL; | 
|  | 484 | xmlFreeDtd(extSubset); | 
|  | 485 | } | 
|  | 486 | if (intSubset != NULL) { | 
|  | 487 | xmlUnlinkNode((xmlNodePtr) cur->intSubset); | 
|  | 488 | cur->intSubset = NULL; | 
|  | 489 | xmlFreeDtd(intSubset); | 
|  | 490 | } | 
|  | 491 |  | 
|  | 492 | if (cur->children != NULL) xmlTextReaderFreeNodeList(reader, cur->children); | 
|  | 493 |  | 
|  | 494 | if (cur->version != NULL) xmlFree((char *) cur->version); | 
|  | 495 | if (cur->name != NULL) xmlFree((char *) cur->name); | 
|  | 496 | if (cur->encoding != NULL) xmlFree((char *) cur->encoding); | 
|  | 497 | if (cur->oldNs != NULL) xmlFreeNsList(cur->oldNs); | 
|  | 498 | if (cur->URL != NULL) xmlFree((char *) cur->URL); | 
|  | 499 | xmlFree(cur); | 
|  | 500 | } | 
|  | 501 |  | 
|  | 502 | /************************************************************************ | 
|  | 503 | *									* | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 504 | *			The reader core parser				* | 
|  | 505 | *									* | 
|  | 506 | ************************************************************************/ | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 507 | #ifdef DEBUG_READER | 
|  | 508 | static void | 
|  | 509 | xmlTextReaderDebug(xmlTextReaderPtr reader) { | 
|  | 510 | if ((reader == NULL) || (reader->ctxt == NULL)) { | 
|  | 511 | fprintf(stderr, "xmlTextReader NULL\n"); | 
|  | 512 | return; | 
|  | 513 | } | 
|  | 514 | fprintf(stderr, "xmlTextReader: state %d depth %d ", | 
|  | 515 | reader->state, reader->depth); | 
|  | 516 | if (reader->node == NULL) { | 
|  | 517 | fprintf(stderr, "node = NULL\n"); | 
|  | 518 | } else { | 
|  | 519 | fprintf(stderr, "node %s\n", reader->node->name); | 
|  | 520 | } | 
|  | 521 | fprintf(stderr, "  input: base %d, cur %d, depth %d: ", | 
|  | 522 | reader->base, reader->cur, reader->ctxt->nodeNr); | 
|  | 523 | if (reader->input->buffer == NULL) { | 
|  | 524 | fprintf(stderr, "buffer is NULL\n"); | 
|  | 525 | } else { | 
|  | 526 | #ifdef LIBXML_DEBUG_ENABLED | 
|  | 527 | xmlDebugDumpString(stderr, | 
|  | 528 | &reader->input->buffer->content[reader->cur]); | 
|  | 529 | #endif | 
|  | 530 | fprintf(stderr, "\n"); | 
|  | 531 | } | 
|  | 532 | } | 
|  | 533 | #endif | 
|  | 534 |  | 
|  | 535 | /** | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 536 | * xmlTextReaderEntPush: | 
|  | 537 | * @reader:  the xmlTextReaderPtr used | 
|  | 538 | * @value:  the entity reference node | 
|  | 539 | * | 
|  | 540 | * Pushes a new entity reference node on top of the entities stack | 
|  | 541 | * | 
|  | 542 | * Returns 0 in case of error, the index in the stack otherwise | 
|  | 543 | */ | 
|  | 544 | static int | 
|  | 545 | xmlTextReaderEntPush(xmlTextReaderPtr reader, xmlNodePtr value) | 
|  | 546 | { | 
|  | 547 | if (reader->entMax <= 0) { | 
|  | 548 | reader->entMax = 10; | 
|  | 549 | reader->entTab = (xmlNodePtr *) xmlMalloc(reader->entMax * | 
|  | 550 | sizeof(reader->entTab[0])); | 
|  | 551 | if (reader->entTab == NULL) { | 
|  | 552 | xmlGenericError(xmlGenericErrorContext, "xmlMalloc failed !\n"); | 
|  | 553 | return (0); | 
|  | 554 | } | 
|  | 555 | } | 
|  | 556 | if (reader->entNr >= reader->entMax) { | 
|  | 557 | reader->entMax *= 2; | 
|  | 558 | reader->entTab = | 
|  | 559 | (xmlNodePtr *) xmlRealloc(reader->entTab, | 
|  | 560 | reader->entMax * | 
|  | 561 | sizeof(reader->entTab[0])); | 
|  | 562 | if (reader->entTab == NULL) { | 
|  | 563 | xmlGenericError(xmlGenericErrorContext, "xmlRealloc failed !\n"); | 
|  | 564 | return (0); | 
|  | 565 | } | 
|  | 566 | } | 
|  | 567 | reader->entTab[reader->entNr] = value; | 
|  | 568 | reader->ent = value; | 
|  | 569 | return (reader->entNr++); | 
|  | 570 | } | 
|  | 571 |  | 
|  | 572 | /** | 
|  | 573 | * xmlTextReaderEntPop: | 
|  | 574 | * @reader:  the xmlTextReaderPtr used | 
|  | 575 | * | 
|  | 576 | * Pops the top element entity from the entities stack | 
|  | 577 | * | 
|  | 578 | * Returns the entity just removed | 
|  | 579 | */ | 
|  | 580 | static xmlNodePtr | 
|  | 581 | xmlTextReaderEntPop(xmlTextReaderPtr reader) | 
|  | 582 | { | 
|  | 583 | xmlNodePtr ret; | 
|  | 584 |  | 
|  | 585 | if (reader->entNr <= 0) | 
|  | 586 | return (0); | 
|  | 587 | reader->entNr--; | 
|  | 588 | if (reader->entNr > 0) | 
|  | 589 | reader->ent = reader->entTab[reader->entNr - 1]; | 
|  | 590 | else | 
|  | 591 | reader->ent = NULL; | 
|  | 592 | ret = reader->entTab[reader->entNr]; | 
|  | 593 | reader->entTab[reader->entNr] = 0; | 
|  | 594 | return (ret); | 
|  | 595 | } | 
|  | 596 |  | 
|  | 597 | /** | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 598 | * xmlTextReaderStartElement: | 
|  | 599 | * @ctx: the user data (XML parser context) | 
|  | 600 | * @fullname:  The element name, including namespace prefix | 
|  | 601 | * @atts:  An array of name/value attributes pairs, NULL terminated | 
|  | 602 | * | 
|  | 603 | * called when an opening tag has been processed. | 
|  | 604 | */ | 
|  | 605 | static void | 
|  | 606 | xmlTextReaderStartElement(void *ctx, const xmlChar *fullname, | 
|  | 607 | const xmlChar **atts) { | 
|  | 608 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; | 
|  | 609 | xmlTextReaderPtr reader = ctxt->_private; | 
|  | 610 |  | 
|  | 611 | #ifdef DEBUG_CALLBACKS | 
|  | 612 | printf("xmlTextReaderStartElement(%s)\n", fullname); | 
|  | 613 | #endif | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 614 | if ((reader != NULL) && (reader->startElement != NULL)) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 615 | reader->startElement(ctx, fullname, atts); | 
| Daniel Veillard | 067bae5 | 2003-01-05 01:27:54 +0000 | [diff] [blame] | 616 | if ((ctxt->node != NULL) && (ctxt->input != NULL) && | 
|  | 617 | (ctxt->input->cur != NULL) && (ctxt->input->cur[0] == '/') && | 
|  | 618 | (ctxt->input->cur[1] == '>')) | 
| Daniel Veillard | e8039df | 2003-10-27 11:25:13 +0000 | [diff] [blame] | 619 | ctxt->node->extra = NODE_IS_EMPTY; | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 620 | } | 
| Daniel Veillard | 9e395c2 | 2003-01-01 14:50:44 +0000 | [diff] [blame] | 621 | if (reader != NULL) | 
|  | 622 | reader->state = XML_TEXTREADER_ELEMENT; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 623 | } | 
|  | 624 |  | 
|  | 625 | /** | 
|  | 626 | * xmlTextReaderEndElement: | 
|  | 627 | * @ctx: the user data (XML parser context) | 
|  | 628 | * @fullname:  The element name, including namespace prefix | 
|  | 629 | * | 
|  | 630 | * called when an ending tag has been processed. | 
|  | 631 | */ | 
|  | 632 | static void | 
|  | 633 | xmlTextReaderEndElement(void *ctx, const xmlChar *fullname) { | 
|  | 634 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; | 
|  | 635 | xmlTextReaderPtr reader = ctxt->_private; | 
|  | 636 |  | 
|  | 637 | #ifdef DEBUG_CALLBACKS | 
|  | 638 | printf("xmlTextReaderEndElement(%s)\n", fullname); | 
|  | 639 | #endif | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 640 | if ((reader != NULL) && (reader->endElement != NULL)) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 641 | reader->endElement(ctx, fullname); | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 642 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 643 | } | 
|  | 644 |  | 
|  | 645 | /** | 
| Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 646 | * xmlTextReaderStartElementNs: | 
|  | 647 | * @ctx: the user data (XML parser context) | 
|  | 648 | * @localname:  the local name of the element | 
|  | 649 | * @prefix:  the element namespace prefix if available | 
|  | 650 | * @URI:  the element namespace name if available | 
|  | 651 | * @nb_namespaces:  number of namespace definitions on that node | 
|  | 652 | * @namespaces:  pointer to the array of prefix/URI pairs namespace definitions | 
|  | 653 | * @nb_attributes:  the number of attributes on that node | 
|  | 654 | * nb_defaulted:  the number of defaulted attributes. | 
|  | 655 | * @attributes:  pointer to the array of (localname/prefix/URI/value/end) | 
|  | 656 | *               attribute values. | 
|  | 657 | * | 
|  | 658 | * called when an opening tag has been processed. | 
|  | 659 | */ | 
|  | 660 | static void | 
|  | 661 | xmlTextReaderStartElementNs(void *ctx, | 
|  | 662 | const xmlChar *localname, | 
|  | 663 | const xmlChar *prefix, | 
|  | 664 | const xmlChar *URI, | 
|  | 665 | int nb_namespaces, | 
|  | 666 | const xmlChar **namespaces, | 
|  | 667 | int nb_attributes, | 
|  | 668 | int nb_defaulted, | 
|  | 669 | const xmlChar **attributes) | 
|  | 670 | { | 
|  | 671 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; | 
|  | 672 | xmlTextReaderPtr reader = ctxt->_private; | 
|  | 673 |  | 
|  | 674 | #ifdef DEBUG_CALLBACKS | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 675 | printf("xmlTextReaderStartElementNs(%s)\n", localname); | 
| Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 676 | #endif | 
|  | 677 | if ((reader != NULL) && (reader->startElementNs != NULL)) { | 
|  | 678 | reader->startElementNs(ctx, localname, prefix, URI, nb_namespaces, | 
|  | 679 | namespaces, nb_attributes, nb_defaulted, | 
|  | 680 | attributes); | 
|  | 681 | if ((ctxt->node != NULL) && (ctxt->input != NULL) && | 
|  | 682 | (ctxt->input->cur != NULL) && (ctxt->input->cur[0] == '/') && | 
|  | 683 | (ctxt->input->cur[1] == '>')) | 
| Daniel Veillard | e8039df | 2003-10-27 11:25:13 +0000 | [diff] [blame] | 684 | ctxt->node->extra = NODE_IS_EMPTY; | 
| Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 685 | } | 
|  | 686 | if (reader != NULL) | 
|  | 687 | reader->state = XML_TEXTREADER_ELEMENT; | 
|  | 688 | } | 
|  | 689 |  | 
|  | 690 | /** | 
|  | 691 | * xmlTextReaderEndElementNs: | 
|  | 692 | * @ctx: the user data (XML parser context) | 
|  | 693 | * @localname:  the local name of the element | 
|  | 694 | * @prefix:  the element namespace prefix if available | 
|  | 695 | * @URI:  the element namespace name if available | 
|  | 696 | * | 
|  | 697 | * called when an ending tag has been processed. | 
|  | 698 | */ | 
|  | 699 | static void | 
|  | 700 | xmlTextReaderEndElementNs(void *ctx, | 
|  | 701 | const xmlChar * localname, | 
|  | 702 | const xmlChar * prefix, | 
|  | 703 | const xmlChar * URI) | 
|  | 704 | { | 
|  | 705 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; | 
|  | 706 | xmlTextReaderPtr reader = ctxt->_private; | 
|  | 707 |  | 
|  | 708 | #ifdef DEBUG_CALLBACKS | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 709 | printf("xmlTextReaderEndElementNs(%s)\n", localname); | 
| Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 710 | #endif | 
|  | 711 | if ((reader != NULL) && (reader->endElementNs != NULL)) { | 
|  | 712 | reader->endElementNs(ctx, localname, prefix, URI); | 
|  | 713 | } | 
|  | 714 | } | 
|  | 715 |  | 
|  | 716 |  | 
|  | 717 | /** | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 718 | * xmlTextReaderCharacters: | 
|  | 719 | * @ctx: the user data (XML parser context) | 
|  | 720 | * @ch:  a xmlChar string | 
|  | 721 | * @len: the number of xmlChar | 
|  | 722 | * | 
|  | 723 | * receiving some chars from the parser. | 
|  | 724 | */ | 
|  | 725 | static void | 
|  | 726 | xmlTextReaderCharacters(void *ctx, const xmlChar *ch, int len) | 
|  | 727 | { | 
|  | 728 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; | 
|  | 729 | xmlTextReaderPtr reader = ctxt->_private; | 
|  | 730 |  | 
|  | 731 | #ifdef DEBUG_CALLBACKS | 
|  | 732 | printf("xmlTextReaderCharacters()\n"); | 
|  | 733 | #endif | 
|  | 734 | if ((reader != NULL) && (reader->characters != NULL)) { | 
|  | 735 | reader->characters(ctx, ch, len); | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 736 | } | 
|  | 737 | } | 
|  | 738 |  | 
|  | 739 | /** | 
|  | 740 | * xmlTextReaderCDataBlock: | 
|  | 741 | * @ctx: the user data (XML parser context) | 
|  | 742 | * @value:  The pcdata content | 
|  | 743 | * @len:  the block length | 
|  | 744 | * | 
|  | 745 | * called when a pcdata block has been parsed | 
|  | 746 | */ | 
|  | 747 | static void | 
|  | 748 | xmlTextReaderCDataBlock(void *ctx, const xmlChar *ch, int len) | 
|  | 749 | { | 
|  | 750 | xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; | 
|  | 751 | xmlTextReaderPtr reader = ctxt->_private; | 
|  | 752 |  | 
|  | 753 | #ifdef DEBUG_CALLBACKS | 
|  | 754 | printf("xmlTextReaderCDataBlock()\n"); | 
|  | 755 | #endif | 
|  | 756 | if ((reader != NULL) && (reader->cdataBlock != NULL)) { | 
|  | 757 | reader->cdataBlock(ctx, ch, len); | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 758 | } | 
|  | 759 | } | 
|  | 760 |  | 
|  | 761 | /** | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 762 | * xmlTextReaderPushData: | 
|  | 763 | * @reader:  the xmlTextReaderPtr used | 
|  | 764 | * | 
|  | 765 | * Push data down the progressive parser until a significant callback | 
|  | 766 | * got raised. | 
|  | 767 | * | 
|  | 768 | * Returns -1 in case of failure, 0 otherwise | 
|  | 769 | */ | 
|  | 770 | static int | 
|  | 771 | xmlTextReaderPushData(xmlTextReaderPtr reader) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 772 | xmlBufferPtr inbuf; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 773 | int val, s; | 
| William M. Brack | 779af00 | 2003-08-01 15:55:39 +0000 | [diff] [blame] | 774 | xmlTextReaderState oldstate; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 775 |  | 
|  | 776 | if ((reader->input == NULL) || (reader->input->buffer == NULL)) | 
|  | 777 | return(-1); | 
|  | 778 |  | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 779 | oldstate = reader->state; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 780 | reader->state = XML_TEXTREADER_NONE; | 
|  | 781 | inbuf = reader->input->buffer; | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 782 |  | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 783 | while (reader->state == XML_TEXTREADER_NONE) { | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 784 | if (inbuf->use < reader->cur + CHUNK_SIZE) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 785 | /* | 
|  | 786 | * Refill the buffer unless we are at the end of the stream | 
|  | 787 | */ | 
|  | 788 | if (reader->mode != XML_TEXTREADER_MODE_EOF) { | 
|  | 789 | val = xmlParserInputBufferRead(reader->input, 4096); | 
| Daniel Veillard | 5335055 | 2003-09-18 13:35:51 +0000 | [diff] [blame] | 790 | if ((val == 0) && | 
|  | 791 | (inbuf->alloc == XML_BUFFER_ALLOC_IMMUTABLE)) { | 
|  | 792 | if (inbuf->use == reader->cur) { | 
|  | 793 | reader->mode = XML_TEXTREADER_MODE_EOF; | 
|  | 794 | reader->state = oldstate; | 
|  | 795 | if ((oldstate != XML_TEXTREADER_START) || | 
|  | 796 | (reader->ctxt->myDoc != NULL)) | 
|  | 797 | return(val); | 
|  | 798 | } | 
|  | 799 | } else if (val < 0) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 800 | reader->mode = XML_TEXTREADER_MODE_EOF; | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 801 | reader->state = oldstate; | 
| Daniel Veillard | aaa105b | 2002-12-30 11:42:17 +0000 | [diff] [blame] | 802 | if ((oldstate != XML_TEXTREADER_START) || | 
|  | 803 | (reader->ctxt->myDoc != NULL)) | 
|  | 804 | return(val); | 
| Daniel Veillard | 5335055 | 2003-09-18 13:35:51 +0000 | [diff] [blame] | 805 | } else if (val == 0) { | 
|  | 806 | /* mark the end of the stream and process the remains */ | 
|  | 807 | reader->mode = XML_TEXTREADER_MODE_EOF; | 
|  | 808 | break; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 809 | } | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 810 |  | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 811 | } else | 
|  | 812 | break; | 
|  | 813 | } | 
| Daniel Veillard | 067bae5 | 2003-01-05 01:27:54 +0000 | [diff] [blame] | 814 | /* | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 815 | * parse by block of CHUNK_SIZE bytes, various tests show that | 
|  | 816 | * it's the best tradeoff at least on a 1.2GH Duron | 
| Daniel Veillard | 067bae5 | 2003-01-05 01:27:54 +0000 | [diff] [blame] | 817 | */ | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 818 | if (inbuf->use >= reader->cur + CHUNK_SIZE) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 819 | val = xmlParseChunk(reader->ctxt, | 
|  | 820 | (const char *) &inbuf->content[reader->cur], | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 821 | CHUNK_SIZE, 0); | 
|  | 822 | reader->cur += CHUNK_SIZE; | 
| Daniel Veillard | 16ed597 | 2003-11-20 18:22:31 +0000 | [diff] [blame] | 823 | if ((val != 0) && (reader->ctxt->wellFormed == 0)) | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 824 | return(-1); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 825 | } else { | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 826 | s = inbuf->use - reader->cur; | 
|  | 827 | val = xmlParseChunk(reader->ctxt, | 
|  | 828 | (const char *) &inbuf->content[reader->cur], | 
|  | 829 | s, 0); | 
|  | 830 | reader->cur += s; | 
| Daniel Veillard | 16ed597 | 2003-11-20 18:22:31 +0000 | [diff] [blame] | 831 | if ((val != 0) && (reader->ctxt->wellFormed == 0)) | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 832 | return(-1); | 
|  | 833 | break; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 834 | } | 
|  | 835 | } | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 836 |  | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 837 | /* | 
|  | 838 | * Discard the consumed input when needed and possible | 
|  | 839 | */ | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 840 | if (reader->mode == XML_TEXTREADER_MODE_INTERACTIVE) { | 
| Daniel Veillard | f6bc7c2 | 2003-09-17 22:33:22 +0000 | [diff] [blame] | 841 | if ((reader->cur >= 4096) && | 
|  | 842 | (inbuf->use - reader->cur <= CHUNK_SIZE)) { | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 843 | val = xmlBufferShrink(inbuf, reader->cur); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 844 | if (val >= 0) { | 
|  | 845 | reader->cur -= val; | 
|  | 846 | } | 
|  | 847 | } | 
|  | 848 | } | 
|  | 849 |  | 
|  | 850 | /* | 
|  | 851 | * At the end of the stream signal that the work is done to the Push | 
|  | 852 | * parser. | 
|  | 853 | */ | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 854 | else if (reader->mode == XML_TEXTREADER_MODE_EOF) { | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 855 | if (reader->mode != XML_TEXTREADER_DONE) { | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 856 | s = inbuf->use - reader->cur; | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 857 | val = xmlParseChunk(reader->ctxt, | 
| Daniel Veillard | 067bae5 | 2003-01-05 01:27:54 +0000 | [diff] [blame] | 858 | (const char *) &inbuf->content[reader->cur], | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 859 | s, 1); | 
|  | 860 | reader->cur = inbuf->use; | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 861 | reader->mode = XML_TEXTREADER_DONE; | 
| Daniel Veillard | 16ed597 | 2003-11-20 18:22:31 +0000 | [diff] [blame] | 862 | if ((val != 0) && (reader->ctxt->wellFormed == 0)) | 
|  | 863 | return(-1); | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 864 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 865 | } | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 866 | reader->state = oldstate; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 867 | return(0); | 
|  | 868 | } | 
|  | 869 |  | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 870 | #ifdef LIBXML_REGEXP_ENABLED | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 871 | /** | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 872 | * xmlTextReaderValidatePush: | 
|  | 873 | * @reader:  the xmlTextReaderPtr used | 
|  | 874 | * | 
|  | 875 | * Push the current node for validation | 
|  | 876 | */ | 
|  | 877 | static void | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 878 | xmlTextReaderValidatePush(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) { | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 879 | xmlNodePtr node = reader->node; | 
|  | 880 |  | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 881 | if ((reader->validate == XML_TEXTREADER_VALIDATE_DTD) && | 
|  | 882 | (reader->ctxt != NULL) && (reader->ctxt->validate == 1)) { | 
|  | 883 | if ((node->ns == NULL) || (node->ns->prefix == NULL)) { | 
|  | 884 | reader->ctxt->valid &= xmlValidatePushElement(&reader->ctxt->vctxt, | 
|  | 885 | reader->ctxt->myDoc, node, node->name); | 
|  | 886 | } else { | 
|  | 887 | /* TODO use the BuildQName interface */ | 
|  | 888 | xmlChar *qname; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 889 |  | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 890 | qname = xmlStrdup(node->ns->prefix); | 
|  | 891 | qname = xmlStrcat(qname, BAD_CAST ":"); | 
|  | 892 | qname = xmlStrcat(qname, node->name); | 
|  | 893 | reader->ctxt->valid &= xmlValidatePushElement(&reader->ctxt->vctxt, | 
|  | 894 | reader->ctxt->myDoc, node, qname); | 
|  | 895 | if (qname != NULL) | 
|  | 896 | xmlFree(qname); | 
|  | 897 | } | 
|  | 898 | #ifdef LIBXML_SCHEMAS_ENABLED | 
|  | 899 | } else if ((reader->validate == XML_TEXTREADER_VALIDATE_RNG) && | 
|  | 900 | (reader->rngValidCtxt != NULL)) { | 
|  | 901 | int ret; | 
|  | 902 |  | 
|  | 903 | if (reader->rngFullNode != NULL) return; | 
|  | 904 | ret = xmlRelaxNGValidatePushElement(reader->rngValidCtxt, | 
|  | 905 | reader->ctxt->myDoc, | 
|  | 906 | node); | 
|  | 907 | if (ret == 0) { | 
|  | 908 | /* | 
|  | 909 | * this element requires a full tree | 
|  | 910 | */ | 
|  | 911 | node = xmlTextReaderExpand(reader); | 
|  | 912 | if (node == NULL) { | 
|  | 913 | printf("Expand failed !\n"); | 
|  | 914 | ret = -1; | 
|  | 915 | } else { | 
|  | 916 | ret = xmlRelaxNGValidateFullElement(reader->rngValidCtxt, | 
|  | 917 | reader->ctxt->myDoc, | 
|  | 918 | node); | 
|  | 919 | reader->rngFullNode = node; | 
|  | 920 | } | 
|  | 921 | } | 
|  | 922 | if (ret != 1) | 
|  | 923 | reader->rngValidErrors++; | 
|  | 924 | #endif | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 925 | } | 
|  | 926 | } | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 927 |  | 
|  | 928 | /** | 
|  | 929 | * xmlTextReaderValidateCData: | 
|  | 930 | * @reader:  the xmlTextReaderPtr used | 
|  | 931 | * @data:  pointer to the CData | 
|  | 932 | * @len:  lenght of the CData block in bytes. | 
|  | 933 | * | 
|  | 934 | * Push some CData for validation | 
|  | 935 | */ | 
|  | 936 | static void | 
|  | 937 | xmlTextReaderValidateCData(xmlTextReaderPtr reader, | 
|  | 938 | const xmlChar *data, int len) { | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 939 | if ((reader->validate == XML_TEXTREADER_VALIDATE_DTD) && | 
|  | 940 | (reader->ctxt != NULL) && (reader->ctxt->validate == 1)) { | 
|  | 941 | reader->ctxt->valid &= xmlValidatePushCData(&reader->ctxt->vctxt, | 
|  | 942 | data, len); | 
|  | 943 | #ifdef LIBXML_SCHEMAS_ENABLED | 
|  | 944 | } else if ((reader->validate == XML_TEXTREADER_VALIDATE_RNG) && | 
|  | 945 | (reader->rngValidCtxt != NULL)) { | 
|  | 946 | int ret; | 
|  | 947 |  | 
|  | 948 | if (reader->rngFullNode != NULL) return; | 
|  | 949 | ret = xmlRelaxNGValidatePushCData(reader->rngValidCtxt, data, len); | 
|  | 950 | if (ret != 1) | 
|  | 951 | reader->rngValidErrors++; | 
|  | 952 | #endif | 
|  | 953 | } | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 954 | } | 
|  | 955 |  | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 956 | /** | 
|  | 957 | * xmlTextReaderValidatePop: | 
|  | 958 | * @reader:  the xmlTextReaderPtr used | 
|  | 959 | * | 
|  | 960 | * Pop the current node from validation | 
|  | 961 | */ | 
|  | 962 | static void | 
|  | 963 | xmlTextReaderValidatePop(xmlTextReaderPtr reader) { | 
|  | 964 | xmlNodePtr node = reader->node; | 
|  | 965 |  | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 966 | if ((reader->validate == XML_TEXTREADER_VALIDATE_DTD) && | 
|  | 967 | (reader->ctxt != NULL) && (reader->ctxt->validate == 1)) { | 
|  | 968 | if ((node->ns == NULL) || (node->ns->prefix == NULL)) { | 
|  | 969 | reader->ctxt->valid &= xmlValidatePopElement(&reader->ctxt->vctxt, | 
|  | 970 | reader->ctxt->myDoc, node, node->name); | 
|  | 971 | } else { | 
|  | 972 | /* TODO use the BuildQName interface */ | 
|  | 973 | xmlChar *qname; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 974 |  | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 975 | qname = xmlStrdup(node->ns->prefix); | 
|  | 976 | qname = xmlStrcat(qname, BAD_CAST ":"); | 
|  | 977 | qname = xmlStrcat(qname, node->name); | 
|  | 978 | reader->ctxt->valid &= xmlValidatePopElement(&reader->ctxt->vctxt, | 
|  | 979 | reader->ctxt->myDoc, node, qname); | 
|  | 980 | if (qname != NULL) | 
|  | 981 | xmlFree(qname); | 
|  | 982 | } | 
|  | 983 | #ifdef LIBXML_SCHEMAS_ENABLED | 
|  | 984 | } else if ((reader->validate == XML_TEXTREADER_VALIDATE_RNG) && | 
|  | 985 | (reader->rngValidCtxt != NULL)) { | 
|  | 986 | int ret; | 
|  | 987 |  | 
|  | 988 | if (reader->rngFullNode != NULL) { | 
|  | 989 | if (node == reader->rngFullNode) | 
|  | 990 | reader->rngFullNode = NULL; | 
|  | 991 | return; | 
|  | 992 | } | 
|  | 993 | ret = xmlRelaxNGValidatePopElement(reader->rngValidCtxt, | 
|  | 994 | reader->ctxt->myDoc, | 
|  | 995 | node); | 
|  | 996 | if (ret != 1) | 
|  | 997 | reader->rngValidErrors++; | 
|  | 998 | #endif | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 999 | } | 
|  | 1000 | } | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1001 |  | 
| Daniel Veillard | a80ff6e | 2003-01-03 12:52:08 +0000 | [diff] [blame] | 1002 | /** | 
|  | 1003 | * xmlTextReaderValidateEntity: | 
|  | 1004 | * @reader:  the xmlTextReaderPtr used | 
|  | 1005 | * | 
|  | 1006 | * Handle the validation when an entity reference is encountered and | 
|  | 1007 | * entity substitution is not activated. As a result the parser interface | 
|  | 1008 | * must walk through the entity and do the validation calls | 
|  | 1009 | */ | 
|  | 1010 | static void | 
|  | 1011 | xmlTextReaderValidateEntity(xmlTextReaderPtr reader) { | 
|  | 1012 | xmlNodePtr oldnode = reader->node; | 
|  | 1013 | xmlNodePtr node = reader->node; | 
|  | 1014 | xmlParserCtxtPtr ctxt = reader->ctxt; | 
|  | 1015 |  | 
|  | 1016 | do { | 
|  | 1017 | if (node->type == XML_ENTITY_REF_NODE) { | 
|  | 1018 | /* | 
|  | 1019 | * Case where the underlying tree is not availble, lookup the entity | 
|  | 1020 | * and walk it. | 
|  | 1021 | */ | 
|  | 1022 | if ((node->children == NULL) && (ctxt->sax != NULL) && | 
|  | 1023 | (ctxt->sax->getEntity != NULL)) { | 
|  | 1024 | node->children = (xmlNodePtr) | 
|  | 1025 | ctxt->sax->getEntity(ctxt, node->name); | 
|  | 1026 | } | 
|  | 1027 |  | 
|  | 1028 | if ((node->children != NULL) && | 
|  | 1029 | (node->children->type == XML_ENTITY_DECL) && | 
|  | 1030 | (node->children->children != NULL)) { | 
|  | 1031 | xmlTextReaderEntPush(reader, node); | 
|  | 1032 | node = node->children->children; | 
|  | 1033 | continue; | 
|  | 1034 | } else { | 
|  | 1035 | /* | 
|  | 1036 | * The error has probably be raised already. | 
|  | 1037 | */ | 
|  | 1038 | if (node == oldnode) | 
|  | 1039 | break; | 
|  | 1040 | node = node->next; | 
|  | 1041 | } | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1042 | #ifdef LIBXML_REGEXP_ENABLED | 
| Daniel Veillard | a80ff6e | 2003-01-03 12:52:08 +0000 | [diff] [blame] | 1043 | } else if (node->type == XML_ELEMENT_NODE) { | 
|  | 1044 | reader->node = node; | 
|  | 1045 | xmlTextReaderValidatePush(reader); | 
|  | 1046 | } else if ((node->type == XML_TEXT_NODE) || | 
|  | 1047 | (node->type == XML_CDATA_SECTION_NODE)) { | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 1048 | xmlTextReaderValidateCData(reader, node->content, | 
|  | 1049 | xmlStrlen(node->content)); | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1050 | #endif | 
| Daniel Veillard | a80ff6e | 2003-01-03 12:52:08 +0000 | [diff] [blame] | 1051 | } | 
|  | 1052 |  | 
|  | 1053 | /* | 
|  | 1054 | * go to next node | 
|  | 1055 | */ | 
|  | 1056 | if (node->children != NULL) { | 
|  | 1057 | node = node->children; | 
|  | 1058 | continue; | 
| Daniel Veillard | ef8dd7b | 2003-03-23 12:02:56 +0000 | [diff] [blame] | 1059 | } else if (node->type == XML_ELEMENT_NODE) { | 
|  | 1060 | xmlTextReaderValidatePop(reader); | 
| Daniel Veillard | a80ff6e | 2003-01-03 12:52:08 +0000 | [diff] [blame] | 1061 | } | 
|  | 1062 | if (node->next != NULL) { | 
|  | 1063 | node = node->next; | 
|  | 1064 | continue; | 
|  | 1065 | } | 
|  | 1066 | do { | 
|  | 1067 | node = node->parent; | 
|  | 1068 | if (node->type == XML_ELEMENT_NODE) { | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 1069 | xmlNodePtr tmp; | 
| Daniel Veillard | 1d211e2 | 2003-10-20 22:32:39 +0000 | [diff] [blame] | 1070 | if (reader->entNr == 0) { | 
|  | 1071 | while ((tmp = node->last) != NULL) { | 
| Daniel Veillard | e8039df | 2003-10-27 11:25:13 +0000 | [diff] [blame] | 1072 | if ((tmp->extra & NODE_IS_PRESERVED) == 0) { | 
| Daniel Veillard | 1d211e2 | 2003-10-20 22:32:39 +0000 | [diff] [blame] | 1073 | xmlUnlinkNode(tmp); | 
|  | 1074 | xmlTextReaderFreeNode(reader, tmp); | 
|  | 1075 | } else | 
|  | 1076 | break; | 
|  | 1077 | } | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 1078 | } | 
| Daniel Veillard | a80ff6e | 2003-01-03 12:52:08 +0000 | [diff] [blame] | 1079 | reader->node = node; | 
|  | 1080 | xmlTextReaderValidatePop(reader); | 
|  | 1081 | } | 
|  | 1082 | if ((node->type == XML_ENTITY_DECL) && | 
|  | 1083 | (reader->ent != NULL) && (reader->ent->children == node)) { | 
|  | 1084 | node = xmlTextReaderEntPop(reader); | 
|  | 1085 | } | 
|  | 1086 | if (node == oldnode) | 
|  | 1087 | break; | 
|  | 1088 | if (node->next != NULL) { | 
|  | 1089 | node = node->next; | 
|  | 1090 | break; | 
|  | 1091 | } | 
|  | 1092 | } while ((node != NULL) && (node != oldnode)); | 
|  | 1093 | } while ((node != NULL) && (node != oldnode)); | 
|  | 1094 | reader->node = oldnode; | 
|  | 1095 | } | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1096 | #endif /* LIBXML_REGEXP_ENABLED */ | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1097 |  | 
|  | 1098 |  | 
|  | 1099 | /** | 
| Daniel Veillard | c6cae7b | 2003-04-11 09:02:11 +0000 | [diff] [blame] | 1100 | * xmlTextReaderGetSuccessor: | 
|  | 1101 | * @cur:  the current node | 
|  | 1102 | * | 
|  | 1103 | * Get the successor of a node if available. | 
|  | 1104 | * | 
|  | 1105 | * Returns the successor node or NULL | 
|  | 1106 | */ | 
|  | 1107 | static xmlNodePtr | 
|  | 1108 | xmlTextReaderGetSuccessor(xmlNodePtr cur) { | 
|  | 1109 | if (cur == NULL) return(NULL) ; /* ERROR */ | 
|  | 1110 | if (cur->next != NULL) return(cur->next) ; | 
|  | 1111 | do { | 
|  | 1112 | cur = cur->parent; | 
|  | 1113 | if (cur == NULL) return(NULL); | 
|  | 1114 | if (cur->next != NULL) return(cur->next); | 
|  | 1115 | } while (cur != NULL); | 
|  | 1116 | return(cur); | 
|  | 1117 | } | 
|  | 1118 |  | 
|  | 1119 | /** | 
|  | 1120 | * xmlTextReaderDoExpand: | 
|  | 1121 | * @reader:  the xmlTextReaderPtr used | 
|  | 1122 | * | 
|  | 1123 | * Makes sure that the current node is fully read as well as all its | 
|  | 1124 | * descendant. It means the full DOM subtree must be available at the | 
|  | 1125 | * end of the call. | 
|  | 1126 | * | 
|  | 1127 | * Returns 1 if the node was expanded successfully, 0 if there is no more | 
|  | 1128 | *          nodes to read, or -1 in case of error | 
|  | 1129 | */ | 
|  | 1130 | static int | 
|  | 1131 | xmlTextReaderDoExpand(xmlTextReaderPtr reader) { | 
|  | 1132 | int val; | 
|  | 1133 |  | 
|  | 1134 | if ((reader == NULL) || (reader->node == NULL) || (reader->ctxt == NULL)) | 
|  | 1135 | return(-1); | 
| Daniel Veillard | c6cae7b | 2003-04-11 09:02:11 +0000 | [diff] [blame] | 1136 | do { | 
| Daniel Veillard | f96cf4e | 2003-10-01 09:05:25 +0000 | [diff] [blame] | 1137 | if (reader->ctxt->instate == XML_PARSER_EOF) return(1); | 
|  | 1138 |  | 
| Daniel Veillard | c6cae7b | 2003-04-11 09:02:11 +0000 | [diff] [blame] | 1139 | if (xmlTextReaderGetSuccessor(reader->node) != NULL) | 
|  | 1140 | return(1); | 
| Daniel Veillard | f96cf4e | 2003-10-01 09:05:25 +0000 | [diff] [blame] | 1141 | if (reader->ctxt->nodeNr < reader->depth) | 
| Daniel Veillard | a37aab8 | 2003-06-09 09:10:36 +0000 | [diff] [blame] | 1142 | return(1); | 
| Daniel Veillard | c6cae7b | 2003-04-11 09:02:11 +0000 | [diff] [blame] | 1143 | if (reader->mode == XML_TEXTREADER_MODE_EOF) | 
|  | 1144 | return(1); | 
|  | 1145 | val = xmlTextReaderPushData(reader); | 
|  | 1146 | if (val < 0) | 
|  | 1147 | return(-1); | 
|  | 1148 | } while(reader->mode != XML_TEXTREADER_MODE_EOF); | 
|  | 1149 | return(1); | 
|  | 1150 | } | 
|  | 1151 |  | 
|  | 1152 | /** | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1153 | * xmlTextReaderRead: | 
|  | 1154 | * @reader:  the xmlTextReaderPtr used | 
|  | 1155 | * | 
|  | 1156 | *  Moves the position of the current instance to the next node in | 
|  | 1157 | *  the stream, exposing its properties. | 
|  | 1158 | * | 
|  | 1159 | *  Returns 1 if the node was read successfully, 0 if there is no more | 
|  | 1160 | *          nodes to read, or -1 in case of error | 
|  | 1161 | */ | 
|  | 1162 | int | 
|  | 1163 | xmlTextReaderRead(xmlTextReaderPtr reader) { | 
| Daniel Veillard | 067bae5 | 2003-01-05 01:27:54 +0000 | [diff] [blame] | 1164 | int val, olddepth = 0; | 
| William M. Brack | 899e64a | 2003-09-26 18:03:42 +0000 | [diff] [blame] | 1165 | xmlTextReaderState oldstate = XML_TEXTREADER_START; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1166 | xmlNodePtr oldnode = NULL; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1167 |  | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1168 |  | 
|  | 1169 | if (reader == NULL) | 
|  | 1170 | return(-1); | 
|  | 1171 | if (reader->doc != NULL) | 
|  | 1172 | return(xmlTextReaderReadTree(reader)); | 
|  | 1173 | if (reader->ctxt == NULL) | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1174 | return(-1); | 
|  | 1175 | if (reader->ctxt->wellFormed != 1) | 
|  | 1176 | return(-1); | 
|  | 1177 |  | 
|  | 1178 | #ifdef DEBUG_READER | 
|  | 1179 | fprintf(stderr, "\nREAD "); | 
|  | 1180 | DUMP_READER | 
|  | 1181 | #endif | 
| Daniel Veillard | 29b3e28 | 2002-12-29 11:14:41 +0000 | [diff] [blame] | 1182 | reader->curnode = NULL; | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 1183 | if (reader->mode == XML_TEXTREADER_MODE_INITIAL) { | 
|  | 1184 | reader->mode = XML_TEXTREADER_MODE_INTERACTIVE; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1185 | /* | 
|  | 1186 | * Initial state | 
|  | 1187 | */ | 
|  | 1188 | do { | 
|  | 1189 | val = xmlTextReaderPushData(reader); | 
|  | 1190 | if (val < 0) | 
|  | 1191 | return(-1); | 
|  | 1192 | } while ((reader->ctxt->node == NULL) && | 
| Daniel Veillard | 067bae5 | 2003-01-05 01:27:54 +0000 | [diff] [blame] | 1193 | ((reader->mode != XML_TEXTREADER_MODE_EOF) && | 
|  | 1194 | (reader->mode != XML_TEXTREADER_DONE))); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1195 | if (reader->ctxt->node == NULL) { | 
| Daniel Veillard | dab8ea9 | 2003-01-02 14:16:45 +0000 | [diff] [blame] | 1196 | if (reader->ctxt->myDoc != NULL) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1197 | reader->node = reader->ctxt->myDoc->children; | 
| Daniel Veillard | dab8ea9 | 2003-01-02 14:16:45 +0000 | [diff] [blame] | 1198 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1199 | if (reader->node == NULL) | 
|  | 1200 | return(-1); | 
| Daniel Veillard | dab8ea9 | 2003-01-02 14:16:45 +0000 | [diff] [blame] | 1201 | reader->state = XML_TEXTREADER_ELEMENT; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1202 | } else { | 
| Daniel Veillard | 48ef4c9 | 2003-03-22 12:38:15 +0000 | [diff] [blame] | 1203 | if (reader->ctxt->myDoc != NULL) { | 
|  | 1204 | reader->node = reader->ctxt->myDoc->children; | 
|  | 1205 | } | 
|  | 1206 | if (reader->node == NULL) | 
|  | 1207 | reader->node = reader->ctxt->nodeTab[0]; | 
| Daniel Veillard | e59494f | 2003-01-04 16:35:29 +0000 | [diff] [blame] | 1208 | reader->state = XML_TEXTREADER_ELEMENT; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1209 | } | 
| Daniel Veillard | 4d8db8a | 2002-12-30 18:40:42 +0000 | [diff] [blame] | 1210 | reader->depth = 0; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1211 | goto node_found; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1212 | } | 
|  | 1213 | oldstate = reader->state; | 
|  | 1214 | olddepth = reader->ctxt->nodeNr; | 
|  | 1215 | oldnode = reader->node; | 
| Daniel Veillard | df512f4 | 2002-12-23 15:56:21 +0000 | [diff] [blame] | 1216 |  | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1217 | get_next_node: | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1218 | /* | 
|  | 1219 | * If we are not backtracking on ancestors or examined nodes, | 
|  | 1220 | * that the parser didn't finished or that we arent at the end | 
|  | 1221 | * of stream, continue processing. | 
|  | 1222 | */ | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 1223 | while ((reader->node->next == NULL) && | 
|  | 1224 | (reader->ctxt->nodeNr == olddepth) && | 
|  | 1225 | ((oldstate == XML_TEXTREADER_BACKTRACK) || | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1226 | (reader->node->children == NULL) || | 
|  | 1227 | (reader->node->type == XML_ENTITY_REF_NODE) || | 
| Daniel Veillard | 409a814 | 2003-07-18 15:16:57 +0000 | [diff] [blame] | 1228 | ((reader->node->children != NULL) && | 
|  | 1229 | (reader->node->children->type == XML_TEXT_NODE) && | 
|  | 1230 | (reader->node->children->next == NULL)) || | 
| Daniel Veillard | 4dbe77a | 2003-01-14 00:17:42 +0000 | [diff] [blame] | 1231 | (reader->node->type == XML_DTD_NODE) || | 
|  | 1232 | (reader->node->type == XML_DOCUMENT_NODE) || | 
|  | 1233 | (reader->node->type == XML_HTML_DOCUMENT_NODE)) && | 
| Daniel Veillard | 4dbe77a | 2003-01-14 00:17:42 +0000 | [diff] [blame] | 1234 | ((reader->ctxt->node == NULL) || | 
|  | 1235 | (reader->ctxt->node == reader->node) || | 
|  | 1236 | (reader->ctxt->node == reader->node->parent)) && | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1237 | (reader->ctxt->instate != XML_PARSER_EOF)) { | 
|  | 1238 | val = xmlTextReaderPushData(reader); | 
|  | 1239 | if (val < 0) | 
|  | 1240 | return(-1); | 
|  | 1241 | if (reader->node == NULL) | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1242 | goto node_end; | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1243 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1244 | if (oldstate != XML_TEXTREADER_BACKTRACK) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1245 | if ((reader->node->children != NULL) && | 
|  | 1246 | (reader->node->type != XML_ENTITY_REF_NODE) && | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1247 | (reader->node->type != XML_XINCLUDE_START) && | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1248 | (reader->node->type != XML_DTD_NODE)) { | 
|  | 1249 | reader->node = reader->node->children; | 
|  | 1250 | reader->depth++; | 
| Daniel Veillard | df512f4 | 2002-12-23 15:56:21 +0000 | [diff] [blame] | 1251 | reader->state = XML_TEXTREADER_ELEMENT; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1252 | goto node_found; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1253 | } | 
|  | 1254 | } | 
|  | 1255 | if (reader->node->next != NULL) { | 
|  | 1256 | if ((oldstate == XML_TEXTREADER_ELEMENT) && | 
| Daniel Veillard | df512f4 | 2002-12-23 15:56:21 +0000 | [diff] [blame] | 1257 | (reader->node->type == XML_ELEMENT_NODE) && | 
| Daniel Veillard | 067bae5 | 2003-01-05 01:27:54 +0000 | [diff] [blame] | 1258 | (reader->node->children == NULL) && | 
| Daniel Veillard | 96b6cd2 | 2004-01-08 16:49:50 +0000 | [diff] [blame^] | 1259 | ((reader->node->extra & NODE_IS_EMPTY) == 0) | 
|  | 1260 | #ifdef LIBXML_XINCLUDE_ENABLED | 
|  | 1261 | && (reader->in_xinclude <= 0) | 
|  | 1262 | #endif | 
|  | 1263 | ) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1264 | reader->state = XML_TEXTREADER_END; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1265 | goto node_found; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1266 | } | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1267 | #ifdef LIBXML_REGEXP_ENABLED | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 1268 | if ((reader->validate) && | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1269 | (reader->node->type == XML_ELEMENT_NODE)) | 
|  | 1270 | xmlTextReaderValidatePop(reader); | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1271 | #endif /* LIBXML_REGEXP_ENABLED */ | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1272 | if ((reader->preserves > 0) && | 
|  | 1273 | (reader->node->extra & NODE_IS_SPRESERVED)) | 
|  | 1274 | reader->preserves--; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1275 | reader->node = reader->node->next; | 
|  | 1276 | reader->state = XML_TEXTREADER_ELEMENT; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1277 |  | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1278 | /* | 
|  | 1279 | * Cleanup of the old node | 
|  | 1280 | */ | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1281 | if ((reader->preserves == 0) && | 
| Daniel Veillard | 96b6cd2 | 2004-01-08 16:49:50 +0000 | [diff] [blame^] | 1282 | #ifdef LIBXML_XINCLUDE_ENABLED | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1283 | (reader->in_xinclude == 0) && | 
| Daniel Veillard | 96b6cd2 | 2004-01-08 16:49:50 +0000 | [diff] [blame^] | 1284 | #endif | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1285 | (reader->entNr == 0) && | 
|  | 1286 | (reader->node->prev != NULL) && | 
| Daniel Veillard | 1d211e2 | 2003-10-20 22:32:39 +0000 | [diff] [blame] | 1287 | (reader->node->prev->type != XML_DTD_NODE) && | 
|  | 1288 | (reader->entNr == 0)) { | 
| Daniel Veillard | 4dbe77a | 2003-01-14 00:17:42 +0000 | [diff] [blame] | 1289 | xmlNodePtr tmp = reader->node->prev; | 
| Daniel Veillard | e8039df | 2003-10-27 11:25:13 +0000 | [diff] [blame] | 1290 | if ((tmp->extra & NODE_IS_PRESERVED) == 0) { | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 1291 | xmlUnlinkNode(tmp); | 
|  | 1292 | xmlTextReaderFreeNode(reader, tmp); | 
|  | 1293 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1294 | } | 
|  | 1295 |  | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1296 | goto node_found; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1297 | } | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1298 | if ((oldstate == XML_TEXTREADER_ELEMENT) && | 
| Daniel Veillard | 571b889 | 2002-12-30 12:37:59 +0000 | [diff] [blame] | 1299 | (reader->node->type == XML_ELEMENT_NODE) && | 
| Daniel Veillard | 067bae5 | 2003-01-05 01:27:54 +0000 | [diff] [blame] | 1300 | (reader->node->children == NULL) && | 
| Daniel Veillard | e8039df | 2003-10-27 11:25:13 +0000 | [diff] [blame] | 1301 | ((reader->node->extra & NODE_IS_EMPTY) == 0)) {; | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1302 | reader->state = XML_TEXTREADER_END; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1303 | goto node_found; | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1304 | } | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1305 | #ifdef LIBXML_REGEXP_ENABLED | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 1306 | if ((reader->validate) && (reader->node->type == XML_ELEMENT_NODE)) | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1307 | xmlTextReaderValidatePop(reader); | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1308 | #endif /* LIBXML_REGEXP_ENABLED */ | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1309 | if ((reader->preserves > 0) && | 
|  | 1310 | (reader->node->extra & NODE_IS_SPRESERVED)) | 
|  | 1311 | reader->preserves--; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1312 | reader->node = reader->node->parent; | 
|  | 1313 | if ((reader->node == NULL) || | 
|  | 1314 | (reader->node->type == XML_DOCUMENT_NODE) || | 
|  | 1315 | #ifdef LIBXML_DOCB_ENABLED | 
|  | 1316 | (reader->node->type == XML_DOCB_DOCUMENT_NODE) || | 
|  | 1317 | #endif | 
|  | 1318 | (reader->node->type == XML_HTML_DOCUMENT_NODE)) { | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1319 | if (reader->mode != XML_TEXTREADER_DONE) { | 
|  | 1320 | val = xmlParseChunk(reader->ctxt, "", 0, 1); | 
|  | 1321 | reader->mode = XML_TEXTREADER_DONE; | 
|  | 1322 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1323 | reader->node = NULL; | 
| Daniel Veillard | 4d8db8a | 2002-12-30 18:40:42 +0000 | [diff] [blame] | 1324 | reader->depth = -1; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1325 |  | 
|  | 1326 | /* | 
|  | 1327 | * Cleanup of the old node | 
|  | 1328 | */ | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1329 | if ((reader->preserves == 0) && | 
| Daniel Veillard | 96b6cd2 | 2004-01-08 16:49:50 +0000 | [diff] [blame^] | 1330 | #ifdef LIBXML_XINCLUDE_ENABLED | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1331 | (reader->in_xinclude == 0) && | 
| Daniel Veillard | 96b6cd2 | 2004-01-08 16:49:50 +0000 | [diff] [blame^] | 1332 | #endif | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1333 | (reader->entNr == 0) && | 
|  | 1334 | (oldnode->type != XML_DTD_NODE) && | 
| Daniel Veillard | e8039df | 2003-10-27 11:25:13 +0000 | [diff] [blame] | 1335 | ((oldnode->extra & NODE_IS_PRESERVED) == 0) && | 
| Daniel Veillard | 1d211e2 | 2003-10-20 22:32:39 +0000 | [diff] [blame] | 1336 | (reader->entNr == 0)) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1337 | xmlUnlinkNode(oldnode); | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 1338 | xmlTextReaderFreeNode(reader, oldnode); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1339 | } | 
|  | 1340 |  | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1341 | goto node_end; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1342 | } | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1343 | if ((reader->preserves == 0) && | 
| Daniel Veillard | 96b6cd2 | 2004-01-08 16:49:50 +0000 | [diff] [blame^] | 1344 | #ifdef LIBXML_XINCLUDE_ENABLED | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1345 | (reader->in_xinclude == 0) && | 
| Daniel Veillard | 96b6cd2 | 2004-01-08 16:49:50 +0000 | [diff] [blame^] | 1346 | #endif | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1347 | (reader->entNr == 0) && | 
|  | 1348 | (reader->node->last != NULL) && | 
|  | 1349 | ((reader->node->last->extra & NODE_IS_PRESERVED) == 0)) { | 
|  | 1350 | xmlNodePtr tmp = reader->node->last; | 
|  | 1351 | xmlUnlinkNode(tmp); | 
|  | 1352 | xmlTextReaderFreeNode(reader, tmp); | 
|  | 1353 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1354 | reader->depth--; | 
|  | 1355 | reader->state = XML_TEXTREADER_BACKTRACK; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1356 |  | 
|  | 1357 | node_found: | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1358 | DUMP_READER | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1359 |  | 
|  | 1360 | /* | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 1361 | * If we are in the middle of a piece of CDATA make sure it's finished | 
|  | 1362 | */ | 
|  | 1363 | if ((reader->node != NULL) && | 
| Daniel Veillard | ccc4d2b | 2003-09-17 21:27:31 +0000 | [diff] [blame] | 1364 | (reader->node->next == NULL) && | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 1365 | ((reader->node->type == XML_TEXT_NODE) || | 
|  | 1366 | (reader->node->type == XML_CDATA_SECTION_NODE))) { | 
|  | 1367 | xmlTextReaderExpand(reader); | 
|  | 1368 | } | 
|  | 1369 |  | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1370 | #ifdef LIBXML_XINCLUDE_ENABLED | 
|  | 1371 | /* | 
|  | 1372 | * Handle XInclude if asked for | 
|  | 1373 | */ | 
|  | 1374 | if ((reader->xinclude) && (reader->node != NULL) && | 
|  | 1375 | (reader->node->type == XML_ELEMENT_NODE) && | 
|  | 1376 | (reader->node->ns != NULL) && | 
| Daniel Veillard | b5fa020 | 2003-12-08 17:41:29 +0000 | [diff] [blame] | 1377 | ((xmlStrEqual(reader->node->ns->href, XINCLUDE_NS)) || | 
|  | 1378 | (xmlStrEqual(reader->node->ns->href, XINCLUDE_OLD_NS)))) { | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1379 | if (reader->xincctxt == NULL) { | 
|  | 1380 | reader->xincctxt = xmlXIncludeNewContext(reader->ctxt->myDoc); | 
| Daniel Veillard | e74d2e1 | 2003-12-09 11:35:37 +0000 | [diff] [blame] | 1381 | xmlXIncludeSetFlags(reader->xincctxt, reader->parserFlags); | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1382 | } | 
|  | 1383 | /* | 
|  | 1384 | * expand that node and process it | 
|  | 1385 | */ | 
|  | 1386 | xmlTextReaderExpand(reader); | 
|  | 1387 | xmlXIncludeProcessNode(reader->xincctxt, reader->node); | 
|  | 1388 | } | 
|  | 1389 | if (reader->node->type == XML_XINCLUDE_START) { | 
|  | 1390 | reader->in_xinclude++; | 
|  | 1391 | goto get_next_node; | 
|  | 1392 | } | 
|  | 1393 | if (reader->node->type == XML_XINCLUDE_END) { | 
|  | 1394 | reader->in_xinclude--; | 
|  | 1395 | goto get_next_node; | 
|  | 1396 | } | 
|  | 1397 | #endif | 
| Daniel Veillard | a880b12 | 2003-04-21 21:36:41 +0000 | [diff] [blame] | 1398 | /* | 
| Daniel Veillard | a80ff6e | 2003-01-03 12:52:08 +0000 | [diff] [blame] | 1399 | * Handle entities enter and exit when in entity replacement mode | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1400 | */ | 
|  | 1401 | if ((reader->node != NULL) && | 
|  | 1402 | (reader->node->type == XML_ENTITY_REF_NODE) && | 
|  | 1403 | (reader->ctxt != NULL) && (reader->ctxt->replaceEntities == 1)) { | 
|  | 1404 | /* | 
|  | 1405 | * Case where the underlying tree is not availble, lookup the entity | 
|  | 1406 | * and walk it. | 
|  | 1407 | */ | 
|  | 1408 | if ((reader->node->children == NULL) && (reader->ctxt->sax != NULL) && | 
|  | 1409 | (reader->ctxt->sax->getEntity != NULL)) { | 
|  | 1410 | reader->node->children = (xmlNodePtr) | 
|  | 1411 | reader->ctxt->sax->getEntity(reader->ctxt, reader->node->name); | 
|  | 1412 | } | 
|  | 1413 |  | 
|  | 1414 | if ((reader->node->children != NULL) && | 
|  | 1415 | (reader->node->children->type == XML_ENTITY_DECL) && | 
|  | 1416 | (reader->node->children->children != NULL)) { | 
|  | 1417 | xmlTextReaderEntPush(reader, reader->node); | 
|  | 1418 | reader->node = reader->node->children->children; | 
|  | 1419 | } | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1420 | #ifdef LIBXML_REGEXP_ENABLED | 
| Daniel Veillard | a80ff6e | 2003-01-03 12:52:08 +0000 | [diff] [blame] | 1421 | } else if ((reader->node != NULL) && | 
|  | 1422 | (reader->node->type == XML_ENTITY_REF_NODE) && | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 1423 | (reader->ctxt != NULL) && (reader->validate)) { | 
| Daniel Veillard | a80ff6e | 2003-01-03 12:52:08 +0000 | [diff] [blame] | 1424 | xmlTextReaderValidateEntity(reader); | 
| Daniel Veillard | a9cce9c | 2003-09-29 13:20:24 +0000 | [diff] [blame] | 1425 | #endif /* LIBXML_REGEXP_ENABLED */ | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1426 | } | 
|  | 1427 | if ((reader->node != NULL) && | 
|  | 1428 | (reader->node->type == XML_ENTITY_DECL) && | 
|  | 1429 | (reader->ent != NULL) && (reader->ent->children == reader->node)) { | 
|  | 1430 | reader->node = xmlTextReaderEntPop(reader); | 
|  | 1431 | reader->depth++; | 
|  | 1432 | goto get_next_node; | 
|  | 1433 | } | 
| Daniel Veillard | 0e298ad | 2003-02-04 16:14:33 +0000 | [diff] [blame] | 1434 | #ifdef LIBXML_REGEXP_ENABLED | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 1435 | if ((reader->validate) && (reader->node != NULL)) { | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1436 | xmlNodePtr node = reader->node; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1437 |  | 
|  | 1438 | if ((node->type == XML_ELEMENT_NODE) && | 
|  | 1439 | ((reader->state != XML_TEXTREADER_END) && | 
|  | 1440 | (reader->state != XML_TEXTREADER_BACKTRACK))) { | 
|  | 1441 | xmlTextReaderValidatePush(reader); | 
|  | 1442 | } else if ((node->type == XML_TEXT_NODE) || | 
|  | 1443 | (node->type == XML_CDATA_SECTION_NODE)) { | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 1444 | xmlTextReaderValidateCData(reader, node->content, | 
|  | 1445 | xmlStrlen(node->content)); | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1446 | } | 
|  | 1447 | } | 
| Daniel Veillard | 0e298ad | 2003-02-04 16:14:33 +0000 | [diff] [blame] | 1448 | #endif /* LIBXML_REGEXP_ENABLED */ | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1449 | #ifdef LIBXML_PATTERN_ENABLED | 
|  | 1450 | if ((reader->patternNr > 0) && (reader->state != XML_TEXTREADER_END) && | 
|  | 1451 | (reader->state != XML_TEXTREADER_BACKTRACK)) { | 
|  | 1452 | int i; | 
|  | 1453 | for (i = 0;i < reader->patternNr;i++) { | 
|  | 1454 | if (xmlPatternMatch(reader->patternTab[i], reader->node) == 1) { | 
|  | 1455 | xmlTextReaderPreserve(reader); | 
|  | 1456 | break; | 
|  | 1457 | } | 
|  | 1458 | } | 
|  | 1459 | } | 
|  | 1460 | #endif /* LIBXML_PATTERN_ENABLED */ | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1461 | return(1); | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1462 | node_end: | 
| Daniel Veillard | c6cae7b | 2003-04-11 09:02:11 +0000 | [diff] [blame] | 1463 | reader->mode = XML_TEXTREADER_DONE; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1464 | return(0); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1465 | } | 
|  | 1466 |  | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 1467 | /** | 
|  | 1468 | * xmlTextReaderReadState: | 
|  | 1469 | * @reader:  the xmlTextReaderPtr used | 
|  | 1470 | * | 
|  | 1471 | * Gets the read state of the reader. | 
|  | 1472 | * | 
|  | 1473 | * Returns the state value, or -1 in case of error | 
|  | 1474 | */ | 
|  | 1475 | int | 
|  | 1476 | xmlTextReaderReadState(xmlTextReaderPtr reader) { | 
|  | 1477 | if (reader == NULL) | 
|  | 1478 | return(-1); | 
|  | 1479 | return(reader->mode); | 
|  | 1480 | } | 
|  | 1481 |  | 
|  | 1482 | /** | 
| Daniel Veillard | c6cae7b | 2003-04-11 09:02:11 +0000 | [diff] [blame] | 1483 | * xmlTextReaderExpand: | 
|  | 1484 | * @reader:  the xmlTextReaderPtr used | 
|  | 1485 | * | 
|  | 1486 | * Reads the contents of the current node and the full subtree. It then makes | 
| Daniel Veillard | 61c5220 | 2003-04-30 12:20:34 +0000 | [diff] [blame] | 1487 | * the subtree available until the next xmlTextReaderRead() call | 
| Daniel Veillard | c6cae7b | 2003-04-11 09:02:11 +0000 | [diff] [blame] | 1488 | * | 
|  | 1489 | * Returns a node pointer valid until the next xmlTextReaderRead() call | 
|  | 1490 | *         or NULL in case of error. | 
|  | 1491 | */ | 
|  | 1492 | xmlNodePtr | 
|  | 1493 | xmlTextReaderExpand(xmlTextReaderPtr reader) { | 
| Daniel Veillard | f40c1ce | 2003-12-19 17:26:28 +0000 | [diff] [blame] | 1494 | if ((reader == NULL) || (reader->node == NULL)) | 
| Daniel Veillard | c6cae7b | 2003-04-11 09:02:11 +0000 | [diff] [blame] | 1495 | return(NULL); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1496 | if (reader->doc != NULL) | 
|  | 1497 | return(reader->node); | 
| Daniel Veillard | f40c1ce | 2003-12-19 17:26:28 +0000 | [diff] [blame] | 1498 | if (reader->ctxt == NULL) | 
|  | 1499 | return(NULL); | 
| Daniel Veillard | c6cae7b | 2003-04-11 09:02:11 +0000 | [diff] [blame] | 1500 | if (xmlTextReaderDoExpand(reader) < 0) | 
|  | 1501 | return(NULL); | 
|  | 1502 | return(reader->node); | 
|  | 1503 | } | 
|  | 1504 |  | 
|  | 1505 | /** | 
|  | 1506 | * xmlTextReaderNext: | 
|  | 1507 | * @reader:  the xmlTextReaderPtr used | 
|  | 1508 | * | 
|  | 1509 | * Skip to the node following the current one in document order while | 
|  | 1510 | * avoiding the subtree if any. | 
|  | 1511 | * | 
|  | 1512 | * Returns 1 if the node was read successfully, 0 if there is no more | 
|  | 1513 | *          nodes to read, or -1 in case of error | 
|  | 1514 | */ | 
|  | 1515 | int | 
|  | 1516 | xmlTextReaderNext(xmlTextReaderPtr reader) { | 
|  | 1517 | int ret; | 
|  | 1518 | xmlNodePtr cur; | 
|  | 1519 |  | 
|  | 1520 | if (reader == NULL) | 
|  | 1521 | return(-1); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1522 | if (reader->doc != NULL) | 
|  | 1523 | return(xmlTextReaderNextTree(reader)); | 
| Daniel Veillard | c6cae7b | 2003-04-11 09:02:11 +0000 | [diff] [blame] | 1524 | cur = reader->node; | 
|  | 1525 | if ((cur == NULL) || (cur->type != XML_ELEMENT_NODE)) | 
|  | 1526 | return(xmlTextReaderRead(reader)); | 
|  | 1527 | if (reader->state == XML_TEXTREADER_END) | 
|  | 1528 | return(xmlTextReaderRead(reader)); | 
| Daniel Veillard | e8039df | 2003-10-27 11:25:13 +0000 | [diff] [blame] | 1529 | if (cur->extra & NODE_IS_EMPTY) | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 1530 | return(xmlTextReaderRead(reader)); | 
| Daniel Veillard | c6cae7b | 2003-04-11 09:02:11 +0000 | [diff] [blame] | 1531 | do { | 
|  | 1532 | ret = xmlTextReaderRead(reader); | 
|  | 1533 | if (ret != 1) | 
|  | 1534 | return(ret); | 
|  | 1535 | } while (reader->node != cur); | 
|  | 1536 | return(xmlTextReaderRead(reader)); | 
|  | 1537 | } | 
|  | 1538 |  | 
|  | 1539 | /** | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 1540 | * xmlTextReaderReadInnerXml: | 
|  | 1541 | * @reader:  the xmlTextReaderPtr used | 
|  | 1542 | * | 
|  | 1543 | * Reads the contents of the current node, including child nodes and markup. | 
|  | 1544 | * | 
|  | 1545 | * Returns a string containing the XML content, or NULL if the current node | 
|  | 1546 | *         is neither an element nor attribute, or has no child nodes. The | 
|  | 1547 | *         string must be deallocated by the caller. | 
|  | 1548 | */ | 
|  | 1549 | xmlChar * | 
| Daniel Veillard | 33300b4 | 2003-04-17 09:09:19 +0000 | [diff] [blame] | 1550 | xmlTextReaderReadInnerXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) { | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 1551 | TODO | 
|  | 1552 | return(NULL); | 
|  | 1553 | } | 
|  | 1554 |  | 
|  | 1555 | /** | 
|  | 1556 | * xmlTextReaderReadOuterXml: | 
|  | 1557 | * @reader:  the xmlTextReaderPtr used | 
|  | 1558 | * | 
|  | 1559 | * Reads the contents of the current node, including child nodes and markup. | 
|  | 1560 | * | 
|  | 1561 | * Returns a string containing the XML content, or NULL if the current node | 
|  | 1562 | *         is neither an element nor attribute, or has no child nodes. The | 
|  | 1563 | *         string must be deallocated by the caller. | 
|  | 1564 | */ | 
|  | 1565 | xmlChar * | 
| Daniel Veillard | 33300b4 | 2003-04-17 09:09:19 +0000 | [diff] [blame] | 1566 | xmlTextReaderReadOuterXml(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) { | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 1567 | TODO | 
|  | 1568 | return(NULL); | 
|  | 1569 | } | 
|  | 1570 |  | 
|  | 1571 | /** | 
|  | 1572 | * xmlTextReaderReadString: | 
|  | 1573 | * @reader:  the xmlTextReaderPtr used | 
|  | 1574 | * | 
|  | 1575 | * Reads the contents of an element or a text node as a string. | 
|  | 1576 | * | 
|  | 1577 | * Returns a string containing the contents of the Element or Text node, | 
|  | 1578 | *         or NULL if the reader is positioned on any other type of node. | 
|  | 1579 | *         The string must be deallocated by the caller. | 
|  | 1580 | */ | 
|  | 1581 | xmlChar * | 
| Daniel Veillard | 33300b4 | 2003-04-17 09:09:19 +0000 | [diff] [blame] | 1582 | xmlTextReaderReadString(xmlTextReaderPtr reader ATTRIBUTE_UNUSED) { | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 1583 | TODO | 
|  | 1584 | return(NULL); | 
|  | 1585 | } | 
|  | 1586 |  | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 1587 | #if 0 | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 1588 | /** | 
|  | 1589 | * xmlTextReaderReadBase64: | 
|  | 1590 | * @reader:  the xmlTextReaderPtr used | 
|  | 1591 | * @array:  a byte array to store the content. | 
|  | 1592 | * @offset:  the zero-based index into array where the method should | 
|  | 1593 | *           begin to write. | 
|  | 1594 | * @len:  the number of bytes to write. | 
|  | 1595 | * | 
|  | 1596 | * Reads and decodes the Base64 encoded contents of an element and | 
|  | 1597 | * stores the result in a byte buffer. | 
|  | 1598 | * | 
|  | 1599 | * Returns the number of bytes written to array, or zero if the current | 
|  | 1600 | *         instance is not positioned on an element or -1 in case of error. | 
|  | 1601 | */ | 
|  | 1602 | int | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 1603 | xmlTextReaderReadBase64(xmlTextReaderPtr reader, | 
|  | 1604 | unsigned char *array ATTRIBUTE_UNUSED, | 
|  | 1605 | int offset ATTRIBUTE_UNUSED, | 
|  | 1606 | int len ATTRIBUTE_UNUSED) { | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 1607 | if ((reader == NULL) || (reader->ctxt == NULL)) | 
|  | 1608 | return(-1); | 
|  | 1609 | if (reader->ctxt->wellFormed != 1) | 
|  | 1610 | return(-1); | 
|  | 1611 |  | 
|  | 1612 | if ((reader->node == NULL) || (reader->node->type == XML_ELEMENT_NODE)) | 
|  | 1613 | return(0); | 
|  | 1614 | TODO | 
|  | 1615 | return(0); | 
|  | 1616 | } | 
|  | 1617 |  | 
|  | 1618 | /** | 
|  | 1619 | * xmlTextReaderReadBinHex: | 
|  | 1620 | * @reader:  the xmlTextReaderPtr used | 
|  | 1621 | * @array:  a byte array to store the content. | 
|  | 1622 | * @offset:  the zero-based index into array where the method should | 
|  | 1623 | *           begin to write. | 
|  | 1624 | * @len:  the number of bytes to write. | 
|  | 1625 | * | 
|  | 1626 | * Reads and decodes the BinHex encoded contents of an element and | 
|  | 1627 | * stores the result in a byte buffer. | 
|  | 1628 | * | 
|  | 1629 | * Returns the number of bytes written to array, or zero if the current | 
|  | 1630 | *         instance is not positioned on an element or -1 in case of error. | 
|  | 1631 | */ | 
|  | 1632 | int | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 1633 | xmlTextReaderReadBinHex(xmlTextReaderPtr reader, | 
|  | 1634 | unsigned char *array ATTRIBUTE_UNUSED, | 
|  | 1635 | int offset ATTRIBUTE_UNUSED, | 
|  | 1636 | int len ATTRIBUTE_UNUSED) { | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 1637 | if ((reader == NULL) || (reader->ctxt == NULL)) | 
|  | 1638 | return(-1); | 
|  | 1639 | if (reader->ctxt->wellFormed != 1) | 
|  | 1640 | return(-1); | 
|  | 1641 |  | 
|  | 1642 | if ((reader->node == NULL) || (reader->node->type == XML_ELEMENT_NODE)) | 
|  | 1643 | return(0); | 
|  | 1644 | TODO | 
|  | 1645 | return(0); | 
|  | 1646 | } | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 1647 | #endif | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 1648 |  | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1649 | /************************************************************************ | 
|  | 1650 | *									* | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1651 | *			Operating on a preparsed tree			* | 
|  | 1652 | *									* | 
|  | 1653 | ************************************************************************/ | 
|  | 1654 | static int | 
|  | 1655 | xmlTextReaderNextTree(xmlTextReaderPtr reader) | 
|  | 1656 | { | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1657 | if (reader == NULL) | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1658 | return(-1); | 
|  | 1659 |  | 
|  | 1660 | if (reader->state == XML_TEXTREADER_END) | 
|  | 1661 | return(0); | 
|  | 1662 |  | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1663 | if (reader->node == NULL) { | 
|  | 1664 | if (reader->doc->children == NULL) { | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1665 | reader->state = XML_TEXTREADER_END; | 
|  | 1666 | return(0); | 
|  | 1667 | } | 
|  | 1668 |  | 
|  | 1669 | reader->node = reader->doc->children; | 
|  | 1670 | reader->state = XML_TEXTREADER_START; | 
|  | 1671 | return(1); | 
|  | 1672 | } | 
|  | 1673 |  | 
|  | 1674 | if (reader->state != XML_TEXTREADER_BACKTRACK) { | 
|  | 1675 | if (reader->node->children != 0) { | 
|  | 1676 | reader->node = reader->node->children; | 
|  | 1677 | reader->depth++; | 
|  | 1678 | reader->state = XML_TEXTREADER_START; | 
|  | 1679 | return(1); | 
|  | 1680 | } | 
|  | 1681 |  | 
|  | 1682 | if ((reader->node->type == XML_ELEMENT_NODE) || | 
|  | 1683 | (reader->node->type == XML_ATTRIBUTE_NODE)) { | 
|  | 1684 | reader->state = XML_TEXTREADER_BACKTRACK; | 
|  | 1685 | return(1); | 
|  | 1686 | } | 
|  | 1687 | } | 
|  | 1688 |  | 
|  | 1689 | if (reader->node->next != 0) { | 
|  | 1690 | reader->node = reader->node->next; | 
|  | 1691 | reader->state = XML_TEXTREADER_START; | 
|  | 1692 | return(1); | 
|  | 1693 | } | 
|  | 1694 |  | 
|  | 1695 | if (reader->node->parent != 0) { | 
|  | 1696 | if (reader->node->parent->type == XML_DOCUMENT_NODE) { | 
|  | 1697 | reader->state = XML_TEXTREADER_END; | 
|  | 1698 | return(0); | 
|  | 1699 | } | 
|  | 1700 |  | 
|  | 1701 | reader->node = reader->node->parent; | 
|  | 1702 | reader->depth--; | 
|  | 1703 | reader->state = XML_TEXTREADER_BACKTRACK; | 
|  | 1704 | return(1); | 
|  | 1705 | } | 
|  | 1706 |  | 
|  | 1707 | reader->state = XML_TEXTREADER_END; | 
|  | 1708 |  | 
|  | 1709 | return(1); | 
|  | 1710 | } | 
|  | 1711 |  | 
|  | 1712 | /** | 
|  | 1713 | * xmlTextReaderReadTree: | 
|  | 1714 | * @reader:  the xmlTextReaderPtr used | 
|  | 1715 | * | 
|  | 1716 | *  Moves the position of the current instance to the next node in | 
|  | 1717 | *  the stream, exposing its properties. | 
|  | 1718 | * | 
|  | 1719 | *  Returns 1 if the node was read successfully, 0 if there is no more | 
|  | 1720 | *          nodes to read, or -1 in case of error | 
|  | 1721 | */ | 
|  | 1722 | static int | 
|  | 1723 | xmlTextReaderReadTree(xmlTextReaderPtr reader) { | 
|  | 1724 | if (reader->state == XML_TEXTREADER_END) | 
|  | 1725 | return(0); | 
|  | 1726 |  | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1727 | next_node: | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1728 | if (reader->node == NULL) { | 
|  | 1729 | if (reader->doc->children == NULL) { | 
|  | 1730 | reader->state = XML_TEXTREADER_END; | 
|  | 1731 | return(0); | 
|  | 1732 | } | 
|  | 1733 |  | 
|  | 1734 | reader->node = reader->doc->children; | 
|  | 1735 | reader->state = XML_TEXTREADER_START; | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1736 | goto found_node; | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1737 | } | 
|  | 1738 |  | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1739 | if ((reader->state != XML_TEXTREADER_BACKTRACK) && | 
|  | 1740 | (reader->node->type != XML_DTD_NODE) && | 
|  | 1741 | (reader->node->type != XML_XINCLUDE_START) && | 
|  | 1742 | (reader->node->type != XML_ENTITY_REF_NODE)) { | 
|  | 1743 | if (reader->node->children != NULL) { | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1744 | reader->node = reader->node->children; | 
|  | 1745 | reader->depth++; | 
|  | 1746 | reader->state = XML_TEXTREADER_START; | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1747 | goto found_node; | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1748 | } | 
|  | 1749 |  | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1750 | if (reader->node->type == XML_ATTRIBUTE_NODE) { | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1751 | reader->state = XML_TEXTREADER_BACKTRACK; | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1752 | goto found_node; | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1753 | } | 
|  | 1754 | } | 
|  | 1755 |  | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1756 | if (reader->node->next != NULL) { | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1757 | reader->node = reader->node->next; | 
|  | 1758 | reader->state = XML_TEXTREADER_START; | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1759 | goto found_node; | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1760 | } | 
|  | 1761 |  | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1762 | if (reader->node->parent != NULL) { | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1763 | if ((reader->node->parent->type == XML_DOCUMENT_NODE) || | 
|  | 1764 | (reader->node->parent->type == XML_HTML_DOCUMENT_NODE)) { | 
|  | 1765 | reader->state = XML_TEXTREADER_END; | 
|  | 1766 | return(0); | 
|  | 1767 | } | 
|  | 1768 |  | 
|  | 1769 | reader->node = reader->node->parent; | 
|  | 1770 | reader->depth--; | 
|  | 1771 | reader->state = XML_TEXTREADER_BACKTRACK; | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1772 | goto found_node; | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1773 | } | 
|  | 1774 |  | 
|  | 1775 | reader->state = XML_TEXTREADER_END; | 
|  | 1776 |  | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1777 | found_node: | 
|  | 1778 | if ((reader->node->type == XML_XINCLUDE_START) || | 
|  | 1779 | (reader->node->type == XML_XINCLUDE_END)) | 
|  | 1780 | goto next_node; | 
|  | 1781 |  | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1782 | return(1); | 
|  | 1783 | } | 
|  | 1784 |  | 
|  | 1785 | /** | 
| William M. Brack | b1d5316 | 2003-11-18 06:54:40 +0000 | [diff] [blame] | 1786 | * xmlTextReaderNextSibling: | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1787 | * @reader:  the xmlTextReaderPtr used | 
|  | 1788 | * | 
|  | 1789 | * Skip to the node following the current one in document order while | 
|  | 1790 | * avoiding the subtree if any. | 
|  | 1791 | * Currently implemented only for Readers built on a document | 
|  | 1792 | * | 
|  | 1793 | * Returns 1 if the node was read successfully, 0 if there is no more | 
|  | 1794 | *          nodes to read, or -1 in case of error | 
|  | 1795 | */ | 
|  | 1796 | int | 
|  | 1797 | xmlTextReaderNextSibling(xmlTextReaderPtr reader) { | 
|  | 1798 | if (reader == NULL) | 
|  | 1799 | return(-1); | 
|  | 1800 | if (reader->doc == NULL) { | 
|  | 1801 | TODO | 
|  | 1802 | return(-1); | 
|  | 1803 | } | 
|  | 1804 |  | 
|  | 1805 | if (reader->state == XML_TEXTREADER_END) | 
|  | 1806 | return(0); | 
|  | 1807 |  | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1808 | if (reader->node == NULL) | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1809 | return(xmlTextReaderNextTree(reader)); | 
|  | 1810 |  | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1811 | if (reader->node->next != NULL) { | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1812 | reader->node = reader->node->next; | 
|  | 1813 | reader->state = XML_TEXTREADER_START; | 
|  | 1814 | return(1); | 
|  | 1815 | } | 
|  | 1816 |  | 
|  | 1817 | return(0); | 
|  | 1818 | } | 
|  | 1819 |  | 
|  | 1820 | /************************************************************************ | 
|  | 1821 | *									* | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1822 | *			Constructor and destructors			* | 
|  | 1823 | *									* | 
|  | 1824 | ************************************************************************/ | 
|  | 1825 | /** | 
|  | 1826 | * xmlNewTextReader: | 
|  | 1827 | * @input: the xmlParserInputBufferPtr used to read data | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1828 | * @URI: the URI information for the source if available | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1829 | * | 
|  | 1830 | * Create an xmlTextReader structure fed with @input | 
|  | 1831 | * | 
|  | 1832 | * Returns the new xmlTextReaderPtr or NULL in case of error | 
|  | 1833 | */ | 
|  | 1834 | xmlTextReaderPtr | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1835 | xmlNewTextReader(xmlParserInputBufferPtr input, const char *URI) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1836 | xmlTextReaderPtr ret; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1837 |  | 
|  | 1838 | if (input == NULL) | 
|  | 1839 | return(NULL); | 
|  | 1840 | ret = xmlMalloc(sizeof(xmlTextReader)); | 
|  | 1841 | if (ret == NULL) { | 
|  | 1842 | xmlGenericError(xmlGenericErrorContext, | 
|  | 1843 | "xmlNewTextReader : malloc failed\n"); | 
|  | 1844 | return(NULL); | 
|  | 1845 | } | 
|  | 1846 | memset(ret, 0, sizeof(xmlTextReader)); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1847 | ret->doc = NULL; | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 1848 | ret->entTab = NULL; | 
|  | 1849 | ret->entMax = 0; | 
|  | 1850 | ret->entNr = 0; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1851 | ret->input = input; | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1852 | ret->buffer = xmlBufferCreateSize(100); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1853 | ret->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler)); | 
|  | 1854 | if (ret->sax == NULL) { | 
|  | 1855 | xmlFree(ret); | 
|  | 1856 | xmlGenericError(xmlGenericErrorContext, | 
|  | 1857 | "xmlNewTextReader : malloc failed\n"); | 
|  | 1858 | return(NULL); | 
|  | 1859 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1860 | xmlSAXVersion(ret->sax, 2); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1861 | ret->startElement = ret->sax->startElement; | 
|  | 1862 | ret->sax->startElement = xmlTextReaderStartElement; | 
|  | 1863 | ret->endElement = ret->sax->endElement; | 
|  | 1864 | ret->sax->endElement = xmlTextReaderEndElement; | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1865 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 1866 | if (ret->sax->initialized == XML_SAX2_MAGIC) { | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1867 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 1868 | ret->startElementNs = ret->sax->startElementNs; | 
|  | 1869 | ret->sax->startElementNs = xmlTextReaderStartElementNs; | 
|  | 1870 | ret->endElementNs = ret->sax->endElementNs; | 
|  | 1871 | ret->sax->endElementNs = xmlTextReaderEndElementNs; | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1872 | #ifdef LIBXML_SAX1_ENABLED | 
| Daniel Veillard | 07cb822 | 2003-09-10 10:51:05 +0000 | [diff] [blame] | 1873 | } else { | 
|  | 1874 | ret->startElementNs = NULL; | 
|  | 1875 | ret->endElementNs = NULL; | 
|  | 1876 | } | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 1877 | #endif /* LIBXML_SAX1_ENABLED */ | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1878 | ret->characters = ret->sax->characters; | 
|  | 1879 | ret->sax->characters = xmlTextReaderCharacters; | 
| Daniel Veillard | 40412cd | 2003-09-03 13:28:32 +0000 | [diff] [blame] | 1880 | ret->sax->ignorableWhitespace = xmlTextReaderCharacters; | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1881 | ret->cdataBlock = ret->sax->cdataBlock; | 
|  | 1882 | ret->sax->cdataBlock = xmlTextReaderCDataBlock; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1883 |  | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 1884 | ret->mode = XML_TEXTREADER_MODE_INITIAL; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1885 | ret->node = NULL; | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 1886 | ret->curnode = NULL; | 
| Daniel Veillard | 5335055 | 2003-09-18 13:35:51 +0000 | [diff] [blame] | 1887 | if (ret->input->buffer->use < 4) { | 
| William M. Brack | 899e64a | 2003-09-26 18:03:42 +0000 | [diff] [blame] | 1888 | xmlParserInputBufferRead(input, 4); | 
| Daniel Veillard | 5335055 | 2003-09-18 13:35:51 +0000 | [diff] [blame] | 1889 | } | 
|  | 1890 | if (ret->input->buffer->use >= 4) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1891 | ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL, | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1892 | (const char *) ret->input->buffer->content, 4, URI); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1893 | ret->base = 0; | 
|  | 1894 | ret->cur = 4; | 
|  | 1895 | } else { | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1896 | ret->ctxt = xmlCreatePushParserCtxt(ret->sax, NULL, NULL, 0, URI); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1897 | ret->base = 0; | 
|  | 1898 | ret->cur = 0; | 
|  | 1899 | } | 
| Daniel Veillard | a76fe5c | 2003-04-24 16:06:47 +0000 | [diff] [blame] | 1900 | if (ret->ctxt == NULL) { | 
|  | 1901 | xmlGenericError(xmlGenericErrorContext, | 
|  | 1902 | "xmlNewTextReader : malloc failed\n"); | 
|  | 1903 | xmlFree(ret->sax); | 
|  | 1904 | xmlFree(ret); | 
|  | 1905 | return(NULL); | 
|  | 1906 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1907 | ret->ctxt->_private = ret; | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1908 | ret->ctxt->linenumbers = 1; | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 1909 | ret->ctxt->dictNames = 1; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1910 | ret->allocs = XML_TEXTREADER_CTXT; | 
| Daniel Veillard | 40412cd | 2003-09-03 13:28:32 +0000 | [diff] [blame] | 1911 | /* | 
|  | 1912 | * use the parser dictionnary to allocate all elements and attributes names | 
|  | 1913 | */ | 
|  | 1914 | ret->ctxt->docdict = 1; | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1915 | ret->dict = ret->ctxt->dict; | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1916 | #ifdef LIBXML_XINCLUDE_ENABLED | 
|  | 1917 | ret->xinclude = 0; | 
|  | 1918 | #endif | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1919 | #ifdef LIBXML_PATTERN_ENABLED | 
|  | 1920 | ret->patternMax = 0; | 
|  | 1921 | ret->patternTab = NULL; | 
|  | 1922 | #endif | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1923 | return(ret); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1924 | } | 
|  | 1925 |  | 
|  | 1926 | /** | 
|  | 1927 | * xmlNewTextReaderFilename: | 
|  | 1928 | * @URI: the URI of the resource to process | 
|  | 1929 | * | 
|  | 1930 | * Create an xmlTextReader structure fed with the resource at @URI | 
|  | 1931 | * | 
|  | 1932 | * Returns the new xmlTextReaderPtr or NULL in case of error | 
|  | 1933 | */ | 
|  | 1934 | xmlTextReaderPtr | 
|  | 1935 | xmlNewTextReaderFilename(const char *URI) { | 
|  | 1936 | xmlParserInputBufferPtr input; | 
|  | 1937 | xmlTextReaderPtr ret; | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1938 | char *directory = NULL; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1939 |  | 
|  | 1940 | input = xmlParserInputBufferCreateFilename(URI, XML_CHAR_ENCODING_NONE); | 
|  | 1941 | if (input == NULL) | 
|  | 1942 | return(NULL); | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1943 | ret = xmlNewTextReader(input, URI); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1944 | if (ret == NULL) { | 
|  | 1945 | xmlFreeParserInputBuffer(input); | 
|  | 1946 | return(NULL); | 
|  | 1947 | } | 
|  | 1948 | ret->allocs |= XML_TEXTREADER_INPUT; | 
| Daniel Veillard | ea7751d | 2002-12-20 00:16:24 +0000 | [diff] [blame] | 1949 | if (ret->ctxt->directory == NULL) | 
|  | 1950 | directory = xmlParserGetDirectory(URI); | 
|  | 1951 | if ((ret->ctxt->directory == NULL) && (directory != NULL)) | 
|  | 1952 | ret->ctxt->directory = (char *) xmlStrdup((xmlChar *) directory); | 
|  | 1953 | if (directory != NULL) | 
|  | 1954 | xmlFree(directory); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1955 | return(ret); | 
|  | 1956 | } | 
|  | 1957 |  | 
|  | 1958 | /** | 
|  | 1959 | * xmlFreeTextReader: | 
|  | 1960 | * @reader:  the xmlTextReaderPtr | 
|  | 1961 | * | 
|  | 1962 | * Deallocate all the resources associated to the reader | 
|  | 1963 | */ | 
|  | 1964 | void | 
|  | 1965 | xmlFreeTextReader(xmlTextReaderPtr reader) { | 
|  | 1966 | if (reader == NULL) | 
|  | 1967 | return; | 
| Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 1968 | #ifdef LIBXML_SCHEMAS_ENABLED | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 1969 | if (reader->rngSchemas != NULL) { | 
|  | 1970 | xmlRelaxNGFree(reader->rngSchemas); | 
|  | 1971 | reader->rngSchemas = NULL; | 
|  | 1972 | } | 
|  | 1973 | if (reader->rngValidCtxt != NULL) { | 
|  | 1974 | xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); | 
|  | 1975 | reader->rngValidCtxt = NULL; | 
|  | 1976 | } | 
| Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 1977 | #endif | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 1978 | #ifdef LIBXML_XINCLUDE_ENABLED | 
|  | 1979 | if (reader->xincctxt != NULL) | 
|  | 1980 | xmlXIncludeFreeContext(reader->xincctxt); | 
|  | 1981 | #endif | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 1982 | #ifdef LIBXML_PATTERN_ENABLED | 
|  | 1983 | if (reader->patternTab != NULL) { | 
|  | 1984 | int i; | 
|  | 1985 | for (i = 0;i < reader->patternNr;i++) { | 
|  | 1986 | if (reader->patternTab[i] != NULL) | 
|  | 1987 | xmlFreePattern(reader->patternTab[i]); | 
|  | 1988 | } | 
|  | 1989 | xmlFree(reader->patternTab); | 
|  | 1990 | } | 
|  | 1991 | #endif | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 1992 | if (reader->ctxt != NULL) { | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 1993 | if (reader->dict == reader->ctxt->dict) | 
|  | 1994 | reader->dict = NULL; | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 1995 | if (reader->ctxt->myDoc != NULL) { | 
|  | 1996 | if (reader->preserve == 0) | 
|  | 1997 | xmlTextReaderFreeDoc(reader, reader->ctxt->myDoc); | 
|  | 1998 | reader->ctxt->myDoc = NULL; | 
|  | 1999 | } | 
| Daniel Veillard | 336fc7d | 2002-12-27 19:37:04 +0000 | [diff] [blame] | 2000 | if ((reader->ctxt->vctxt.vstateTab != NULL) && | 
|  | 2001 | (reader->ctxt->vctxt.vstateMax > 0)){ | 
|  | 2002 | xmlFree(reader->ctxt->vctxt.vstateTab); | 
|  | 2003 | reader->ctxt->vctxt.vstateTab = 0; | 
|  | 2004 | reader->ctxt->vctxt.vstateMax = 0; | 
|  | 2005 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2006 | if (reader->allocs & XML_TEXTREADER_CTXT) | 
|  | 2007 | xmlFreeParserCtxt(reader->ctxt); | 
|  | 2008 | } | 
|  | 2009 | if (reader->sax != NULL) | 
|  | 2010 | xmlFree(reader->sax); | 
|  | 2011 | if ((reader->input != NULL)  && (reader->allocs & XML_TEXTREADER_INPUT)) | 
|  | 2012 | xmlFreeParserInputBuffer(reader->input); | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 2013 | if (reader->faketext != NULL) { | 
|  | 2014 | xmlFreeNode(reader->faketext); | 
|  | 2015 | } | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 2016 | if (reader->buffer != NULL) | 
|  | 2017 | xmlBufferFree(reader->buffer); | 
| Daniel Veillard | 1fdfd11 | 2003-01-03 01:18:43 +0000 | [diff] [blame] | 2018 | if (reader->entTab != NULL) | 
|  | 2019 | xmlFree(reader->entTab); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 2020 | if (reader->dict != NULL) | 
|  | 2021 | xmlDictFree(reader->dict); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2022 | xmlFree(reader); | 
|  | 2023 | } | 
|  | 2024 |  | 
|  | 2025 | /************************************************************************ | 
|  | 2026 | *									* | 
| Daniel Veillard | 0eb38c7 | 2002-12-14 23:00:35 +0000 | [diff] [blame] | 2027 | *			Methods for XmlTextReader			* | 
|  | 2028 | *									* | 
|  | 2029 | ************************************************************************/ | 
|  | 2030 | /** | 
|  | 2031 | * xmlTextReaderClose: | 
|  | 2032 | * @reader:  the xmlTextReaderPtr used | 
|  | 2033 | * | 
|  | 2034 | * This method releases any resources allocated by the current instance | 
|  | 2035 | * changes the state to Closed and close any underlying input. | 
|  | 2036 | * | 
|  | 2037 | * Returns 0 or -1 in case of error | 
|  | 2038 | */ | 
|  | 2039 | int | 
|  | 2040 | xmlTextReaderClose(xmlTextReaderPtr reader) { | 
|  | 2041 | if (reader == NULL) | 
|  | 2042 | return(-1); | 
|  | 2043 | reader->node = NULL; | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2044 | reader->curnode = NULL; | 
| Daniel Veillard | 0eb38c7 | 2002-12-14 23:00:35 +0000 | [diff] [blame] | 2045 | reader->mode = XML_TEXTREADER_MODE_CLOSED; | 
|  | 2046 | if (reader->ctxt != NULL) { | 
|  | 2047 | if (reader->ctxt->myDoc != NULL) { | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 2048 | if (reader->preserve == 0) | 
|  | 2049 | xmlTextReaderFreeDoc(reader, reader->ctxt->myDoc); | 
| Daniel Veillard | 0eb38c7 | 2002-12-14 23:00:35 +0000 | [diff] [blame] | 2050 | reader->ctxt->myDoc = NULL; | 
|  | 2051 | } | 
|  | 2052 | if (reader->allocs & XML_TEXTREADER_CTXT) { | 
|  | 2053 | xmlFreeParserCtxt(reader->ctxt); | 
|  | 2054 | reader->allocs -= XML_TEXTREADER_CTXT; | 
|  | 2055 | } | 
|  | 2056 | } | 
|  | 2057 | if (reader->sax != NULL) { | 
|  | 2058 | xmlFree(reader->sax); | 
|  | 2059 | reader->sax = NULL; | 
|  | 2060 | } | 
|  | 2061 | if ((reader->input != NULL)  && (reader->allocs & XML_TEXTREADER_INPUT)) { | 
|  | 2062 | xmlFreeParserInputBuffer(reader->input); | 
|  | 2063 | reader->allocs -= XML_TEXTREADER_INPUT; | 
|  | 2064 | } | 
|  | 2065 | return(0); | 
|  | 2066 | } | 
|  | 2067 |  | 
|  | 2068 | /** | 
|  | 2069 | * xmlTextReaderGetAttributeNo: | 
|  | 2070 | * @reader:  the xmlTextReaderPtr used | 
|  | 2071 | * @no: the zero-based index of the attribute relative to the containing element | 
|  | 2072 | * | 
|  | 2073 | * Provides the value of the attribute with the specified index relative | 
|  | 2074 | * to the containing element. | 
|  | 2075 | * | 
|  | 2076 | * Returns a string containing the value of the specified attribute, or NULL | 
|  | 2077 | *    in case of error. The string must be deallocated by the caller. | 
|  | 2078 | */ | 
|  | 2079 | xmlChar * | 
|  | 2080 | xmlTextReaderGetAttributeNo(xmlTextReaderPtr reader, int no) { | 
|  | 2081 | xmlChar *ret; | 
|  | 2082 | int i; | 
|  | 2083 | xmlAttrPtr cur; | 
|  | 2084 | xmlNsPtr ns; | 
|  | 2085 |  | 
|  | 2086 | if (reader == NULL) | 
|  | 2087 | return(NULL); | 
|  | 2088 | if (reader->node == NULL) | 
|  | 2089 | return(NULL); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2090 | if (reader->curnode != NULL) | 
|  | 2091 | return(NULL); | 
| Daniel Veillard | 0eb38c7 | 2002-12-14 23:00:35 +0000 | [diff] [blame] | 2092 | /* TODO: handle the xmlDecl */ | 
|  | 2093 | if (reader->node->type != XML_ELEMENT_NODE) | 
|  | 2094 | return(NULL); | 
|  | 2095 |  | 
|  | 2096 | ns = reader->node->nsDef; | 
|  | 2097 | for (i = 0;(i < no) && (ns != NULL);i++) { | 
|  | 2098 | ns = ns->next; | 
|  | 2099 | } | 
|  | 2100 | if (ns != NULL) | 
|  | 2101 | return(xmlStrdup(ns->href)); | 
|  | 2102 |  | 
|  | 2103 | cur = reader->node->properties; | 
|  | 2104 | if (cur == NULL) | 
|  | 2105 | return(NULL); | 
|  | 2106 | for (;i < no;i++) { | 
|  | 2107 | cur = cur->next; | 
|  | 2108 | if (cur == NULL) | 
|  | 2109 | return(NULL); | 
|  | 2110 | } | 
|  | 2111 | /* TODO walk the DTD if present */ | 
|  | 2112 |  | 
|  | 2113 | ret = xmlNodeListGetString(reader->node->doc, cur->children, 1); | 
|  | 2114 | if (ret == NULL) return(xmlStrdup((xmlChar *)"")); | 
|  | 2115 | return(ret); | 
|  | 2116 | } | 
|  | 2117 |  | 
|  | 2118 | /** | 
|  | 2119 | * xmlTextReaderGetAttribute: | 
|  | 2120 | * @reader:  the xmlTextReaderPtr used | 
|  | 2121 | * @name: the qualified name of the attribute. | 
|  | 2122 | * | 
|  | 2123 | * Provides the value of the attribute with the specified qualified name. | 
|  | 2124 | * | 
|  | 2125 | * Returns a string containing the value of the specified attribute, or NULL | 
|  | 2126 | *    in case of error. The string must be deallocated by the caller. | 
|  | 2127 | */ | 
|  | 2128 | xmlChar * | 
|  | 2129 | xmlTextReaderGetAttribute(xmlTextReaderPtr reader, const xmlChar *name) { | 
|  | 2130 | xmlChar *prefix = NULL; | 
|  | 2131 | xmlChar *localname; | 
|  | 2132 | xmlNsPtr ns; | 
|  | 2133 | xmlChar *ret = NULL; | 
|  | 2134 |  | 
|  | 2135 | if ((reader == NULL) || (name == NULL)) | 
|  | 2136 | return(NULL); | 
|  | 2137 | if (reader->node == NULL) | 
|  | 2138 | return(NULL); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2139 | if (reader->curnode != NULL) | 
|  | 2140 | return(NULL); | 
| Daniel Veillard | 0eb38c7 | 2002-12-14 23:00:35 +0000 | [diff] [blame] | 2141 |  | 
|  | 2142 | /* TODO: handle the xmlDecl */ | 
|  | 2143 | if (reader->node->type != XML_ELEMENT_NODE) | 
|  | 2144 | return(NULL); | 
|  | 2145 |  | 
|  | 2146 | localname = xmlSplitQName2(name, &prefix); | 
|  | 2147 | if (localname == NULL) | 
|  | 2148 | return(xmlGetProp(reader->node, name)); | 
|  | 2149 |  | 
|  | 2150 | ns = xmlSearchNs(reader->node->doc, reader->node, prefix); | 
|  | 2151 | if (ns != NULL) | 
|  | 2152 | ret = xmlGetNsProp(reader->node, localname, ns->href); | 
|  | 2153 |  | 
|  | 2154 | if (localname != NULL) | 
|  | 2155 | xmlFree(localname); | 
|  | 2156 | if (prefix != NULL) | 
|  | 2157 | xmlFree(prefix); | 
|  | 2158 | return(ret); | 
|  | 2159 | } | 
|  | 2160 |  | 
|  | 2161 |  | 
|  | 2162 | /** | 
|  | 2163 | * xmlTextReaderGetAttributeNs: | 
|  | 2164 | * @reader:  the xmlTextReaderPtr used | 
|  | 2165 | * @localName: the local name of the attribute. | 
|  | 2166 | * @namespaceURI: the namespace URI of the attribute. | 
|  | 2167 | * | 
|  | 2168 | * Provides the value of the specified attribute | 
|  | 2169 | * | 
|  | 2170 | * Returns a string containing the value of the specified attribute, or NULL | 
|  | 2171 | *    in case of error. The string must be deallocated by the caller. | 
|  | 2172 | */ | 
|  | 2173 | xmlChar * | 
|  | 2174 | xmlTextReaderGetAttributeNs(xmlTextReaderPtr reader, const xmlChar *localName, | 
|  | 2175 | const xmlChar *namespaceURI) { | 
|  | 2176 | if ((reader == NULL) || (localName == NULL)) | 
|  | 2177 | return(NULL); | 
|  | 2178 | if (reader->node == NULL) | 
|  | 2179 | return(NULL); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2180 | if (reader->curnode != NULL) | 
|  | 2181 | return(NULL); | 
| Daniel Veillard | 0eb38c7 | 2002-12-14 23:00:35 +0000 | [diff] [blame] | 2182 |  | 
|  | 2183 | /* TODO: handle the xmlDecl */ | 
|  | 2184 | if (reader->node->type != XML_ELEMENT_NODE) | 
|  | 2185 | return(NULL); | 
|  | 2186 |  | 
|  | 2187 | return(xmlGetNsProp(reader->node, localName, namespaceURI)); | 
|  | 2188 | } | 
|  | 2189 |  | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2190 | /** | 
|  | 2191 | * xmlTextReaderGetRemainder: | 
|  | 2192 | * @reader:  the xmlTextReaderPtr used | 
|  | 2193 | * | 
|  | 2194 | * Method to get the remainder of the buffered XML. this method stops the | 
|  | 2195 | * parser, set its state to End Of File and return the input stream with | 
|  | 2196 | * what is left that the parser did not use. | 
|  | 2197 | * | 
|  | 2198 | * Returns the xmlParserInputBufferPtr attached to the XML or NULL | 
|  | 2199 | *    in case of error. | 
|  | 2200 | */ | 
|  | 2201 | xmlParserInputBufferPtr | 
|  | 2202 | xmlTextReaderGetRemainder(xmlTextReaderPtr reader) { | 
|  | 2203 | xmlParserInputBufferPtr ret = NULL; | 
|  | 2204 |  | 
|  | 2205 | if (reader == NULL) | 
|  | 2206 | return(NULL); | 
|  | 2207 | if (reader->node == NULL) | 
|  | 2208 | return(NULL); | 
|  | 2209 |  | 
|  | 2210 | reader->node = NULL; | 
|  | 2211 | reader->curnode = NULL; | 
|  | 2212 | reader->mode = XML_TEXTREADER_MODE_EOF; | 
|  | 2213 | if (reader->ctxt != NULL) { | 
|  | 2214 | if (reader->ctxt->myDoc != NULL) { | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 2215 | if (reader->preserve == 0) | 
|  | 2216 | xmlTextReaderFreeDoc(reader, reader->ctxt->myDoc); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2217 | reader->ctxt->myDoc = NULL; | 
|  | 2218 | } | 
|  | 2219 | if (reader->allocs & XML_TEXTREADER_CTXT) { | 
|  | 2220 | xmlFreeParserCtxt(reader->ctxt); | 
|  | 2221 | reader->allocs -= XML_TEXTREADER_CTXT; | 
|  | 2222 | } | 
|  | 2223 | } | 
|  | 2224 | if (reader->sax != NULL) { | 
|  | 2225 | xmlFree(reader->sax); | 
|  | 2226 | reader->sax = NULL; | 
|  | 2227 | } | 
|  | 2228 | if (reader->allocs & XML_TEXTREADER_INPUT) { | 
|  | 2229 | ret = reader->input; | 
|  | 2230 | reader->allocs -= XML_TEXTREADER_INPUT; | 
|  | 2231 | } else { | 
|  | 2232 | /* | 
|  | 2233 | * Hum, one may need to duplicate the data structure because | 
|  | 2234 | * without reference counting the input may be freed twice: | 
|  | 2235 | *   - by the layer which allocated it. | 
|  | 2236 | *   - by the layer to which would have been returned to. | 
|  | 2237 | */ | 
|  | 2238 | TODO | 
|  | 2239 | return(NULL); | 
|  | 2240 | } | 
|  | 2241 | return(ret); | 
|  | 2242 | } | 
|  | 2243 |  | 
|  | 2244 | /** | 
|  | 2245 | * xmlTextReaderLookupNamespace: | 
|  | 2246 | * @reader:  the xmlTextReaderPtr used | 
|  | 2247 | * @prefix: the prefix whose namespace URI is to be resolved. To return | 
|  | 2248 | *          the default namespace, specify NULL | 
|  | 2249 | * | 
|  | 2250 | * Resolves a namespace prefix in the scope of the current element. | 
|  | 2251 | * | 
|  | 2252 | * Returns a string containing the namespace URI to which the prefix maps | 
|  | 2253 | *    or NULL in case of error. The string must be deallocated by the caller. | 
|  | 2254 | */ | 
|  | 2255 | xmlChar * | 
|  | 2256 | xmlTextReaderLookupNamespace(xmlTextReaderPtr reader, const xmlChar *prefix) { | 
|  | 2257 | xmlNsPtr ns; | 
|  | 2258 |  | 
|  | 2259 | if (reader == NULL) | 
|  | 2260 | return(NULL); | 
|  | 2261 | if (reader->node == NULL) | 
|  | 2262 | return(NULL); | 
|  | 2263 |  | 
|  | 2264 | ns = xmlSearchNs(reader->node->doc, reader->node, prefix); | 
|  | 2265 | if (ns == NULL) | 
|  | 2266 | return(NULL); | 
|  | 2267 | return(xmlStrdup(ns->href)); | 
|  | 2268 | } | 
|  | 2269 |  | 
|  | 2270 | /** | 
|  | 2271 | * xmlTextReaderMoveToAttributeNo: | 
|  | 2272 | * @reader:  the xmlTextReaderPtr used | 
|  | 2273 | * @no: the zero-based index of the attribute relative to the containing | 
|  | 2274 | *      element. | 
|  | 2275 | * | 
|  | 2276 | * Moves the position of the current instance to the attribute with | 
|  | 2277 | * the specified index relative to the containing element. | 
|  | 2278 | * | 
|  | 2279 | * Returns 1 in case of success, -1 in case of error, 0 if not found | 
|  | 2280 | */ | 
|  | 2281 | int | 
|  | 2282 | xmlTextReaderMoveToAttributeNo(xmlTextReaderPtr reader, int no) { | 
|  | 2283 | int i; | 
|  | 2284 | xmlAttrPtr cur; | 
|  | 2285 | xmlNsPtr ns; | 
|  | 2286 |  | 
|  | 2287 | if (reader == NULL) | 
|  | 2288 | return(-1); | 
|  | 2289 | if (reader->node == NULL) | 
|  | 2290 | return(-1); | 
|  | 2291 | /* TODO: handle the xmlDecl */ | 
|  | 2292 | if (reader->node->type != XML_ELEMENT_NODE) | 
|  | 2293 | return(-1); | 
|  | 2294 |  | 
|  | 2295 | reader->curnode = NULL; | 
|  | 2296 |  | 
|  | 2297 | ns = reader->node->nsDef; | 
|  | 2298 | for (i = 0;(i < no) && (ns != NULL);i++) { | 
|  | 2299 | ns = ns->next; | 
|  | 2300 | } | 
|  | 2301 | if (ns != NULL) { | 
|  | 2302 | reader->curnode = (xmlNodePtr) ns; | 
|  | 2303 | return(1); | 
|  | 2304 | } | 
|  | 2305 |  | 
|  | 2306 | cur = reader->node->properties; | 
|  | 2307 | if (cur == NULL) | 
|  | 2308 | return(0); | 
|  | 2309 | for (;i < no;i++) { | 
|  | 2310 | cur = cur->next; | 
|  | 2311 | if (cur == NULL) | 
|  | 2312 | return(0); | 
|  | 2313 | } | 
|  | 2314 | /* TODO walk the DTD if present */ | 
|  | 2315 |  | 
|  | 2316 | reader->curnode = (xmlNodePtr) cur; | 
|  | 2317 | return(1); | 
|  | 2318 | } | 
|  | 2319 |  | 
|  | 2320 | /** | 
|  | 2321 | * xmlTextReaderMoveToAttribute: | 
|  | 2322 | * @reader:  the xmlTextReaderPtr used | 
|  | 2323 | * @name: the qualified name of the attribute. | 
|  | 2324 | * | 
|  | 2325 | * Moves the position of the current instance to the attribute with | 
|  | 2326 | * the specified qualified name. | 
|  | 2327 | * | 
|  | 2328 | * Returns 1 in case of success, -1 in case of error, 0 if not found | 
|  | 2329 | */ | 
|  | 2330 | int | 
|  | 2331 | xmlTextReaderMoveToAttribute(xmlTextReaderPtr reader, const xmlChar *name) { | 
|  | 2332 | xmlChar *prefix = NULL; | 
|  | 2333 | xmlChar *localname; | 
|  | 2334 | xmlNsPtr ns; | 
|  | 2335 | xmlAttrPtr prop; | 
|  | 2336 |  | 
|  | 2337 | if ((reader == NULL) || (name == NULL)) | 
|  | 2338 | return(-1); | 
|  | 2339 | if (reader->node == NULL) | 
|  | 2340 | return(-1); | 
|  | 2341 |  | 
|  | 2342 | /* TODO: handle the xmlDecl */ | 
|  | 2343 | if (reader->node->type != XML_ELEMENT_NODE) | 
|  | 2344 | return(0); | 
|  | 2345 |  | 
|  | 2346 | localname = xmlSplitQName2(name, &prefix); | 
|  | 2347 | if (localname == NULL) { | 
|  | 2348 | /* | 
|  | 2349 | * Namespace default decl | 
|  | 2350 | */ | 
|  | 2351 | if (xmlStrEqual(name, BAD_CAST "xmlns")) { | 
|  | 2352 | ns = reader->node->nsDef; | 
|  | 2353 | while (ns != NULL) { | 
|  | 2354 | if (ns->prefix == NULL) { | 
|  | 2355 | reader->curnode = (xmlNodePtr) ns; | 
|  | 2356 | return(1); | 
|  | 2357 | } | 
|  | 2358 | ns = ns->next; | 
|  | 2359 | } | 
|  | 2360 | return(0); | 
|  | 2361 | } | 
|  | 2362 |  | 
|  | 2363 | prop = reader->node->properties; | 
|  | 2364 | while (prop != NULL) { | 
|  | 2365 | /* | 
|  | 2366 | * One need to have | 
|  | 2367 | *   - same attribute names | 
|  | 2368 | *   - and the attribute carrying that namespace | 
|  | 2369 | */ | 
|  | 2370 | if ((xmlStrEqual(prop->name, name)) && | 
|  | 2371 | ((prop->ns == NULL) || (prop->ns->prefix == NULL))) { | 
|  | 2372 | reader->curnode = (xmlNodePtr) prop; | 
|  | 2373 | return(1); | 
|  | 2374 | } | 
|  | 2375 | prop = prop->next; | 
|  | 2376 | } | 
|  | 2377 | return(0); | 
|  | 2378 | } | 
|  | 2379 |  | 
|  | 2380 | /* | 
|  | 2381 | * Namespace default decl | 
|  | 2382 | */ | 
|  | 2383 | if (xmlStrEqual(prefix, BAD_CAST "xmlns")) { | 
|  | 2384 | ns = reader->node->nsDef; | 
|  | 2385 | while (ns != NULL) { | 
|  | 2386 | if ((ns->prefix != NULL) && (xmlStrEqual(ns->prefix, localname))) { | 
|  | 2387 | reader->curnode = (xmlNodePtr) ns; | 
|  | 2388 | goto found; | 
|  | 2389 | } | 
|  | 2390 | ns = ns->next; | 
|  | 2391 | } | 
|  | 2392 | goto not_found; | 
|  | 2393 | } | 
|  | 2394 | prop = reader->node->properties; | 
|  | 2395 | while (prop != NULL) { | 
|  | 2396 | /* | 
|  | 2397 | * One need to have | 
|  | 2398 | *   - same attribute names | 
|  | 2399 | *   - and the attribute carrying that namespace | 
|  | 2400 | */ | 
|  | 2401 | if ((xmlStrEqual(prop->name, localname)) && | 
|  | 2402 | (prop->ns != NULL) && (xmlStrEqual(prop->ns->prefix, prefix))) { | 
|  | 2403 | reader->curnode = (xmlNodePtr) prop; | 
|  | 2404 | goto found; | 
|  | 2405 | } | 
|  | 2406 | prop = prop->next; | 
|  | 2407 | } | 
|  | 2408 | not_found: | 
|  | 2409 | if (localname != NULL) | 
|  | 2410 | xmlFree(localname); | 
|  | 2411 | if (prefix != NULL) | 
|  | 2412 | xmlFree(prefix); | 
|  | 2413 | return(0); | 
|  | 2414 |  | 
|  | 2415 | found: | 
|  | 2416 | if (localname != NULL) | 
|  | 2417 | xmlFree(localname); | 
|  | 2418 | if (prefix != NULL) | 
|  | 2419 | xmlFree(prefix); | 
|  | 2420 | return(1); | 
|  | 2421 | } | 
|  | 2422 |  | 
|  | 2423 | /** | 
|  | 2424 | * xmlTextReaderMoveToAttributeNs: | 
|  | 2425 | * @reader:  the xmlTextReaderPtr used | 
|  | 2426 | * @localName:  the local name of the attribute. | 
|  | 2427 | * @namespaceURI:  the namespace URI of the attribute. | 
|  | 2428 | * | 
|  | 2429 | * Moves the position of the current instance to the attribute with the | 
|  | 2430 | * specified local name and namespace URI. | 
|  | 2431 | * | 
|  | 2432 | * Returns 1 in case of success, -1 in case of error, 0 if not found | 
|  | 2433 | */ | 
|  | 2434 | int | 
|  | 2435 | xmlTextReaderMoveToAttributeNs(xmlTextReaderPtr reader, | 
|  | 2436 | const xmlChar *localName, const xmlChar *namespaceURI) { | 
|  | 2437 | xmlAttrPtr prop; | 
|  | 2438 | xmlNodePtr node; | 
|  | 2439 |  | 
|  | 2440 | if ((reader == NULL) || (localName == NULL) || (namespaceURI == NULL)) | 
|  | 2441 | return(-1); | 
|  | 2442 | if (reader->node == NULL) | 
|  | 2443 | return(-1); | 
|  | 2444 | if (reader->node->type != XML_ELEMENT_NODE) | 
|  | 2445 | return(0); | 
|  | 2446 | node = reader->node; | 
|  | 2447 |  | 
|  | 2448 | /* | 
|  | 2449 | * A priori reading http://www.w3.org/TR/REC-xml-names/ there is no | 
|  | 2450 | * namespace name associated to "xmlns" | 
|  | 2451 | */ | 
|  | 2452 | prop = node->properties; | 
|  | 2453 | while (prop != NULL) { | 
|  | 2454 | /* | 
|  | 2455 | * One need to have | 
|  | 2456 | *   - same attribute names | 
|  | 2457 | *   - and the attribute carrying that namespace | 
|  | 2458 | */ | 
|  | 2459 | if (xmlStrEqual(prop->name, localName) && | 
|  | 2460 | ((prop->ns != NULL) && | 
|  | 2461 | (xmlStrEqual(prop->ns->href, namespaceURI)))) { | 
|  | 2462 | reader->curnode = (xmlNodePtr) prop; | 
|  | 2463 | return(1); | 
|  | 2464 | } | 
|  | 2465 | prop = prop->next; | 
|  | 2466 | } | 
|  | 2467 | return(0); | 
|  | 2468 | } | 
|  | 2469 |  | 
|  | 2470 | /** | 
|  | 2471 | * xmlTextReaderMoveToFirstAttribute: | 
|  | 2472 | * @reader:  the xmlTextReaderPtr used | 
|  | 2473 | * | 
|  | 2474 | * Moves the position of the current instance to the first attribute | 
|  | 2475 | * associated with the current node. | 
|  | 2476 | * | 
|  | 2477 | * Returns 1 in case of success, -1 in case of error, 0 if not found | 
|  | 2478 | */ | 
|  | 2479 | int | 
|  | 2480 | xmlTextReaderMoveToFirstAttribute(xmlTextReaderPtr reader) { | 
|  | 2481 | if (reader == NULL) | 
|  | 2482 | return(-1); | 
|  | 2483 | if (reader->node == NULL) | 
|  | 2484 | return(-1); | 
|  | 2485 | if (reader->node->type != XML_ELEMENT_NODE) | 
|  | 2486 | return(0); | 
|  | 2487 |  | 
|  | 2488 | if (reader->node->nsDef != NULL) { | 
|  | 2489 | reader->curnode = (xmlNodePtr) reader->node->nsDef; | 
|  | 2490 | return(1); | 
|  | 2491 | } | 
|  | 2492 | if (reader->node->properties != NULL) { | 
|  | 2493 | reader->curnode = (xmlNodePtr) reader->node->properties; | 
|  | 2494 | return(1); | 
|  | 2495 | } | 
|  | 2496 | return(0); | 
|  | 2497 | } | 
|  | 2498 |  | 
|  | 2499 | /** | 
|  | 2500 | * xmlTextReaderMoveToNextAttribute: | 
|  | 2501 | * @reader:  the xmlTextReaderPtr used | 
|  | 2502 | * | 
|  | 2503 | * Moves the position of the current instance to the next attribute | 
|  | 2504 | * associated with the current node. | 
|  | 2505 | * | 
|  | 2506 | * Returns 1 in case of success, -1 in case of error, 0 if not found | 
|  | 2507 | */ | 
|  | 2508 | int | 
|  | 2509 | xmlTextReaderMoveToNextAttribute(xmlTextReaderPtr reader) { | 
|  | 2510 | if (reader == NULL) | 
|  | 2511 | return(-1); | 
|  | 2512 | if (reader->node == NULL) | 
|  | 2513 | return(-1); | 
|  | 2514 | if (reader->node->type != XML_ELEMENT_NODE) | 
|  | 2515 | return(0); | 
|  | 2516 | if (reader->curnode == NULL) | 
|  | 2517 | return(xmlTextReaderMoveToFirstAttribute(reader)); | 
|  | 2518 |  | 
|  | 2519 | if (reader->curnode->type == XML_NAMESPACE_DECL) { | 
|  | 2520 | xmlNsPtr ns = (xmlNsPtr) reader->curnode; | 
|  | 2521 | if (ns->next != NULL) { | 
|  | 2522 | reader->curnode = (xmlNodePtr) ns->next; | 
|  | 2523 | return(1); | 
|  | 2524 | } | 
|  | 2525 | if (reader->node->properties != NULL) { | 
|  | 2526 | reader->curnode = (xmlNodePtr) reader->node->properties; | 
|  | 2527 | return(1); | 
|  | 2528 | } | 
|  | 2529 | return(0); | 
|  | 2530 | } else if ((reader->curnode->type == XML_ATTRIBUTE_NODE) && | 
|  | 2531 | (reader->curnode->next != NULL)) { | 
|  | 2532 | reader->curnode = reader->curnode->next; | 
|  | 2533 | return(1); | 
|  | 2534 | } | 
|  | 2535 | return(0); | 
|  | 2536 | } | 
|  | 2537 |  | 
|  | 2538 | /** | 
|  | 2539 | * xmlTextReaderMoveToElement: | 
|  | 2540 | * @reader:  the xmlTextReaderPtr used | 
|  | 2541 | * | 
|  | 2542 | * Moves the position of the current instance to the node that | 
|  | 2543 | * contains the current Attribute  node. | 
|  | 2544 | * | 
|  | 2545 | * Returns 1 in case of success, -1 in case of error, 0 if not moved | 
|  | 2546 | */ | 
|  | 2547 | int | 
|  | 2548 | xmlTextReaderMoveToElement(xmlTextReaderPtr reader) { | 
|  | 2549 | if (reader == NULL) | 
|  | 2550 | return(-1); | 
|  | 2551 | if (reader->node == NULL) | 
|  | 2552 | return(-1); | 
|  | 2553 | if (reader->node->type != XML_ELEMENT_NODE) | 
|  | 2554 | return(0); | 
|  | 2555 | if (reader->curnode != NULL) { | 
|  | 2556 | reader->curnode = NULL; | 
|  | 2557 | return(1); | 
|  | 2558 | } | 
|  | 2559 | return(0); | 
|  | 2560 | } | 
|  | 2561 |  | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 2562 | /** | 
|  | 2563 | * xmlTextReaderReadAttributeValue: | 
|  | 2564 | * @reader:  the xmlTextReaderPtr used | 
|  | 2565 | * | 
|  | 2566 | * Parses an attribute value into one or more Text and EntityReference nodes. | 
|  | 2567 | * | 
|  | 2568 | * Returns 1 in case of success, 0 if the reader was not positionned on an | 
|  | 2569 | *         ttribute node or all the attribute values have been read, or -1 | 
|  | 2570 | *         in case of error. | 
|  | 2571 | */ | 
|  | 2572 | int | 
|  | 2573 | xmlTextReaderReadAttributeValue(xmlTextReaderPtr reader) { | 
|  | 2574 | if (reader == NULL) | 
|  | 2575 | return(-1); | 
|  | 2576 | if (reader->node == NULL) | 
|  | 2577 | return(-1); | 
|  | 2578 | if (reader->curnode == NULL) | 
|  | 2579 | return(0); | 
|  | 2580 | if (reader->curnode->type == XML_ATTRIBUTE_NODE) { | 
|  | 2581 | if (reader->curnode->children == NULL) | 
|  | 2582 | return(0); | 
|  | 2583 | reader->curnode = reader->curnode->children; | 
|  | 2584 | } else if (reader->curnode->type == XML_NAMESPACE_DECL) { | 
|  | 2585 | xmlNsPtr ns = (xmlNsPtr) reader->curnode; | 
|  | 2586 |  | 
|  | 2587 | if (reader->faketext == NULL) { | 
|  | 2588 | reader->faketext = xmlNewDocText(reader->node->doc, | 
|  | 2589 | ns->href); | 
|  | 2590 | } else { | 
|  | 2591 | if (reader->faketext->content != NULL) | 
|  | 2592 | xmlFree(reader->faketext->content); | 
|  | 2593 | reader->faketext->content = xmlStrdup(ns->href); | 
|  | 2594 | } | 
|  | 2595 | reader->curnode = reader->faketext; | 
|  | 2596 | } else { | 
|  | 2597 | if (reader->curnode->next == NULL) | 
|  | 2598 | return(0); | 
|  | 2599 | reader->curnode = reader->curnode->next; | 
|  | 2600 | } | 
|  | 2601 | return(1); | 
|  | 2602 | } | 
|  | 2603 |  | 
| Daniel Veillard | 0eb38c7 | 2002-12-14 23:00:35 +0000 | [diff] [blame] | 2604 | /************************************************************************ | 
|  | 2605 | *									* | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2606 | *			Acces API to the current node			* | 
|  | 2607 | *									* | 
|  | 2608 | ************************************************************************/ | 
|  | 2609 | /** | 
|  | 2610 | * xmlTextReaderAttributeCount: | 
|  | 2611 | * @reader:  the xmlTextReaderPtr used | 
|  | 2612 | * | 
| Daniel Veillard | a9b66d0 | 2002-12-11 14:23:49 +0000 | [diff] [blame] | 2613 | * Provides the number of attributes of the current node | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2614 | * | 
|  | 2615 | * Returns 0 i no attributes, -1 in case of error or the attribute count | 
|  | 2616 | */ | 
|  | 2617 | int | 
|  | 2618 | xmlTextReaderAttributeCount(xmlTextReaderPtr reader) { | 
|  | 2619 | int ret; | 
|  | 2620 | xmlAttrPtr attr; | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 2621 | xmlNsPtr ns; | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2622 | xmlNodePtr node; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2623 |  | 
|  | 2624 | if (reader == NULL) | 
|  | 2625 | return(-1); | 
|  | 2626 | if (reader->node == NULL) | 
|  | 2627 | return(0); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2628 |  | 
|  | 2629 | if (reader->curnode != NULL) | 
|  | 2630 | node = reader->curnode; | 
|  | 2631 | else | 
|  | 2632 | node = reader->node; | 
|  | 2633 |  | 
|  | 2634 | if (node->type != XML_ELEMENT_NODE) | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2635 | return(0); | 
|  | 2636 | if ((reader->state == XML_TEXTREADER_END) || | 
|  | 2637 | (reader->state == XML_TEXTREADER_BACKTRACK)) | 
|  | 2638 | return(0); | 
|  | 2639 | ret = 0; | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2640 | attr = node->properties; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2641 | while (attr != NULL) { | 
|  | 2642 | ret++; | 
|  | 2643 | attr = attr->next; | 
|  | 2644 | } | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 2645 | ns = node->nsDef; | 
|  | 2646 | while (ns != NULL) { | 
|  | 2647 | ret++; | 
|  | 2648 | ns = ns->next; | 
|  | 2649 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2650 | return(ret); | 
|  | 2651 | } | 
|  | 2652 |  | 
|  | 2653 | /** | 
|  | 2654 | * xmlTextReaderNodeType: | 
|  | 2655 | * @reader:  the xmlTextReaderPtr used | 
|  | 2656 | * | 
|  | 2657 | * Get the node type of the current node | 
|  | 2658 | * Reference: | 
|  | 2659 | * http://dotgnu.org/pnetlib-doc/System/Xml/XmlNodeType.html | 
|  | 2660 | * | 
|  | 2661 | * Returns the xmlNodeType of the current node or -1 in case of error | 
|  | 2662 | */ | 
|  | 2663 | int | 
|  | 2664 | xmlTextReaderNodeType(xmlTextReaderPtr reader) { | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2665 | xmlNodePtr node; | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2666 |  | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2667 | if (reader == NULL) | 
|  | 2668 | return(-1); | 
|  | 2669 | if (reader->node == NULL) | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2670 | return(XML_READER_TYPE_NONE); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2671 | if (reader->curnode != NULL) | 
|  | 2672 | node = reader->curnode; | 
|  | 2673 | else | 
|  | 2674 | node = reader->node; | 
|  | 2675 | switch (node->type) { | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2676 | case XML_ELEMENT_NODE: | 
|  | 2677 | if ((reader->state == XML_TEXTREADER_END) || | 
|  | 2678 | (reader->state == XML_TEXTREADER_BACKTRACK)) | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2679 | return(XML_READER_TYPE_END_ELEMENT); | 
|  | 2680 | return(XML_READER_TYPE_ELEMENT); | 
| Daniel Veillard | ecaba49 | 2002-12-30 10:55:29 +0000 | [diff] [blame] | 2681 | case XML_NAMESPACE_DECL: | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2682 | case XML_ATTRIBUTE_NODE: | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2683 | return(XML_READER_TYPE_ATTRIBUTE); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2684 | case XML_TEXT_NODE: | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2685 | if (xmlIsBlankNode(reader->node)) { | 
|  | 2686 | if (xmlNodeGetSpacePreserve(reader->node)) | 
|  | 2687 | return(XML_READER_TYPE_SIGNIFICANT_WHITESPACE); | 
|  | 2688 | else | 
|  | 2689 | return(XML_READER_TYPE_WHITESPACE); | 
|  | 2690 | } else { | 
|  | 2691 | return(XML_READER_TYPE_TEXT); | 
|  | 2692 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2693 | case XML_CDATA_SECTION_NODE: | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2694 | return(XML_READER_TYPE_CDATA); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2695 | case XML_ENTITY_REF_NODE: | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2696 | return(XML_READER_TYPE_ENTITY_REFERENCE); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2697 | case XML_ENTITY_NODE: | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2698 | return(XML_READER_TYPE_ENTITY); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2699 | case XML_PI_NODE: | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2700 | return(XML_READER_TYPE_PROCESSING_INSTRUCTION); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2701 | case XML_COMMENT_NODE: | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2702 | return(XML_READER_TYPE_COMMENT); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2703 | case XML_DOCUMENT_NODE: | 
|  | 2704 | case XML_HTML_DOCUMENT_NODE: | 
|  | 2705 | #ifdef LIBXML_DOCB_ENABLED | 
|  | 2706 | case XML_DOCB_DOCUMENT_NODE: | 
|  | 2707 | #endif | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2708 | return(XML_READER_TYPE_DOCUMENT); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2709 | case XML_DOCUMENT_FRAG_NODE: | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2710 | return(XML_READER_TYPE_DOCUMENT_FRAGMENT); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2711 | case XML_NOTATION_NODE: | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2712 | return(XML_READER_TYPE_NOTATION); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2713 | case XML_DOCUMENT_TYPE_NODE: | 
|  | 2714 | case XML_DTD_NODE: | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2715 | return(XML_READER_TYPE_DOCUMENT_TYPE); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2716 |  | 
|  | 2717 | case XML_ELEMENT_DECL: | 
|  | 2718 | case XML_ATTRIBUTE_DECL: | 
|  | 2719 | case XML_ENTITY_DECL: | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2720 | case XML_XINCLUDE_START: | 
|  | 2721 | case XML_XINCLUDE_END: | 
| Daniel Veillard | d6038e0 | 2003-07-30 16:37:18 +0000 | [diff] [blame] | 2722 | return(XML_READER_TYPE_NONE); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2723 | } | 
|  | 2724 | return(-1); | 
|  | 2725 | } | 
|  | 2726 |  | 
|  | 2727 | /** | 
| Daniel Veillard | 01c13b5 | 2002-12-10 15:19:08 +0000 | [diff] [blame] | 2728 | * xmlTextReaderIsEmptyElement: | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2729 | * @reader:  the xmlTextReaderPtr used | 
|  | 2730 | * | 
|  | 2731 | * Check if the current node is empty | 
|  | 2732 | * | 
|  | 2733 | * Returns 1 if empty, 0 if not and -1 in case of error | 
|  | 2734 | */ | 
|  | 2735 | int | 
|  | 2736 | xmlTextReaderIsEmptyElement(xmlTextReaderPtr reader) { | 
|  | 2737 | if ((reader == NULL) || (reader->node == NULL)) | 
|  | 2738 | return(-1); | 
| Daniel Veillard | df512f4 | 2002-12-23 15:56:21 +0000 | [diff] [blame] | 2739 | if (reader->node->type != XML_ELEMENT_NODE) | 
|  | 2740 | return(0); | 
| Daniel Veillard | e3c036e | 2003-01-01 15:11:05 +0000 | [diff] [blame] | 2741 | if (reader->curnode != NULL) | 
|  | 2742 | return(0); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2743 | if (reader->node->children != NULL) | 
|  | 2744 | return(0); | 
| Daniel Veillard | dab8ea9 | 2003-01-02 14:16:45 +0000 | [diff] [blame] | 2745 | if (reader->state == XML_TEXTREADER_END) | 
|  | 2746 | return(0); | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 2747 | if (reader->doc != NULL) | 
|  | 2748 | return(1); | 
| Daniel Veillard | 96b6cd2 | 2004-01-08 16:49:50 +0000 | [diff] [blame^] | 2749 | #ifdef LIBXML_XINCLUDE_ENABLED | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 2750 | if (reader->in_xinclude > 0) | 
|  | 2751 | return(1); | 
| Daniel Veillard | 96b6cd2 | 2004-01-08 16:49:50 +0000 | [diff] [blame^] | 2752 | #endif | 
| Daniel Veillard | e8039df | 2003-10-27 11:25:13 +0000 | [diff] [blame] | 2753 | return((reader->node->extra & NODE_IS_EMPTY) != 0); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2754 | } | 
|  | 2755 |  | 
|  | 2756 | /** | 
|  | 2757 | * xmlTextReaderLocalName: | 
|  | 2758 | * @reader:  the xmlTextReaderPtr used | 
|  | 2759 | * | 
|  | 2760 | * The local name of the node. | 
|  | 2761 | * | 
|  | 2762 | * Returns the local name or NULL if not available | 
|  | 2763 | */ | 
|  | 2764 | xmlChar * | 
|  | 2765 | xmlTextReaderLocalName(xmlTextReaderPtr reader) { | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2766 | xmlNodePtr node; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2767 | if ((reader == NULL) || (reader->node == NULL)) | 
|  | 2768 | return(NULL); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2769 | if (reader->curnode != NULL) | 
|  | 2770 | node = reader->curnode; | 
|  | 2771 | else | 
|  | 2772 | node = reader->node; | 
|  | 2773 | if (node->type == XML_NAMESPACE_DECL) { | 
|  | 2774 | xmlNsPtr ns = (xmlNsPtr) node; | 
|  | 2775 | if (ns->prefix == NULL) | 
|  | 2776 | return(xmlStrdup(BAD_CAST "xmlns")); | 
|  | 2777 | else | 
|  | 2778 | return(xmlStrdup(ns->prefix)); | 
|  | 2779 | } | 
|  | 2780 | if ((node->type != XML_ELEMENT_NODE) && | 
|  | 2781 | (node->type != XML_ATTRIBUTE_NODE)) | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 2782 | return(xmlTextReaderName(reader)); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2783 | return(xmlStrdup(node->name)); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2784 | } | 
|  | 2785 |  | 
|  | 2786 | /** | 
| Daniel Veillard | e72c508 | 2003-09-19 12:44:05 +0000 | [diff] [blame] | 2787 | * xmlTextReaderConstLocalName: | 
|  | 2788 | * @reader:  the xmlTextReaderPtr used | 
|  | 2789 | * | 
|  | 2790 | * The local name of the node. | 
|  | 2791 | * | 
|  | 2792 | * Returns the local name or NULL if not available, the | 
|  | 2793 | *         string will be deallocated with the reader. | 
|  | 2794 | */ | 
|  | 2795 | const xmlChar * | 
|  | 2796 | xmlTextReaderConstLocalName(xmlTextReaderPtr reader) { | 
|  | 2797 | xmlNodePtr node; | 
|  | 2798 | if ((reader == NULL) || (reader->node == NULL)) | 
|  | 2799 | return(NULL); | 
|  | 2800 | if (reader->curnode != NULL) | 
|  | 2801 | node = reader->curnode; | 
|  | 2802 | else | 
|  | 2803 | node = reader->node; | 
|  | 2804 | if (node->type == XML_NAMESPACE_DECL) { | 
|  | 2805 | xmlNsPtr ns = (xmlNsPtr) node; | 
|  | 2806 | if (ns->prefix == NULL) | 
|  | 2807 | return(CONSTSTR(BAD_CAST "xmlns")); | 
|  | 2808 | else | 
|  | 2809 | return(ns->prefix); | 
|  | 2810 | } | 
|  | 2811 | if ((node->type != XML_ELEMENT_NODE) && | 
|  | 2812 | (node->type != XML_ATTRIBUTE_NODE)) | 
|  | 2813 | return(xmlTextReaderConstName(reader)); | 
|  | 2814 | return(node->name); | 
|  | 2815 | } | 
|  | 2816 |  | 
|  | 2817 | /** | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2818 | * xmlTextReaderName: | 
|  | 2819 | * @reader:  the xmlTextReaderPtr used | 
|  | 2820 | * | 
|  | 2821 | * The qualified name of the node, equal to Prefix :LocalName. | 
|  | 2822 | * | 
|  | 2823 | * Returns the local name or NULL if not available | 
|  | 2824 | */ | 
|  | 2825 | xmlChar * | 
|  | 2826 | xmlTextReaderName(xmlTextReaderPtr reader) { | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2827 | xmlNodePtr node; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2828 | xmlChar *ret; | 
|  | 2829 |  | 
|  | 2830 | if ((reader == NULL) || (reader->node == NULL)) | 
|  | 2831 | return(NULL); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2832 | if (reader->curnode != NULL) | 
|  | 2833 | node = reader->curnode; | 
|  | 2834 | else | 
|  | 2835 | node = reader->node; | 
|  | 2836 | switch (node->type) { | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 2837 | case XML_ELEMENT_NODE: | 
|  | 2838 | case XML_ATTRIBUTE_NODE: | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2839 | if ((node->ns == NULL) || | 
|  | 2840 | (node->ns->prefix == NULL)) | 
|  | 2841 | return(xmlStrdup(node->name)); | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 2842 |  | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2843 | ret = xmlStrdup(node->ns->prefix); | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 2844 | ret = xmlStrcat(ret, BAD_CAST ":"); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2845 | ret = xmlStrcat(ret, node->name); | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 2846 | return(ret); | 
|  | 2847 | case XML_TEXT_NODE: | 
|  | 2848 | return(xmlStrdup(BAD_CAST "#text")); | 
|  | 2849 | case XML_CDATA_SECTION_NODE: | 
|  | 2850 | return(xmlStrdup(BAD_CAST "#cdata-section")); | 
|  | 2851 | case XML_ENTITY_NODE: | 
|  | 2852 | case XML_ENTITY_REF_NODE: | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2853 | return(xmlStrdup(node->name)); | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 2854 | case XML_PI_NODE: | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2855 | return(xmlStrdup(node->name)); | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 2856 | case XML_COMMENT_NODE: | 
|  | 2857 | return(xmlStrdup(BAD_CAST "#comment")); | 
|  | 2858 | case XML_DOCUMENT_NODE: | 
|  | 2859 | case XML_HTML_DOCUMENT_NODE: | 
|  | 2860 | #ifdef LIBXML_DOCB_ENABLED | 
|  | 2861 | case XML_DOCB_DOCUMENT_NODE: | 
|  | 2862 | #endif | 
|  | 2863 | return(xmlStrdup(BAD_CAST "#document")); | 
|  | 2864 | case XML_DOCUMENT_FRAG_NODE: | 
|  | 2865 | return(xmlStrdup(BAD_CAST "#document-fragment")); | 
|  | 2866 | case XML_NOTATION_NODE: | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2867 | return(xmlStrdup(node->name)); | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 2868 | case XML_DOCUMENT_TYPE_NODE: | 
|  | 2869 | case XML_DTD_NODE: | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2870 | return(xmlStrdup(node->name)); | 
|  | 2871 | case XML_NAMESPACE_DECL: { | 
|  | 2872 | xmlNsPtr ns = (xmlNsPtr) node; | 
|  | 2873 |  | 
|  | 2874 | ret = xmlStrdup(BAD_CAST "xmlns"); | 
|  | 2875 | if (ns->prefix == NULL) | 
|  | 2876 | return(ret); | 
|  | 2877 | ret = xmlStrcat(ret, BAD_CAST ":"); | 
|  | 2878 | ret = xmlStrcat(ret, ns->prefix); | 
|  | 2879 | return(ret); | 
|  | 2880 | } | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 2881 |  | 
|  | 2882 | case XML_ELEMENT_DECL: | 
|  | 2883 | case XML_ATTRIBUTE_DECL: | 
|  | 2884 | case XML_ENTITY_DECL: | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 2885 | case XML_XINCLUDE_START: | 
|  | 2886 | case XML_XINCLUDE_END: | 
|  | 2887 | return(NULL); | 
|  | 2888 | } | 
|  | 2889 | return(NULL); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2890 | } | 
|  | 2891 |  | 
|  | 2892 | /** | 
| Daniel Veillard | e72c508 | 2003-09-19 12:44:05 +0000 | [diff] [blame] | 2893 | * xmlTextReaderConstName: | 
|  | 2894 | * @reader:  the xmlTextReaderPtr used | 
|  | 2895 | * | 
|  | 2896 | * The qualified name of the node, equal to Prefix :LocalName. | 
|  | 2897 | * | 
|  | 2898 | * Returns the local name or NULL if not available, the string is | 
|  | 2899 | *         deallocated with the reader. | 
|  | 2900 | */ | 
|  | 2901 | const xmlChar * | 
|  | 2902 | xmlTextReaderConstName(xmlTextReaderPtr reader) { | 
|  | 2903 | xmlNodePtr node; | 
|  | 2904 |  | 
|  | 2905 | if ((reader == NULL) || (reader->node == NULL)) | 
|  | 2906 | return(NULL); | 
|  | 2907 | if (reader->curnode != NULL) | 
|  | 2908 | node = reader->curnode; | 
|  | 2909 | else | 
|  | 2910 | node = reader->node; | 
|  | 2911 | switch (node->type) { | 
|  | 2912 | case XML_ELEMENT_NODE: | 
|  | 2913 | case XML_ATTRIBUTE_NODE: | 
|  | 2914 | if ((node->ns == NULL) || | 
|  | 2915 | (node->ns->prefix == NULL)) | 
|  | 2916 | return(node->name); | 
|  | 2917 | return(CONSTQSTR(node->ns->prefix, node->name)); | 
|  | 2918 | case XML_TEXT_NODE: | 
|  | 2919 | return(CONSTSTR(BAD_CAST "#text")); | 
|  | 2920 | case XML_CDATA_SECTION_NODE: | 
|  | 2921 | return(CONSTSTR(BAD_CAST "#cdata-section")); | 
|  | 2922 | case XML_ENTITY_NODE: | 
|  | 2923 | case XML_ENTITY_REF_NODE: | 
|  | 2924 | return(CONSTSTR(node->name)); | 
|  | 2925 | case XML_PI_NODE: | 
|  | 2926 | return(CONSTSTR(node->name)); | 
|  | 2927 | case XML_COMMENT_NODE: | 
|  | 2928 | return(CONSTSTR(BAD_CAST "#comment")); | 
|  | 2929 | case XML_DOCUMENT_NODE: | 
|  | 2930 | case XML_HTML_DOCUMENT_NODE: | 
|  | 2931 | #ifdef LIBXML_DOCB_ENABLED | 
|  | 2932 | case XML_DOCB_DOCUMENT_NODE: | 
|  | 2933 | #endif | 
|  | 2934 | return(CONSTSTR(BAD_CAST "#document")); | 
|  | 2935 | case XML_DOCUMENT_FRAG_NODE: | 
|  | 2936 | return(CONSTSTR(BAD_CAST "#document-fragment")); | 
|  | 2937 | case XML_NOTATION_NODE: | 
|  | 2938 | return(CONSTSTR(node->name)); | 
|  | 2939 | case XML_DOCUMENT_TYPE_NODE: | 
|  | 2940 | case XML_DTD_NODE: | 
|  | 2941 | return(CONSTSTR(node->name)); | 
|  | 2942 | case XML_NAMESPACE_DECL: { | 
|  | 2943 | xmlNsPtr ns = (xmlNsPtr) node; | 
|  | 2944 |  | 
|  | 2945 | if (ns->prefix == NULL) | 
|  | 2946 | return(CONSTSTR(BAD_CAST "xmlns")); | 
|  | 2947 | return(CONSTQSTR(BAD_CAST "xmlns", ns->prefix)); | 
|  | 2948 | } | 
|  | 2949 |  | 
|  | 2950 | case XML_ELEMENT_DECL: | 
|  | 2951 | case XML_ATTRIBUTE_DECL: | 
|  | 2952 | case XML_ENTITY_DECL: | 
|  | 2953 | case XML_XINCLUDE_START: | 
|  | 2954 | case XML_XINCLUDE_END: | 
|  | 2955 | return(NULL); | 
|  | 2956 | } | 
|  | 2957 | return(NULL); | 
|  | 2958 | } | 
|  | 2959 |  | 
|  | 2960 | /** | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2961 | * xmlTextReaderPrefix: | 
|  | 2962 | * @reader:  the xmlTextReaderPtr used | 
|  | 2963 | * | 
|  | 2964 | * A shorthand reference to the namespace associated with the node. | 
|  | 2965 | * | 
|  | 2966 | * Returns the prefix or NULL if not available | 
|  | 2967 | */ | 
|  | 2968 | xmlChar * | 
|  | 2969 | xmlTextReaderPrefix(xmlTextReaderPtr reader) { | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2970 | xmlNodePtr node; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2971 | if ((reader == NULL) || (reader->node == NULL)) | 
|  | 2972 | return(NULL); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2973 | if (reader->curnode != NULL) | 
|  | 2974 | node = reader->curnode; | 
|  | 2975 | else | 
|  | 2976 | node = reader->node; | 
|  | 2977 | if (node->type == XML_NAMESPACE_DECL) { | 
|  | 2978 | xmlNsPtr ns = (xmlNsPtr) node; | 
|  | 2979 | if (ns->prefix == NULL) | 
|  | 2980 | return(NULL); | 
|  | 2981 | return(xmlStrdup(BAD_CAST "xmlns")); | 
|  | 2982 | } | 
|  | 2983 | if ((node->type != XML_ELEMENT_NODE) && | 
|  | 2984 | (node->type != XML_ATTRIBUTE_NODE)) | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2985 | return(NULL); | 
| Daniel Veillard | 952379b | 2003-03-17 15:37:12 +0000 | [diff] [blame] | 2986 | if ((node->ns != NULL) && (node->ns->prefix != NULL)) | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 2987 | return(xmlStrdup(node->ns->prefix)); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 2988 | return(NULL); | 
|  | 2989 | } | 
|  | 2990 |  | 
|  | 2991 | /** | 
| Daniel Veillard | e72c508 | 2003-09-19 12:44:05 +0000 | [diff] [blame] | 2992 | * xmlTextReaderConstPrefix: | 
|  | 2993 | * @reader:  the xmlTextReaderPtr used | 
|  | 2994 | * | 
|  | 2995 | * A shorthand reference to the namespace associated with the node. | 
|  | 2996 | * | 
|  | 2997 | * Returns the prefix or NULL if not available, the string is deallocated | 
|  | 2998 | *         with the reader. | 
|  | 2999 | */ | 
|  | 3000 | const xmlChar * | 
|  | 3001 | xmlTextReaderConstPrefix(xmlTextReaderPtr reader) { | 
|  | 3002 | xmlNodePtr node; | 
|  | 3003 | if ((reader == NULL) || (reader->node == NULL)) | 
|  | 3004 | return(NULL); | 
|  | 3005 | if (reader->curnode != NULL) | 
|  | 3006 | node = reader->curnode; | 
|  | 3007 | else | 
|  | 3008 | node = reader->node; | 
|  | 3009 | if (node->type == XML_NAMESPACE_DECL) { | 
|  | 3010 | xmlNsPtr ns = (xmlNsPtr) node; | 
|  | 3011 | if (ns->prefix == NULL) | 
|  | 3012 | return(NULL); | 
|  | 3013 | return(CONSTSTR(BAD_CAST "xmlns")); | 
|  | 3014 | } | 
|  | 3015 | if ((node->type != XML_ELEMENT_NODE) && | 
|  | 3016 | (node->type != XML_ATTRIBUTE_NODE)) | 
|  | 3017 | return(NULL); | 
|  | 3018 | if ((node->ns != NULL) && (node->ns->prefix != NULL)) | 
|  | 3019 | return(CONSTSTR(node->ns->prefix)); | 
|  | 3020 | return(NULL); | 
|  | 3021 | } | 
|  | 3022 |  | 
|  | 3023 | /** | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3024 | * xmlTextReaderNamespaceUri: | 
|  | 3025 | * @reader:  the xmlTextReaderPtr used | 
|  | 3026 | * | 
|  | 3027 | * The URI defining the namespace associated with the node. | 
|  | 3028 | * | 
|  | 3029 | * Returns the namespace URI or NULL if not available | 
|  | 3030 | */ | 
|  | 3031 | xmlChar * | 
|  | 3032 | xmlTextReaderNamespaceUri(xmlTextReaderPtr reader) { | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3033 | xmlNodePtr node; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3034 | if ((reader == NULL) || (reader->node == NULL)) | 
|  | 3035 | return(NULL); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3036 | if (reader->curnode != NULL) | 
|  | 3037 | node = reader->curnode; | 
|  | 3038 | else | 
|  | 3039 | node = reader->node; | 
| Daniel Veillard | ecaba49 | 2002-12-30 10:55:29 +0000 | [diff] [blame] | 3040 | if (node->type == XML_NAMESPACE_DECL) | 
|  | 3041 | return(xmlStrdup(BAD_CAST "http://www.w3.org/2000/xmlns/")); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3042 | if ((node->type != XML_ELEMENT_NODE) && | 
|  | 3043 | (node->type != XML_ATTRIBUTE_NODE)) | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3044 | return(NULL); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3045 | if (node->ns != NULL) | 
|  | 3046 | return(xmlStrdup(node->ns->href)); | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3047 | return(NULL); | 
|  | 3048 | } | 
|  | 3049 |  | 
|  | 3050 | /** | 
| Daniel Veillard | e72c508 | 2003-09-19 12:44:05 +0000 | [diff] [blame] | 3051 | * xmlTextReaderConstNamespaceUri: | 
|  | 3052 | * @reader:  the xmlTextReaderPtr used | 
|  | 3053 | * | 
|  | 3054 | * The URI defining the namespace associated with the node. | 
|  | 3055 | * | 
|  | 3056 | * Returns the namespace URI or NULL if not available, the string | 
|  | 3057 | *         will be deallocated with the reader | 
|  | 3058 | */ | 
|  | 3059 | const xmlChar * | 
|  | 3060 | xmlTextReaderConstNamespaceUri(xmlTextReaderPtr reader) { | 
|  | 3061 | xmlNodePtr node; | 
|  | 3062 | if ((reader == NULL) || (reader->node == NULL)) | 
|  | 3063 | return(NULL); | 
|  | 3064 | if (reader->curnode != NULL) | 
|  | 3065 | node = reader->curnode; | 
|  | 3066 | else | 
|  | 3067 | node = reader->node; | 
|  | 3068 | if (node->type == XML_NAMESPACE_DECL) | 
|  | 3069 | return(CONSTSTR(BAD_CAST "http://www.w3.org/2000/xmlns/")); | 
|  | 3070 | if ((node->type != XML_ELEMENT_NODE) && | 
|  | 3071 | (node->type != XML_ATTRIBUTE_NODE)) | 
|  | 3072 | return(NULL); | 
|  | 3073 | if (node->ns != NULL) | 
|  | 3074 | return(CONSTSTR(node->ns->href)); | 
|  | 3075 | return(NULL); | 
|  | 3076 | } | 
|  | 3077 |  | 
|  | 3078 | /** | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3079 | * xmlTextReaderBaseUri: | 
|  | 3080 | * @reader:  the xmlTextReaderPtr used | 
|  | 3081 | * | 
|  | 3082 | * The base URI of the node. | 
|  | 3083 | * | 
|  | 3084 | * Returns the base URI or NULL if not available | 
|  | 3085 | */ | 
|  | 3086 | xmlChar * | 
|  | 3087 | xmlTextReaderBaseUri(xmlTextReaderPtr reader) { | 
|  | 3088 | if ((reader == NULL) || (reader->node == NULL)) | 
|  | 3089 | return(NULL); | 
|  | 3090 | return(xmlNodeGetBase(NULL, reader->node)); | 
|  | 3091 | } | 
|  | 3092 |  | 
|  | 3093 | /** | 
| Daniel Veillard | e72c508 | 2003-09-19 12:44:05 +0000 | [diff] [blame] | 3094 | * xmlTextReaderConstBaseUri: | 
|  | 3095 | * @reader:  the xmlTextReaderPtr used | 
|  | 3096 | * | 
|  | 3097 | * The base URI of the node. | 
|  | 3098 | * | 
|  | 3099 | * Returns the base URI or NULL if not available, the string | 
|  | 3100 | *         will be deallocated with the reader | 
|  | 3101 | */ | 
|  | 3102 | const xmlChar * | 
|  | 3103 | xmlTextReaderConstBaseUri(xmlTextReaderPtr reader) { | 
|  | 3104 | xmlChar *tmp; | 
|  | 3105 | const xmlChar *ret; | 
|  | 3106 |  | 
|  | 3107 | if ((reader == NULL) || (reader->node == NULL)) | 
|  | 3108 | return(NULL); | 
|  | 3109 | tmp = xmlNodeGetBase(NULL, reader->node); | 
|  | 3110 | if (tmp == NULL) | 
|  | 3111 | return(NULL); | 
|  | 3112 | ret = CONSTSTR(tmp); | 
|  | 3113 | xmlFree(tmp); | 
|  | 3114 | return(ret); | 
|  | 3115 | } | 
|  | 3116 |  | 
|  | 3117 | /** | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3118 | * xmlTextReaderDepth: | 
|  | 3119 | * @reader:  the xmlTextReaderPtr used | 
|  | 3120 | * | 
|  | 3121 | * The depth of the node in the tree. | 
|  | 3122 | * | 
|  | 3123 | * Returns the depth or -1 in case of error | 
|  | 3124 | */ | 
|  | 3125 | int | 
|  | 3126 | xmlTextReaderDepth(xmlTextReaderPtr reader) { | 
|  | 3127 | if (reader == NULL) | 
|  | 3128 | return(-1); | 
|  | 3129 | if (reader->node == NULL) | 
|  | 3130 | return(0); | 
|  | 3131 |  | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 3132 | if (reader->curnode != NULL) { | 
|  | 3133 | if ((reader->curnode->type == XML_ATTRIBUTE_NODE) || | 
|  | 3134 | (reader->curnode->type == XML_NAMESPACE_DECL)) | 
|  | 3135 | return(reader->depth + 1); | 
|  | 3136 | return(reader->depth + 2); | 
|  | 3137 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3138 | return(reader->depth); | 
|  | 3139 | } | 
|  | 3140 |  | 
|  | 3141 | /** | 
|  | 3142 | * xmlTextReaderHasAttributes: | 
|  | 3143 | * @reader:  the xmlTextReaderPtr used | 
|  | 3144 | * | 
|  | 3145 | * Whether the node has attributes. | 
|  | 3146 | * | 
|  | 3147 | * Returns 1 if true, 0 if false, and -1 in case or error | 
|  | 3148 | */ | 
|  | 3149 | int | 
|  | 3150 | xmlTextReaderHasAttributes(xmlTextReaderPtr reader) { | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3151 | xmlNodePtr node; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3152 | if (reader == NULL) | 
|  | 3153 | return(-1); | 
|  | 3154 | if (reader->node == NULL) | 
|  | 3155 | return(0); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3156 | if (reader->curnode != NULL) | 
|  | 3157 | node = reader->curnode; | 
|  | 3158 | else | 
|  | 3159 | node = reader->node; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3160 |  | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3161 | if ((node->type == XML_ELEMENT_NODE) && | 
|  | 3162 | (node->properties != NULL)) | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3163 | return(1); | 
|  | 3164 | /* TODO: handle the xmlDecl */ | 
|  | 3165 | return(0); | 
|  | 3166 | } | 
|  | 3167 |  | 
|  | 3168 | /** | 
|  | 3169 | * xmlTextReaderHasValue: | 
|  | 3170 | * @reader:  the xmlTextReaderPtr used | 
|  | 3171 | * | 
|  | 3172 | * Whether the node can have a text value. | 
|  | 3173 | * | 
|  | 3174 | * Returns 1 if true, 0 if false, and -1 in case or error | 
|  | 3175 | */ | 
|  | 3176 | int | 
|  | 3177 | xmlTextReaderHasValue(xmlTextReaderPtr reader) { | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3178 | xmlNodePtr node; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3179 | if (reader == NULL) | 
|  | 3180 | return(-1); | 
|  | 3181 | if (reader->node == NULL) | 
|  | 3182 | return(0); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3183 | if (reader->curnode != NULL) | 
|  | 3184 | node = reader->curnode; | 
|  | 3185 | else | 
|  | 3186 | node = reader->node; | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3187 |  | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3188 | switch (node->type) { | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3189 | case XML_ATTRIBUTE_NODE: | 
|  | 3190 | case XML_TEXT_NODE: | 
|  | 3191 | case XML_CDATA_SECTION_NODE: | 
|  | 3192 | case XML_PI_NODE: | 
|  | 3193 | case XML_COMMENT_NODE: | 
| Daniel Veillard | 9e07710 | 2003-04-10 13:36:54 +0000 | [diff] [blame] | 3194 | case XML_NAMESPACE_DECL: | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3195 | return(1); | 
|  | 3196 | default: | 
| Daniel Veillard | 2cfd9df | 2003-03-22 22:39:16 +0000 | [diff] [blame] | 3197 | break; | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3198 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3199 | return(0); | 
|  | 3200 | } | 
|  | 3201 |  | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3202 | /** | 
|  | 3203 | * xmlTextReaderValue: | 
|  | 3204 | * @reader:  the xmlTextReaderPtr used | 
|  | 3205 | * | 
|  | 3206 | * Provides the text value of the node if present | 
|  | 3207 | * | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 3208 | * Returns the string or NULL if not available. The result must be deallocated | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3209 | *     with xmlFree() | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3210 | */ | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3211 | xmlChar * | 
|  | 3212 | xmlTextReaderValue(xmlTextReaderPtr reader) { | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3213 | xmlNodePtr node; | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3214 | if (reader == NULL) | 
|  | 3215 | return(NULL); | 
|  | 3216 | if (reader->node == NULL) | 
|  | 3217 | return(NULL); | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3218 | if (reader->curnode != NULL) | 
|  | 3219 | node = reader->curnode; | 
|  | 3220 | else | 
|  | 3221 | node = reader->node; | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3222 |  | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3223 | switch (node->type) { | 
|  | 3224 | case XML_NAMESPACE_DECL: | 
|  | 3225 | return(xmlStrdup(((xmlNsPtr) node)->href)); | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3226 | case XML_ATTRIBUTE_NODE:{ | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3227 | xmlAttrPtr attr = (xmlAttrPtr) node; | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3228 |  | 
|  | 3229 | if (attr->parent != NULL) | 
|  | 3230 | return (xmlNodeListGetString | 
|  | 3231 | (attr->parent->doc, attr->children, 1)); | 
|  | 3232 | else | 
|  | 3233 | return (xmlNodeListGetString(NULL, attr->children, 1)); | 
|  | 3234 | break; | 
|  | 3235 | } | 
|  | 3236 | case XML_TEXT_NODE: | 
|  | 3237 | case XML_CDATA_SECTION_NODE: | 
|  | 3238 | case XML_PI_NODE: | 
|  | 3239 | case XML_COMMENT_NODE: | 
| Daniel Veillard | da46d2d | 2002-12-15 23:36:49 +0000 | [diff] [blame] | 3240 | if (node->content != NULL) | 
|  | 3241 | return (xmlStrdup(node->content)); | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3242 | default: | 
| Daniel Veillard | 2cfd9df | 2003-03-22 22:39:16 +0000 | [diff] [blame] | 3243 | break; | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3244 | } | 
|  | 3245 | return(NULL); | 
|  | 3246 | } | 
|  | 3247 |  | 
|  | 3248 | /** | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 3249 | * xmlTextReaderConstValue: | 
|  | 3250 | * @reader:  the xmlTextReaderPtr used | 
|  | 3251 | * | 
|  | 3252 | * Provides the text value of the node if present | 
|  | 3253 | * | 
|  | 3254 | * Returns the string or NULL if not available. The result will be | 
|  | 3255 | *     deallocated on the next Read() operation. | 
|  | 3256 | */ | 
|  | 3257 | const xmlChar * | 
|  | 3258 | xmlTextReaderConstValue(xmlTextReaderPtr reader) { | 
|  | 3259 | xmlNodePtr node; | 
|  | 3260 | if (reader == NULL) | 
|  | 3261 | return(NULL); | 
|  | 3262 | if (reader->node == NULL) | 
|  | 3263 | return(NULL); | 
|  | 3264 | if (reader->curnode != NULL) | 
|  | 3265 | node = reader->curnode; | 
|  | 3266 | else | 
|  | 3267 | node = reader->node; | 
|  | 3268 |  | 
|  | 3269 | switch (node->type) { | 
|  | 3270 | case XML_NAMESPACE_DECL: | 
|  | 3271 | return(((xmlNsPtr) node)->href); | 
|  | 3272 | case XML_ATTRIBUTE_NODE:{ | 
|  | 3273 | xmlAttrPtr attr = (xmlAttrPtr) node; | 
|  | 3274 |  | 
|  | 3275 | if ((attr->children != NULL) && | 
|  | 3276 | (attr->children->type == XML_TEXT_NODE) && | 
|  | 3277 | (attr->children->next == NULL)) | 
|  | 3278 | return(attr->children->content); | 
|  | 3279 | else { | 
|  | 3280 | reader->buffer->use = 0; | 
|  | 3281 | xmlNodeBufGetContent(reader->buffer, node); | 
|  | 3282 | return(reader->buffer->content); | 
|  | 3283 | } | 
|  | 3284 | break; | 
|  | 3285 | } | 
|  | 3286 | case XML_TEXT_NODE: | 
|  | 3287 | case XML_CDATA_SECTION_NODE: | 
|  | 3288 | case XML_PI_NODE: | 
|  | 3289 | case XML_COMMENT_NODE: | 
|  | 3290 | return(node->content); | 
|  | 3291 | default: | 
|  | 3292 | break; | 
|  | 3293 | } | 
|  | 3294 | return(NULL); | 
|  | 3295 | } | 
|  | 3296 |  | 
|  | 3297 | /** | 
| Daniel Veillard | 9b4bb4d | 2002-12-11 19:28:47 +0000 | [diff] [blame] | 3298 | * xmlTextReaderIsDefault: | 
|  | 3299 | * @reader:  the xmlTextReaderPtr used | 
|  | 3300 | * | 
|  | 3301 | * Whether an Attribute  node was generated from the default value | 
|  | 3302 | * defined in the DTD or schema. | 
|  | 3303 | * | 
|  | 3304 | * Returns 0 if not defaulted, 1 if defaulted, and -1 in case of error | 
|  | 3305 | */ | 
|  | 3306 | int | 
|  | 3307 | xmlTextReaderIsDefault(xmlTextReaderPtr reader) { | 
|  | 3308 | if (reader == NULL) | 
|  | 3309 | return(-1); | 
|  | 3310 | return(0); | 
|  | 3311 | } | 
|  | 3312 |  | 
|  | 3313 | /** | 
|  | 3314 | * xmlTextReaderQuoteChar: | 
|  | 3315 | * @reader:  the xmlTextReaderPtr used | 
|  | 3316 | * | 
|  | 3317 | * The quotation mark character used to enclose the value of an attribute. | 
|  | 3318 | * | 
|  | 3319 | * Returns " or ' and -1 in case of error | 
|  | 3320 | */ | 
|  | 3321 | int | 
|  | 3322 | xmlTextReaderQuoteChar(xmlTextReaderPtr reader) { | 
|  | 3323 | if (reader == NULL) | 
|  | 3324 | return(-1); | 
|  | 3325 | /* TODO maybe lookup the attribute value for " first */ | 
|  | 3326 | return((int) '"'); | 
|  | 3327 | } | 
| Daniel Veillard | e1ca503 | 2002-12-09 14:13:43 +0000 | [diff] [blame] | 3328 |  | 
|  | 3329 | /** | 
|  | 3330 | * xmlTextReaderXmlLang: | 
|  | 3331 | * @reader:  the xmlTextReaderPtr used | 
|  | 3332 | * | 
|  | 3333 | * The xml:lang scope within which the node resides. | 
|  | 3334 | * | 
|  | 3335 | * Returns the xml:lang value or NULL if none exists. | 
|  | 3336 | */ | 
|  | 3337 | xmlChar * | 
|  | 3338 | xmlTextReaderXmlLang(xmlTextReaderPtr reader) { | 
|  | 3339 | if (reader == NULL) | 
|  | 3340 | return(NULL); | 
|  | 3341 | if (reader->node == NULL) | 
|  | 3342 | return(NULL); | 
|  | 3343 | return(xmlNodeGetLang(reader->node)); | 
|  | 3344 | } | 
|  | 3345 |  | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 3346 | /** | 
| Daniel Veillard | 7a02cfe | 2003-09-25 12:18:34 +0000 | [diff] [blame] | 3347 | * xmlTextReaderConstXmlLang: | 
| Daniel Veillard | e72c508 | 2003-09-19 12:44:05 +0000 | [diff] [blame] | 3348 | * @reader:  the xmlTextReaderPtr used | 
|  | 3349 | * | 
|  | 3350 | * The xml:lang scope within which the node resides. | 
|  | 3351 | * | 
|  | 3352 | * Returns the xml:lang value or NULL if none exists. | 
|  | 3353 | */ | 
|  | 3354 | const xmlChar * | 
|  | 3355 | xmlTextReaderConstXmlLang(xmlTextReaderPtr reader) { | 
|  | 3356 | xmlChar *tmp; | 
|  | 3357 | const xmlChar *ret; | 
|  | 3358 |  | 
|  | 3359 | if (reader == NULL) | 
|  | 3360 | return(NULL); | 
|  | 3361 | if (reader->node == NULL) | 
|  | 3362 | return(NULL); | 
|  | 3363 | tmp = xmlNodeGetLang(reader->node); | 
|  | 3364 | if (tmp == NULL) | 
|  | 3365 | return(NULL); | 
|  | 3366 | ret = CONSTSTR(tmp); | 
|  | 3367 | xmlFree(tmp); | 
|  | 3368 | return(ret); | 
|  | 3369 | } | 
|  | 3370 |  | 
|  | 3371 | /** | 
| Daniel Veillard | f85ce8e | 2003-09-22 10:24:45 +0000 | [diff] [blame] | 3372 | * xmlTextReaderConstString: | 
|  | 3373 | * @reader:  the xmlTextReaderPtr used | 
|  | 3374 | * @str:  the string to intern. | 
|  | 3375 | * | 
|  | 3376 | * Get an interned string from the reader, allows for example to | 
|  | 3377 | * speedup string name comparisons | 
|  | 3378 | * | 
|  | 3379 | * Returns an interned copy of the string or NULL in case of error. The | 
|  | 3380 | *         string will be deallocated with the reader. | 
|  | 3381 | */ | 
|  | 3382 | const xmlChar * | 
|  | 3383 | xmlTextReaderConstString(xmlTextReaderPtr reader, const xmlChar *str) { | 
|  | 3384 | if (reader == NULL) | 
|  | 3385 | return(NULL); | 
|  | 3386 | return(CONSTSTR(str)); | 
|  | 3387 | } | 
|  | 3388 |  | 
|  | 3389 | /** | 
| Daniel Veillard | 67df809 | 2002-12-16 22:04:11 +0000 | [diff] [blame] | 3390 | * xmlTextReaderNormalization: | 
|  | 3391 | * @reader:  the xmlTextReaderPtr used | 
|  | 3392 | * | 
|  | 3393 | * The value indicating whether to normalize white space and attribute values. | 
|  | 3394 | * Since attribute value and end of line normalizations are a MUST in the XML | 
|  | 3395 | * specification only the value true is accepted. The broken bahaviour of | 
|  | 3396 | * accepting out of range character entities like � is of course not | 
|  | 3397 | * supported either. | 
|  | 3398 | * | 
|  | 3399 | * Returns 1 or -1 in case of error. | 
|  | 3400 | */ | 
|  | 3401 | int | 
|  | 3402 | xmlTextReaderNormalization(xmlTextReaderPtr reader) { | 
|  | 3403 | if (reader == NULL) | 
|  | 3404 | return(-1); | 
|  | 3405 | return(1); | 
|  | 3406 | } | 
|  | 3407 |  | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 3408 | /************************************************************************ | 
|  | 3409 | *									* | 
|  | 3410 | *			Extensions to the base APIs			* | 
|  | 3411 | *									* | 
|  | 3412 | ************************************************************************/ | 
|  | 3413 |  | 
|  | 3414 | /** | 
|  | 3415 | * xmlTextReaderSetParserProp: | 
|  | 3416 | * @reader:  the xmlTextReaderPtr used | 
|  | 3417 | * @prop:  the xmlParserProperties to set | 
|  | 3418 | * @value:  usually 0 or 1 to (de)activate it | 
|  | 3419 | * | 
|  | 3420 | * Change the parser processing behaviour by changing some of its internal | 
|  | 3421 | * properties. Note that some properties can only be changed before any | 
|  | 3422 | * read has been done. | 
|  | 3423 | * | 
|  | 3424 | * Returns 0 if the call was successful, or -1 in case of error | 
|  | 3425 | */ | 
|  | 3426 | int | 
|  | 3427 | xmlTextReaderSetParserProp(xmlTextReaderPtr reader, int prop, int value) { | 
|  | 3428 | xmlParserProperties p = (xmlParserProperties) prop; | 
|  | 3429 | xmlParserCtxtPtr ctxt; | 
|  | 3430 |  | 
|  | 3431 | if ((reader == NULL) || (reader->ctxt == NULL)) | 
|  | 3432 | return(-1); | 
|  | 3433 | ctxt = reader->ctxt; | 
|  | 3434 |  | 
|  | 3435 | switch (p) { | 
|  | 3436 | case XML_PARSER_LOADDTD: | 
|  | 3437 | if (value != 0) { | 
|  | 3438 | if (ctxt->loadsubset == 0) { | 
|  | 3439 | if (reader->mode != XML_TEXTREADER_MODE_INITIAL) | 
|  | 3440 | return(-1); | 
|  | 3441 | ctxt->loadsubset = XML_DETECT_IDS; | 
|  | 3442 | } | 
|  | 3443 | } else { | 
|  | 3444 | ctxt->loadsubset = 0; | 
|  | 3445 | } | 
|  | 3446 | return(0); | 
|  | 3447 | case XML_PARSER_DEFAULTATTRS: | 
|  | 3448 | if (value != 0) { | 
|  | 3449 | ctxt->loadsubset |= XML_COMPLETE_ATTRS; | 
|  | 3450 | } else { | 
|  | 3451 | if (ctxt->loadsubset & XML_COMPLETE_ATTRS) | 
|  | 3452 | ctxt->loadsubset -= XML_COMPLETE_ATTRS; | 
|  | 3453 | } | 
|  | 3454 | return(0); | 
|  | 3455 | case XML_PARSER_VALIDATE: | 
|  | 3456 | if (value != 0) { | 
|  | 3457 | ctxt->validate = 1; | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 3458 | reader->validate = XML_TEXTREADER_VALIDATE_DTD; | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 3459 | } else { | 
|  | 3460 | ctxt->validate = 0; | 
|  | 3461 | } | 
|  | 3462 | return(0); | 
| Daniel Veillard | e18fc18 | 2002-12-28 22:56:33 +0000 | [diff] [blame] | 3463 | case XML_PARSER_SUBST_ENTITIES: | 
|  | 3464 | if (value != 0) { | 
|  | 3465 | ctxt->replaceEntities = 1; | 
|  | 3466 | } else { | 
|  | 3467 | ctxt->replaceEntities = 0; | 
|  | 3468 | } | 
|  | 3469 | return(0); | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 3470 | } | 
|  | 3471 | return(-1); | 
|  | 3472 | } | 
|  | 3473 |  | 
|  | 3474 | /** | 
|  | 3475 | * xmlTextReaderGetParserProp: | 
|  | 3476 | * @reader:  the xmlTextReaderPtr used | 
|  | 3477 | * @prop:  the xmlParserProperties to get | 
|  | 3478 | * | 
|  | 3479 | * Read the parser internal property. | 
|  | 3480 | * | 
|  | 3481 | * Returns the value, usually 0 or 1, or -1 in case of error. | 
|  | 3482 | */ | 
|  | 3483 | int | 
|  | 3484 | xmlTextReaderGetParserProp(xmlTextReaderPtr reader, int prop) { | 
|  | 3485 | xmlParserProperties p = (xmlParserProperties) prop; | 
|  | 3486 | xmlParserCtxtPtr ctxt; | 
|  | 3487 |  | 
|  | 3488 | if ((reader == NULL) || (reader->ctxt == NULL)) | 
|  | 3489 | return(-1); | 
|  | 3490 | ctxt = reader->ctxt; | 
|  | 3491 |  | 
|  | 3492 | switch (p) { | 
|  | 3493 | case XML_PARSER_LOADDTD: | 
|  | 3494 | if ((ctxt->loadsubset != 0) || (ctxt->validate != 0)) | 
|  | 3495 | return(1); | 
|  | 3496 | return(0); | 
|  | 3497 | case XML_PARSER_DEFAULTATTRS: | 
|  | 3498 | if (ctxt->loadsubset & XML_COMPLETE_ATTRS) | 
|  | 3499 | return(1); | 
|  | 3500 | return(0); | 
|  | 3501 | case XML_PARSER_VALIDATE: | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 3502 | return(reader->validate); | 
| Daniel Veillard | e18fc18 | 2002-12-28 22:56:33 +0000 | [diff] [blame] | 3503 | case XML_PARSER_SUBST_ENTITIES: | 
|  | 3504 | return(ctxt->replaceEntities); | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 3505 | } | 
|  | 3506 | return(-1); | 
|  | 3507 | } | 
|  | 3508 |  | 
| Daniel Veillard | e18fc18 | 2002-12-28 22:56:33 +0000 | [diff] [blame] | 3509 | /** | 
|  | 3510 | * xmlTextReaderCurrentNode: | 
|  | 3511 | * @reader:  the xmlTextReaderPtr used | 
|  | 3512 | * | 
|  | 3513 | * Hacking interface allowing to get the xmlNodePtr correponding to the | 
|  | 3514 | * current node being accessed by the xmlTextReader. This is dangerous | 
|  | 3515 | * because the underlying node may be destroyed on the next Reads. | 
|  | 3516 | * | 
|  | 3517 | * Returns the xmlNodePtr or NULL in case of error. | 
|  | 3518 | */ | 
|  | 3519 | xmlNodePtr | 
|  | 3520 | xmlTextReaderCurrentNode(xmlTextReaderPtr reader) { | 
|  | 3521 | if (reader == NULL) | 
|  | 3522 | return(NULL); | 
|  | 3523 |  | 
|  | 3524 | if (reader->curnode != NULL) | 
|  | 3525 | return(reader->curnode); | 
|  | 3526 | return(reader->node); | 
|  | 3527 | } | 
|  | 3528 |  | 
|  | 3529 | /** | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 3530 | * xmlTextReaderPreserve: | 
|  | 3531 | * @reader:  the xmlTextReaderPtr used | 
|  | 3532 | * | 
|  | 3533 | * | 
|  | 3534 | * current node being accessed by the xmlTextReader. This is dangerous | 
|  | 3535 | * because the underlying node may be destroyed on the next Reads. | 
|  | 3536 | * | 
|  | 3537 | * Returns the xmlNodePtr or NULL in case of error. | 
|  | 3538 | */ | 
|  | 3539 | xmlNodePtr | 
|  | 3540 | xmlTextReaderPreserve(xmlTextReaderPtr reader) { | 
|  | 3541 | xmlNodePtr cur, parent; | 
|  | 3542 |  | 
|  | 3543 | if (reader == NULL) | 
|  | 3544 | return(NULL); | 
|  | 3545 |  | 
|  | 3546 | if (reader->curnode != NULL) | 
|  | 3547 | cur = reader->curnode; | 
|  | 3548 | else | 
|  | 3549 | cur = reader->node; | 
|  | 3550 | if (cur == NULL) | 
|  | 3551 | return(NULL); | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 3552 |  | 
|  | 3553 | if (cur->type != XML_DOCUMENT_NODE) { | 
|  | 3554 | cur->extra |= NODE_IS_PRESERVED; | 
|  | 3555 | cur->extra |= NODE_IS_SPRESERVED; | 
|  | 3556 | } | 
|  | 3557 | reader->preserves++; | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 3558 |  | 
|  | 3559 | parent = cur->parent;; | 
|  | 3560 | while (parent != NULL) { | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 3561 | if (parent->type == XML_ELEMENT_NODE) | 
|  | 3562 | parent->extra |= NODE_IS_PRESERVED; | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 3563 | parent = parent->parent; | 
|  | 3564 | } | 
|  | 3565 | return(cur); | 
|  | 3566 | } | 
|  | 3567 |  | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 3568 | #ifdef LIBXML_PATTERN_ENABLED | 
|  | 3569 | /** | 
|  | 3570 | * xmlTextReaderPreservePattern: | 
|  | 3571 | * @reader:  the xmlTextReaderPtr used | 
|  | 3572 | * @pattern:  an XPath subset pattern | 
| Daniel Veillard | ffa7b7e | 2003-12-05 16:10:21 +0000 | [diff] [blame] | 3573 | * @namespaces: the prefix definitions, array of [URI, prefix] or NULL | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 3574 | * | 
|  | 3575 | * This tells the XML Reader to preserve all nodes matched by the | 
|  | 3576 | * pattern. The caller must also use xmlTextReaderCurrentDoc() to | 
|  | 3577 | * keep an handle on the resulting document once parsing has finished | 
|  | 3578 | * | 
|  | 3579 | * Returns a positive number in case of success and -1 in case of error | 
|  | 3580 | */ | 
|  | 3581 | int | 
| Daniel Veillard | ffa7b7e | 2003-12-05 16:10:21 +0000 | [diff] [blame] | 3582 | xmlTextReaderPreservePattern(xmlTextReaderPtr reader, const xmlChar *pattern, | 
|  | 3583 | const xmlChar **namespaces) | 
|  | 3584 | { | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 3585 | xmlPatternPtr comp; | 
|  | 3586 |  | 
|  | 3587 | if ((reader == NULL) || (pattern == NULL)) | 
|  | 3588 | return(-1); | 
|  | 3589 |  | 
| Daniel Veillard | ffa7b7e | 2003-12-05 16:10:21 +0000 | [diff] [blame] | 3590 | comp = xmlPatterncompile(pattern, reader->dict, 0, namespaces); | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 3591 | if (comp == NULL) | 
|  | 3592 | return(-1); | 
|  | 3593 |  | 
|  | 3594 | if (reader->patternMax <= 0) { | 
|  | 3595 | reader->patternMax = 4; | 
|  | 3596 | reader->patternTab = (xmlPatternPtr *) xmlMalloc(reader->patternMax * | 
|  | 3597 | sizeof(reader->patternTab[0])); | 
|  | 3598 | if (reader->patternTab == NULL) { | 
|  | 3599 | xmlGenericError(xmlGenericErrorContext, "xmlMalloc failed !\n"); | 
|  | 3600 | return (-1); | 
|  | 3601 | } | 
|  | 3602 | } | 
|  | 3603 | if (reader->patternNr >= reader->patternMax) { | 
|  | 3604 | xmlPatternPtr *tmp; | 
|  | 3605 | reader->patternMax *= 2; | 
|  | 3606 | tmp = (xmlPatternPtr *) xmlRealloc(reader->patternTab, | 
|  | 3607 | reader->patternMax * | 
|  | 3608 | sizeof(reader->patternTab[0])); | 
|  | 3609 | if (tmp == NULL) { | 
|  | 3610 | xmlGenericError(xmlGenericErrorContext, "xmlRealloc failed !\n"); | 
|  | 3611 | reader->patternMax /= 2; | 
|  | 3612 | return (-1); | 
|  | 3613 | } | 
|  | 3614 | reader->patternTab = tmp; | 
|  | 3615 | } | 
|  | 3616 | reader->patternTab[reader->patternNr] = comp; | 
|  | 3617 | return(reader->patternNr++); | 
|  | 3618 | } | 
|  | 3619 | #endif | 
|  | 3620 |  | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 3621 | /** | 
| Daniel Veillard | e18fc18 | 2002-12-28 22:56:33 +0000 | [diff] [blame] | 3622 | * xmlTextReaderCurrentDoc: | 
|  | 3623 | * @reader:  the xmlTextReaderPtr used | 
|  | 3624 | * | 
|  | 3625 | * Hacking interface allowing to get the xmlDocPtr correponding to the | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 3626 | * current document being accessed by the xmlTextReader. | 
|  | 3627 | * NOTE: as a result of this call, the reader will not destroy the | 
|  | 3628 | *       associated XML document and calling xmlFreeDoc() on the result | 
|  | 3629 | *       is needed once the reader parsing has finished. | 
| Daniel Veillard | e18fc18 | 2002-12-28 22:56:33 +0000 | [diff] [blame] | 3630 | * | 
|  | 3631 | * Returns the xmlDocPtr or NULL in case of error. | 
|  | 3632 | */ | 
|  | 3633 | xmlDocPtr | 
|  | 3634 | xmlTextReaderCurrentDoc(xmlTextReaderPtr reader) { | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 3635 | if (reader == NULL) | 
|  | 3636 | return(NULL); | 
|  | 3637 | if (reader->doc != NULL) | 
|  | 3638 | return(reader->doc); | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 3639 | if ((reader == NULL) || (reader->ctxt == NULL) || | 
|  | 3640 | (reader->ctxt->myDoc == NULL)) | 
| Daniel Veillard | e18fc18 | 2002-12-28 22:56:33 +0000 | [diff] [blame] | 3641 | return(NULL); | 
|  | 3642 |  | 
| Daniel Veillard | 9ee35f3 | 2003-09-28 00:19:54 +0000 | [diff] [blame] | 3643 | reader->preserve = 1; | 
|  | 3644 | if ((reader->ctxt->myDoc->dict != NULL) && | 
|  | 3645 | (reader->ctxt->myDoc->dict == reader->ctxt->dict)) | 
|  | 3646 | xmlDictReference(reader->ctxt->dict); | 
| Daniel Veillard | e18fc18 | 2002-12-28 22:56:33 +0000 | [diff] [blame] | 3647 | return(reader->ctxt->myDoc); | 
|  | 3648 | } | 
|  | 3649 |  | 
| Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 3650 | #ifdef LIBXML_SCHEMAS_ENABLED | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 3651 | /** | 
| Daniel Veillard | 33300b4 | 2003-04-17 09:09:19 +0000 | [diff] [blame] | 3652 | * xmlTextReaderRelaxNGSetSchema: | 
|  | 3653 | * @reader:  the xmlTextReaderPtr used | 
|  | 3654 | * @schema:  a precompiled RelaxNG schema | 
|  | 3655 | * | 
|  | 3656 | * Use RelaxNG to validate the document as it is processed. | 
|  | 3657 | * Activation is only possible before the first Read(). | 
|  | 3658 | * if @schema is NULL, then RelaxNG validation is desactivated. | 
|  | 3659 | @ The @schema should not be freed until the reader is deallocated | 
|  | 3660 | * or its use has been deactivated. | 
|  | 3661 | * | 
|  | 3662 | * Returns 0 in case the RelaxNG validation could be (des)activated and | 
|  | 3663 | *         -1 in case of error. | 
|  | 3664 | */ | 
|  | 3665 | int | 
|  | 3666 | xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, xmlRelaxNGPtr schema) { | 
|  | 3667 | if (schema == NULL) { | 
|  | 3668 | if (reader->rngSchemas != NULL) { | 
|  | 3669 | xmlRelaxNGFree(reader->rngSchemas); | 
|  | 3670 | reader->rngSchemas = NULL; | 
|  | 3671 | } | 
|  | 3672 | if (reader->rngValidCtxt != NULL) { | 
|  | 3673 | xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); | 
|  | 3674 | reader->rngValidCtxt = NULL; | 
|  | 3675 | } | 
|  | 3676 | return(0); | 
|  | 3677 | } | 
|  | 3678 | if (reader->mode != XML_TEXTREADER_MODE_INITIAL) | 
|  | 3679 | return(-1); | 
|  | 3680 | if (reader->rngSchemas != NULL) { | 
|  | 3681 | xmlRelaxNGFree(reader->rngSchemas); | 
|  | 3682 | reader->rngSchemas = NULL; | 
|  | 3683 | } | 
|  | 3684 | if (reader->rngValidCtxt != NULL) { | 
|  | 3685 | xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); | 
|  | 3686 | reader->rngValidCtxt = NULL; | 
|  | 3687 | } | 
|  | 3688 | reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(schema); | 
|  | 3689 | if (reader->rngValidCtxt == NULL) | 
|  | 3690 | return(-1); | 
|  | 3691 | if (reader->errorFunc != NULL) { | 
|  | 3692 | xmlRelaxNGSetValidErrors(reader->rngValidCtxt, | 
|  | 3693 | (xmlRelaxNGValidityErrorFunc)reader->errorFunc, | 
|  | 3694 | (xmlRelaxNGValidityWarningFunc) reader->errorFunc, | 
|  | 3695 | reader->errorFuncArg); | 
|  | 3696 | } | 
|  | 3697 | reader->rngValidErrors = 0; | 
|  | 3698 | reader->rngFullNode = NULL; | 
|  | 3699 | reader->validate = XML_TEXTREADER_VALIDATE_RNG; | 
|  | 3700 | return(0); | 
|  | 3701 | } | 
|  | 3702 |  | 
|  | 3703 | /** | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 3704 | * xmlTextReaderRelaxNGValidate: | 
|  | 3705 | * @reader:  the xmlTextReaderPtr used | 
|  | 3706 | * @rng:  the path to a RelaxNG schema or NULL | 
|  | 3707 | * | 
|  | 3708 | * Use RelaxNG to validate the document as it is processed. | 
|  | 3709 | * Activation is only possible before the first Read(). | 
|  | 3710 | * if @rng is NULL, then RelaxNG validation is desactivated. | 
|  | 3711 | * | 
|  | 3712 | * Returns 0 in case the RelaxNG validation could be (des)activated and | 
|  | 3713 | *         -1 in case of error. | 
|  | 3714 | */ | 
|  | 3715 | int | 
|  | 3716 | xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng) { | 
|  | 3717 | xmlRelaxNGParserCtxtPtr ctxt; | 
|  | 3718 |  | 
|  | 3719 | if (reader == NULL) | 
|  | 3720 | return(-1); | 
|  | 3721 |  | 
|  | 3722 | if (rng == NULL) { | 
|  | 3723 | if (reader->rngSchemas != NULL) { | 
|  | 3724 | xmlRelaxNGFree(reader->rngSchemas); | 
|  | 3725 | reader->rngSchemas = NULL; | 
|  | 3726 | } | 
|  | 3727 | if (reader->rngValidCtxt != NULL) { | 
|  | 3728 | xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); | 
|  | 3729 | reader->rngValidCtxt = NULL; | 
|  | 3730 | } | 
|  | 3731 | return(0); | 
|  | 3732 | } | 
|  | 3733 | if (reader->mode != XML_TEXTREADER_MODE_INITIAL) | 
|  | 3734 | return(-1); | 
| Daniel Veillard | 33300b4 | 2003-04-17 09:09:19 +0000 | [diff] [blame] | 3735 | if (reader->rngSchemas != NULL) { | 
|  | 3736 | xmlRelaxNGFree(reader->rngSchemas); | 
|  | 3737 | reader->rngSchemas = NULL; | 
|  | 3738 | } | 
|  | 3739 | if (reader->rngValidCtxt != NULL) { | 
|  | 3740 | xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); | 
|  | 3741 | reader->rngValidCtxt = NULL; | 
|  | 3742 | } | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 3743 | ctxt = xmlRelaxNGNewParserCtxt(rng); | 
|  | 3744 | if (reader->errorFunc != NULL) { | 
|  | 3745 | xmlRelaxNGSetParserErrors(ctxt, | 
|  | 3746 | (xmlRelaxNGValidityErrorFunc) reader->errorFunc, | 
|  | 3747 | (xmlRelaxNGValidityWarningFunc) reader->errorFunc, | 
|  | 3748 | reader->errorFuncArg); | 
|  | 3749 | } | 
|  | 3750 | reader->rngSchemas = xmlRelaxNGParse(ctxt); | 
|  | 3751 | xmlRelaxNGFreeParserCtxt(ctxt); | 
|  | 3752 | if (reader->rngSchemas == NULL) | 
|  | 3753 | return(-1); | 
|  | 3754 | reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(reader->rngSchemas); | 
|  | 3755 | if (reader->rngValidCtxt == NULL) | 
|  | 3756 | return(-1); | 
|  | 3757 | if (reader->errorFunc != NULL) { | 
|  | 3758 | xmlRelaxNGSetValidErrors(reader->rngValidCtxt, | 
|  | 3759 | (xmlRelaxNGValidityErrorFunc)reader->errorFunc, | 
|  | 3760 | (xmlRelaxNGValidityWarningFunc) reader->errorFunc, | 
|  | 3761 | reader->errorFuncArg); | 
|  | 3762 | } | 
|  | 3763 | reader->rngValidErrors = 0; | 
|  | 3764 | reader->rngFullNode = NULL; | 
|  | 3765 | reader->validate = XML_TEXTREADER_VALIDATE_RNG; | 
|  | 3766 | return(0); | 
|  | 3767 | } | 
| Daniel Veillard | 37fc84d | 2003-05-09 19:38:15 +0000 | [diff] [blame] | 3768 | #endif | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 3769 |  | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 3770 | /************************************************************************ | 
|  | 3771 | *									* | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3772 | *			Error Handling Extensions                       * | 
|  | 3773 | *									* | 
|  | 3774 | ************************************************************************/ | 
|  | 3775 |  | 
|  | 3776 | /* helper to build a xmlMalloc'ed string from a format and va_list */ | 
|  | 3777 | static char * | 
|  | 3778 | xmlTextReaderBuildMessage(const char *msg, va_list ap) { | 
|  | 3779 | int size; | 
|  | 3780 | int chars; | 
|  | 3781 | char *larger; | 
|  | 3782 | char *str; | 
|  | 3783 |  | 
| Daniel Veillard | 3c908dc | 2003-04-19 00:07:51 +0000 | [diff] [blame] | 3784 | str = (char *) xmlMallocAtomic(150); | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3785 | if (str == NULL) { | 
|  | 3786 | xmlGenericError(xmlGenericErrorContext, "xmlMalloc failed !\n"); | 
|  | 3787 | return NULL; | 
|  | 3788 | } | 
|  | 3789 |  | 
|  | 3790 | size = 150; | 
|  | 3791 |  | 
|  | 3792 | while (1) { | 
|  | 3793 | chars = vsnprintf(str, size, msg, ap); | 
|  | 3794 | if ((chars > -1) && (chars < size)) | 
|  | 3795 | break; | 
|  | 3796 | if (chars > -1) | 
|  | 3797 | size += chars + 1; | 
|  | 3798 | else | 
|  | 3799 | size += 100; | 
|  | 3800 | if ((larger = (char *) xmlRealloc(str, size)) == NULL) { | 
|  | 3801 | xmlGenericError(xmlGenericErrorContext, "xmlRealloc failed !\n"); | 
|  | 3802 | xmlFree(str); | 
|  | 3803 | return NULL; | 
|  | 3804 | } | 
|  | 3805 | str = larger; | 
|  | 3806 | } | 
|  | 3807 |  | 
|  | 3808 | return str; | 
|  | 3809 | } | 
|  | 3810 |  | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3811 | /** | 
| Daniel Veillard | 540a31a | 2003-01-21 11:21:07 +0000 | [diff] [blame] | 3812 | * xmlTextReaderLocatorLineNumber: | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3813 | * @locator: the xmlTextReaderLocatorPtr used | 
|  | 3814 | * | 
|  | 3815 | * Obtain the line number for the given locator. | 
|  | 3816 | * | 
|  | 3817 | * Returns the line number or -1 in case of error. | 
|  | 3818 | */ | 
|  | 3819 | int | 
|  | 3820 | xmlTextReaderLocatorLineNumber(xmlTextReaderLocatorPtr locator) { | 
|  | 3821 | /* we know that locator is a xmlParserCtxtPtr */ | 
|  | 3822 | xmlParserCtxtPtr ctx = (xmlParserCtxtPtr)locator; | 
|  | 3823 | int ret = -1; | 
|  | 3824 |  | 
|  | 3825 | if (ctx->node != NULL) { | 
|  | 3826 | ret = xmlGetLineNo(ctx->node); | 
|  | 3827 | } | 
|  | 3828 | else { | 
|  | 3829 | /* inspired from error.c */ | 
|  | 3830 | xmlParserInputPtr input; | 
|  | 3831 | input = ctx->input; | 
|  | 3832 | if ((input->filename == NULL) && (ctx->inputNr > 1)) | 
|  | 3833 | input = ctx->inputTab[ctx->inputNr - 2]; | 
|  | 3834 | if (input != NULL) { | 
|  | 3835 | ret = input->line; | 
|  | 3836 | } | 
|  | 3837 | else { | 
|  | 3838 | ret = -1; | 
|  | 3839 | } | 
|  | 3840 | } | 
|  | 3841 |  | 
|  | 3842 | return ret; | 
|  | 3843 | } | 
|  | 3844 |  | 
|  | 3845 | /** | 
| Daniel Veillard | 540a31a | 2003-01-21 11:21:07 +0000 | [diff] [blame] | 3846 | * xmlTextReaderLocatorBaseURI: | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3847 | * @locator: the xmlTextReaderLocatorPtr used | 
|  | 3848 | * | 
|  | 3849 | * Obtain the base URI for the given locator. | 
|  | 3850 | * | 
|  | 3851 | * Returns the base URI or NULL in case of error. | 
|  | 3852 | */ | 
|  | 3853 | xmlChar * | 
|  | 3854 | xmlTextReaderLocatorBaseURI(xmlTextReaderLocatorPtr locator) { | 
|  | 3855 | /* we know that locator is a xmlParserCtxtPtr */ | 
|  | 3856 | xmlParserCtxtPtr ctx = (xmlParserCtxtPtr)locator; | 
|  | 3857 | xmlChar *ret = NULL; | 
|  | 3858 |  | 
|  | 3859 | if (ctx->node != NULL) { | 
|  | 3860 | ret = xmlNodeGetBase(NULL,ctx->node); | 
|  | 3861 | } | 
|  | 3862 | else { | 
|  | 3863 | /* inspired from error.c */ | 
|  | 3864 | xmlParserInputPtr input; | 
|  | 3865 | input = ctx->input; | 
|  | 3866 | if ((input->filename == NULL) && (ctx->inputNr > 1)) | 
|  | 3867 | input = ctx->inputTab[ctx->inputNr - 2]; | 
|  | 3868 | if (input != NULL) { | 
| Daniel Veillard | 580ced8 | 2003-03-21 21:22:48 +0000 | [diff] [blame] | 3869 | ret = xmlStrdup(BAD_CAST input->filename); | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3870 | } | 
|  | 3871 | else { | 
|  | 3872 | ret = NULL; | 
|  | 3873 | } | 
|  | 3874 | } | 
|  | 3875 |  | 
|  | 3876 | return ret; | 
|  | 3877 | } | 
|  | 3878 |  | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3879 | static void | 
| William M. Brack | 899e64a | 2003-09-26 18:03:42 +0000 | [diff] [blame] | 3880 | xmlTextReaderGenericError(void *ctxt, xmlParserSeverities severity, char *str) { | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3881 | xmlParserCtxtPtr ctx = (xmlParserCtxtPtr)ctxt; | 
|  | 3882 | xmlTextReaderPtr reader = (xmlTextReaderPtr)ctx->_private; | 
|  | 3883 |  | 
|  | 3884 | if (str != NULL) { | 
|  | 3885 | reader->errorFunc(reader->errorFuncArg, | 
|  | 3886 | str, | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3887 | severity, | 
|  | 3888 | (xmlTextReaderLocatorPtr)ctx); | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3889 | xmlFree(str); | 
|  | 3890 | } | 
|  | 3891 | } | 
|  | 3892 |  | 
|  | 3893 | static void | 
|  | 3894 | xmlTextReaderError(void *ctxt, const char *msg, ...) { | 
|  | 3895 | va_list ap; | 
|  | 3896 |  | 
|  | 3897 | va_start(ap,msg); | 
|  | 3898 | xmlTextReaderGenericError(ctxt, | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3899 | XML_PARSER_SEVERITY_ERROR, | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3900 | xmlTextReaderBuildMessage(msg,ap)); | 
|  | 3901 | va_end(ap); | 
|  | 3902 |  | 
|  | 3903 | } | 
|  | 3904 |  | 
|  | 3905 | static void | 
|  | 3906 | xmlTextReaderWarning(void *ctxt, const char *msg, ...) { | 
|  | 3907 | va_list ap; | 
|  | 3908 |  | 
|  | 3909 | va_start(ap,msg); | 
|  | 3910 | xmlTextReaderGenericError(ctxt, | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3911 | XML_PARSER_SEVERITY_WARNING, | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3912 | xmlTextReaderBuildMessage(msg,ap)); | 
|  | 3913 | va_end(ap); | 
|  | 3914 | } | 
|  | 3915 |  | 
|  | 3916 | static void | 
|  | 3917 | xmlTextReaderValidityError(void *ctxt, const char *msg, ...) { | 
|  | 3918 | va_list ap; | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3919 | int len = xmlStrlen((const xmlChar *) msg); | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3920 |  | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3921 | if ((len > 1) && (msg[len - 2] != ':')) { | 
|  | 3922 | /* | 
|  | 3923 | * some callbacks only report locator information: | 
|  | 3924 | * skip them (mimicking behaviour in error.c) | 
|  | 3925 | */ | 
|  | 3926 | va_start(ap,msg); | 
|  | 3927 | xmlTextReaderGenericError(ctxt, | 
|  | 3928 | XML_PARSER_SEVERITY_VALIDITY_ERROR, | 
|  | 3929 | xmlTextReaderBuildMessage(msg,ap)); | 
|  | 3930 | va_end(ap); | 
|  | 3931 | } | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3932 | } | 
|  | 3933 |  | 
|  | 3934 | static void | 
|  | 3935 | xmlTextReaderValidityWarning(void *ctxt, const char *msg, ...) { | 
|  | 3936 | va_list ap; | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3937 | int len = xmlStrlen((const xmlChar *) msg); | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3938 |  | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3939 | if ((len != 0) && (msg[len - 1] != ':')) { | 
|  | 3940 | /* | 
|  | 3941 | * some callbacks only report locator information: | 
|  | 3942 | * skip them (mimicking behaviour in error.c) | 
|  | 3943 | */ | 
|  | 3944 | va_start(ap,msg); | 
|  | 3945 | xmlTextReaderGenericError(ctxt, | 
|  | 3946 | XML_PARSER_SEVERITY_VALIDITY_WARNING, | 
|  | 3947 | xmlTextReaderBuildMessage(msg,ap)); | 
|  | 3948 | va_end(ap); | 
|  | 3949 | } | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3950 | } | 
|  | 3951 |  | 
|  | 3952 | /** | 
|  | 3953 | * xmlTextReaderSetErrorHandler: | 
|  | 3954 | * @reader:  the xmlTextReaderPtr used | 
|  | 3955 | * @f:	the callback function to call on error and warnings | 
|  | 3956 | * @arg:    a user argument to pass to the callback function | 
|  | 3957 | * | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3958 | * Register a callback function that will be called on error and warnings. | 
|  | 3959 | * | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3960 | * If @f is NULL, the default error and warning handlers are restored. | 
|  | 3961 | */ | 
|  | 3962 | void | 
|  | 3963 | xmlTextReaderSetErrorHandler(xmlTextReaderPtr reader, | 
|  | 3964 | xmlTextReaderErrorFunc f, | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3965 | void *arg) { | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 3966 | if (f != NULL) { | 
|  | 3967 | reader->ctxt->sax->error = xmlTextReaderError; | 
|  | 3968 | reader->ctxt->vctxt.error = xmlTextReaderValidityError; | 
|  | 3969 | reader->ctxt->sax->warning = xmlTextReaderWarning; | 
|  | 3970 | reader->ctxt->vctxt.warning = xmlTextReaderValidityWarning; | 
|  | 3971 | reader->errorFunc = f; | 
|  | 3972 | reader->errorFuncArg = arg; | 
|  | 3973 | } | 
|  | 3974 | else { | 
|  | 3975 | /* restore defaults */ | 
|  | 3976 | reader->ctxt->sax->error = xmlParserError; | 
|  | 3977 | reader->ctxt->vctxt.error = xmlParserValidityError; | 
|  | 3978 | reader->ctxt->sax->warning = xmlParserWarning; | 
|  | 3979 | reader->ctxt->vctxt.warning = xmlParserValidityWarning; | 
|  | 3980 | reader->errorFunc = NULL; | 
|  | 3981 | reader->errorFuncArg = NULL; | 
|  | 3982 | } | 
|  | 3983 | } | 
|  | 3984 |  | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 3985 | /** | 
| Daniel Veillard | f6bad79 | 2003-04-11 19:38:54 +0000 | [diff] [blame] | 3986 | * xmlTextReaderIsValid: | 
|  | 3987 | * @reader:  the xmlTextReaderPtr used | 
|  | 3988 | * | 
|  | 3989 | * Retrieve the validity status from the parser context | 
|  | 3990 | * | 
|  | 3991 | * Returns the flag value 1 if valid, 0 if no, and -1 in case of error | 
|  | 3992 | */ | 
|  | 3993 | int | 
|  | 3994 | xmlTextReaderIsValid(xmlTextReaderPtr reader) { | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 3995 | if (reader == NULL) return(-1); | 
|  | 3996 | #ifdef LIBXML_SCHEMAS_ENABLED | 
|  | 3997 | if (reader->validate == XML_TEXTREADER_VALIDATE_RNG) | 
|  | 3998 | return(reader->rngValidErrors == 0); | 
|  | 3999 | #endif | 
| Daniel Veillard | 16ed597 | 2003-11-20 18:22:31 +0000 | [diff] [blame] | 4000 | if ((reader->ctxt != NULL) && (reader->ctxt->validate == 1)) | 
| Daniel Veillard | f4e5576 | 2003-04-15 23:32:22 +0000 | [diff] [blame] | 4001 | return(reader->ctxt->valid); | 
|  | 4002 | return(0); | 
| Daniel Veillard | f6bad79 | 2003-04-11 19:38:54 +0000 | [diff] [blame] | 4003 | } | 
|  | 4004 |  | 
|  | 4005 | /** | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 4006 | * xmlTextReaderGetErrorHandler: | 
|  | 4007 | * @reader:  the xmlTextReaderPtr used | 
|  | 4008 | * @f:	the callback function or NULL is no callback has been registered | 
|  | 4009 | * @arg:    a user argument | 
|  | 4010 | * | 
|  | 4011 | * Retrieve the error callback function and user argument. | 
|  | 4012 | */ | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 4013 | void | 
|  | 4014 | xmlTextReaderGetErrorHandler(xmlTextReaderPtr reader, | 
|  | 4015 | xmlTextReaderErrorFunc *f, | 
| Daniel Veillard | 417be3a | 2003-01-20 21:26:34 +0000 | [diff] [blame] | 4016 | void **arg) { | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 4017 | *f = reader->errorFunc; | 
|  | 4018 | *arg = reader->errorFuncArg; | 
|  | 4019 | } | 
|  | 4020 |  | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4021 |  | 
|  | 4022 | /************************************************************************ | 
|  | 4023 | *									* | 
|  | 4024 | *	New set (2.6.0) of simpler and more flexible APIs		* | 
|  | 4025 | *									* | 
|  | 4026 | ************************************************************************/ | 
|  | 4027 |  | 
|  | 4028 | /** | 
|  | 4029 | * xmlTextReaderSetup: | 
|  | 4030 | * @reader:  an XML reader | 
|  | 4031 | * @URL:  the base URL to use for the document | 
|  | 4032 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4033 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4034 | * @reuse:  keep the context for reuse | 
|  | 4035 | * | 
|  | 4036 | * Setup an XML reader with new options | 
|  | 4037 | * | 
|  | 4038 | * Returns 0 in case of success and -1 in case of error. | 
|  | 4039 | */ | 
|  | 4040 | static int | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4041 | xmlTextReaderSetup(xmlTextReaderPtr reader, | 
|  | 4042 | xmlParserInputBufferPtr input, const char *URL, | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4043 | const char *encoding, int options) | 
|  | 4044 | { | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4045 | if (reader == NULL) | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4046 | return (-1); | 
|  | 4047 |  | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4048 | reader->doc = NULL; | 
|  | 4049 | reader->entNr = 0; | 
| Daniel Veillard | e74d2e1 | 2003-12-09 11:35:37 +0000 | [diff] [blame] | 4050 | reader->parserFlags = options; | 
| Daniel Veillard | c36965d | 2003-12-02 10:28:48 +0000 | [diff] [blame] | 4051 | reader->validate = XML_TEXTREADER_NOT_VALIDATE; | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4052 | if ((input != NULL) && (reader->input != NULL) && | 
|  | 4053 | (reader->allocs & XML_TEXTREADER_INPUT)) { | 
|  | 4054 | xmlFreeParserInputBuffer(reader->input); | 
|  | 4055 | reader->input = NULL; | 
|  | 4056 | reader->allocs -= XML_TEXTREADER_INPUT; | 
|  | 4057 | } | 
|  | 4058 | if (input != NULL) { | 
|  | 4059 | reader->input = input; | 
|  | 4060 | reader->allocs |= XML_TEXTREADER_INPUT; | 
|  | 4061 | } | 
|  | 4062 | if (reader->buffer == NULL) | 
|  | 4063 | reader->buffer = xmlBufferCreateSize(100); | 
|  | 4064 | if (reader->buffer == NULL) { | 
|  | 4065 | xmlGenericError(xmlGenericErrorContext, | 
|  | 4066 | "xmlTextReaderSetup : malloc failed\n"); | 
|  | 4067 | return (-1); | 
|  | 4068 | } | 
|  | 4069 | if (reader->sax == NULL) | 
|  | 4070 | reader->sax = (xmlSAXHandler *) xmlMalloc(sizeof(xmlSAXHandler)); | 
|  | 4071 | if (reader->sax == NULL) { | 
|  | 4072 | xmlGenericError(xmlGenericErrorContext, | 
|  | 4073 | "xmlTextReaderSetup : malloc failed\n"); | 
|  | 4074 | return (-1); | 
|  | 4075 | } | 
|  | 4076 | xmlSAXVersion(reader->sax, 2); | 
|  | 4077 | reader->startElement = reader->sax->startElement; | 
|  | 4078 | reader->sax->startElement = xmlTextReaderStartElement; | 
|  | 4079 | reader->endElement = reader->sax->endElement; | 
|  | 4080 | reader->sax->endElement = xmlTextReaderEndElement; | 
|  | 4081 | #ifdef LIBXML_SAX1_ENABLED | 
|  | 4082 | if (reader->sax->initialized == XML_SAX2_MAGIC) { | 
|  | 4083 | #endif /* LIBXML_SAX1_ENABLED */ | 
|  | 4084 | reader->startElementNs = reader->sax->startElementNs; | 
|  | 4085 | reader->sax->startElementNs = xmlTextReaderStartElementNs; | 
|  | 4086 | reader->endElementNs = reader->sax->endElementNs; | 
|  | 4087 | reader->sax->endElementNs = xmlTextReaderEndElementNs; | 
|  | 4088 | #ifdef LIBXML_SAX1_ENABLED | 
|  | 4089 | } else { | 
|  | 4090 | reader->startElementNs = NULL; | 
|  | 4091 | reader->endElementNs = NULL; | 
|  | 4092 | } | 
|  | 4093 | #endif /* LIBXML_SAX1_ENABLED */ | 
|  | 4094 | reader->characters = reader->sax->characters; | 
|  | 4095 | reader->sax->characters = xmlTextReaderCharacters; | 
|  | 4096 | reader->sax->ignorableWhitespace = xmlTextReaderCharacters; | 
|  | 4097 | reader->cdataBlock = reader->sax->cdataBlock; | 
|  | 4098 | reader->sax->cdataBlock = xmlTextReaderCDataBlock; | 
|  | 4099 |  | 
|  | 4100 | reader->mode = XML_TEXTREADER_MODE_INITIAL; | 
|  | 4101 | reader->node = NULL; | 
|  | 4102 | reader->curnode = NULL; | 
|  | 4103 | if (input != NULL) { | 
|  | 4104 | if (reader->input->buffer->use < 4) { | 
|  | 4105 | xmlParserInputBufferRead(input, 4); | 
|  | 4106 | } | 
|  | 4107 | if (reader->ctxt == NULL) { | 
|  | 4108 | if (reader->input->buffer->use >= 4) { | 
|  | 4109 | reader->ctxt = xmlCreatePushParserCtxt(reader->sax, NULL, | 
|  | 4110 | (const char *) reader->input->buffer->content, 4, URL); | 
|  | 4111 | reader->base = 0; | 
|  | 4112 | reader->cur = 4; | 
|  | 4113 | } else { | 
|  | 4114 | reader->ctxt = | 
|  | 4115 | xmlCreatePushParserCtxt(reader->sax, NULL, NULL, 0, URL); | 
|  | 4116 | reader->base = 0; | 
|  | 4117 | reader->cur = 0; | 
|  | 4118 | } | 
|  | 4119 | } else { | 
|  | 4120 | xmlParserInputPtr inputStream; | 
|  | 4121 | xmlParserInputBufferPtr buf; | 
|  | 4122 | xmlCharEncoding enc = XML_CHAR_ENCODING_NONE; | 
|  | 4123 |  | 
|  | 4124 | if (reader->ctxt->myDoc != NULL) | 
|  | 4125 | xmlDictReference(reader->ctxt->myDoc->dict); | 
|  | 4126 | xmlCtxtReset(reader->ctxt); | 
|  | 4127 | buf = xmlAllocParserInputBuffer(enc); | 
|  | 4128 | if (buf == NULL) return(-1); | 
|  | 4129 | inputStream = xmlNewInputStream(reader->ctxt); | 
|  | 4130 | if (inputStream == NULL) { | 
|  | 4131 | xmlFreeParserInputBuffer(buf); | 
|  | 4132 | return(-1); | 
|  | 4133 | } | 
|  | 4134 |  | 
|  | 4135 | if (URL == NULL) | 
|  | 4136 | inputStream->filename = NULL; | 
|  | 4137 | else | 
|  | 4138 | inputStream->filename = (char *) | 
|  | 4139 | xmlCanonicPath((const xmlChar *) URL); | 
|  | 4140 | inputStream->buf = buf; | 
|  | 4141 | inputStream->base = inputStream->buf->buffer->content; | 
|  | 4142 | inputStream->cur = inputStream->buf->buffer->content; | 
|  | 4143 | inputStream->end = | 
|  | 4144 | &inputStream->buf->buffer->content[inputStream->buf->buffer->use]; | 
|  | 4145 |  | 
|  | 4146 | inputPush(reader->ctxt, inputStream); | 
|  | 4147 | reader->cur = 0; | 
|  | 4148 | } | 
|  | 4149 | if (reader->ctxt == NULL) { | 
|  | 4150 | xmlGenericError(xmlGenericErrorContext, | 
|  | 4151 | "xmlTextReaderSetup : malloc failed\n"); | 
|  | 4152 | return (-1); | 
|  | 4153 | } | 
|  | 4154 | } | 
|  | 4155 | if (reader->dict != NULL) { | 
|  | 4156 | if (reader->ctxt->dict != NULL) { | 
|  | 4157 | if (reader->dict != reader->ctxt->dict) { | 
|  | 4158 | xmlDictFree(reader->dict); | 
|  | 4159 | reader->dict = reader->ctxt->dict; | 
|  | 4160 | } | 
|  | 4161 | } else { | 
|  | 4162 | reader->ctxt->dict = reader->dict; | 
|  | 4163 | } | 
|  | 4164 | } else { | 
|  | 4165 | if (reader->ctxt->dict == NULL) | 
|  | 4166 | reader->ctxt->dict = xmlDictCreate(); | 
|  | 4167 | reader->dict = reader->ctxt->dict; | 
|  | 4168 | } | 
|  | 4169 | reader->ctxt->_private = reader; | 
|  | 4170 | reader->ctxt->linenumbers = 1; | 
|  | 4171 | reader->ctxt->dictNames = 1; | 
|  | 4172 | /* | 
|  | 4173 | * use the parser dictionnary to allocate all elements and attributes names | 
|  | 4174 | */ | 
|  | 4175 | reader->ctxt->docdict = 1; | 
|  | 4176 |  | 
| Daniel Veillard | 7899c5c | 2003-11-03 12:31:38 +0000 | [diff] [blame] | 4177 | #ifdef LIBXML_XINCLUDE_ENABLED | 
|  | 4178 | if (reader->xincctxt != NULL) { | 
|  | 4179 | xmlXIncludeFreeContext(reader->xincctxt); | 
|  | 4180 | reader->xincctxt = NULL; | 
|  | 4181 | } | 
|  | 4182 | if (options & XML_PARSE_XINCLUDE) { | 
|  | 4183 | reader->xinclude = 1; | 
|  | 4184 | reader->xinclude_name = xmlDictLookup(reader->dict, XINCLUDE_NODE, -1); | 
|  | 4185 | options -= XML_PARSE_XINCLUDE; | 
|  | 4186 | } else | 
|  | 4187 | reader->xinclude = 0; | 
|  | 4188 | reader->in_xinclude = 0; | 
|  | 4189 | #endif | 
| Daniel Veillard | 1e90661 | 2003-12-05 14:57:46 +0000 | [diff] [blame] | 4190 | #ifdef LIBXML_PATTERN_ENABLED | 
|  | 4191 | if (reader->patternTab == NULL) { | 
|  | 4192 | reader->patternNr = 0; | 
|  | 4193 | reader->patternMax = 0; | 
|  | 4194 | } | 
|  | 4195 | while (reader->patternNr > 0) { | 
|  | 4196 | reader->patternNr--; | 
|  | 4197 | if (reader->patternTab[reader->patternNr] != NULL) { | 
|  | 4198 | xmlFreePattern(reader->patternTab[reader->patternNr]); | 
|  | 4199 | reader->patternTab[reader->patternNr] = NULL; | 
|  | 4200 | } | 
|  | 4201 | } | 
|  | 4202 | #endif | 
|  | 4203 |  | 
| Daniel Veillard | c36965d | 2003-12-02 10:28:48 +0000 | [diff] [blame] | 4204 | if (options & XML_PARSE_DTDVALID) | 
|  | 4205 | reader->validate = XML_TEXTREADER_VALIDATE_DTD; | 
|  | 4206 |  | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4207 | xmlCtxtUseOptions(reader->ctxt, options); | 
|  | 4208 | if (encoding != NULL) { | 
|  | 4209 | xmlCharEncodingHandlerPtr hdlr; | 
|  | 4210 |  | 
|  | 4211 | hdlr = xmlFindCharEncodingHandler(encoding); | 
|  | 4212 | if (hdlr != NULL) | 
|  | 4213 | xmlSwitchToEncoding(reader->ctxt, hdlr); | 
|  | 4214 | } | 
|  | 4215 | if ((URL != NULL) && (reader->ctxt->input != NULL) && | 
|  | 4216 | (reader->ctxt->input->filename == NULL)) | 
|  | 4217 | reader->ctxt->input->filename = (char *) | 
|  | 4218 | xmlStrdup((const xmlChar *) URL); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4219 |  | 
|  | 4220 | reader->doc = NULL; | 
|  | 4221 |  | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4222 | return (0); | 
|  | 4223 | } | 
|  | 4224 |  | 
|  | 4225 | /** | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4226 | * xmlReaderWalker: | 
|  | 4227 | * @doc:  a preparsed document | 
|  | 4228 | * | 
|  | 4229 | * Create an xmltextReader for a preparsed document. | 
|  | 4230 | * | 
|  | 4231 | * Returns the new reader or NULL in case of error. | 
|  | 4232 | */ | 
|  | 4233 | xmlTextReaderPtr | 
|  | 4234 | xmlReaderWalker(xmlDocPtr doc) | 
|  | 4235 | { | 
|  | 4236 | xmlTextReaderPtr ret; | 
|  | 4237 |  | 
|  | 4238 | if (doc == NULL) | 
|  | 4239 | return(NULL); | 
|  | 4240 |  | 
|  | 4241 | ret = xmlMalloc(sizeof(xmlTextReader)); | 
|  | 4242 | if (ret == NULL) { | 
|  | 4243 | xmlGenericError(xmlGenericErrorContext, | 
|  | 4244 | "xmlNewTextReader : malloc failed\n"); | 
|  | 4245 | return(NULL); | 
|  | 4246 | } | 
|  | 4247 | memset(ret, 0, sizeof(xmlTextReader)); | 
|  | 4248 | ret->entNr = 0; | 
|  | 4249 | ret->input = NULL; | 
|  | 4250 | ret->mode = XML_TEXTREADER_MODE_INITIAL; | 
|  | 4251 | ret->node = NULL; | 
|  | 4252 | ret->curnode = NULL; | 
|  | 4253 | ret->base = 0; | 
|  | 4254 | ret->cur = 0; | 
|  | 4255 | ret->allocs = XML_TEXTREADER_CTXT; | 
|  | 4256 | ret->doc = doc; | 
|  | 4257 | ret->state = XML_TEXTREADER_START; | 
|  | 4258 | ret->dict = xmlDictCreate(); | 
|  | 4259 | return(ret); | 
|  | 4260 | } | 
|  | 4261 |  | 
|  | 4262 | /** | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4263 | * xmlReaderForDoc: | 
|  | 4264 | * @cur:  a pointer to a zero terminated string | 
|  | 4265 | * @URL:  the base URL to use for the document | 
|  | 4266 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4267 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4268 | * | 
|  | 4269 | * Create an xmltextReader for an XML in-memory document. | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4270 | * The parsing flags @options are a combination of xmlParserOption. | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4271 | * | 
|  | 4272 | * Returns the new reader or NULL in case of error. | 
|  | 4273 | */ | 
|  | 4274 | xmlTextReaderPtr | 
|  | 4275 | xmlReaderForDoc(const xmlChar * cur, const char *URL, const char *encoding, | 
|  | 4276 | int options) | 
|  | 4277 | { | 
|  | 4278 | int len; | 
|  | 4279 |  | 
|  | 4280 | if (cur == NULL) | 
|  | 4281 | return (NULL); | 
|  | 4282 | len = xmlStrlen(cur); | 
|  | 4283 |  | 
|  | 4284 | return (xmlReaderForMemory | 
|  | 4285 | ((const char *) cur, len, URL, encoding, options)); | 
|  | 4286 | } | 
|  | 4287 |  | 
|  | 4288 | /** | 
|  | 4289 | * xmlReaderForFile: | 
|  | 4290 | * @filename:  a file or URL | 
|  | 4291 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4292 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4293 | * | 
|  | 4294 | * parse an XML file from the filesystem or the network. | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4295 | * The parsing flags @options are a combination of xmlParserOption. | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4296 | * | 
|  | 4297 | * Returns the new reader or NULL in case of error. | 
|  | 4298 | */ | 
|  | 4299 | xmlTextReaderPtr | 
|  | 4300 | xmlReaderForFile(const char *filename, const char *encoding, int options) | 
|  | 4301 | { | 
|  | 4302 | xmlTextReaderPtr reader; | 
|  | 4303 |  | 
|  | 4304 | reader = xmlNewTextReaderFilename(filename); | 
|  | 4305 | if (reader == NULL) | 
|  | 4306 | return (NULL); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4307 | xmlTextReaderSetup(reader, NULL, NULL, encoding, options); | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4308 | return (reader); | 
|  | 4309 | } | 
|  | 4310 |  | 
|  | 4311 | /** | 
|  | 4312 | * xmlReaderForMemory: | 
|  | 4313 | * @buffer:  a pointer to a char array | 
|  | 4314 | * @size:  the size of the array | 
|  | 4315 | * @URL:  the base URL to use for the document | 
|  | 4316 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4317 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4318 | * | 
|  | 4319 | * Create an xmltextReader for an XML in-memory document. | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4320 | * The parsing flags @options are a combination of xmlParserOption. | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4321 | * | 
|  | 4322 | * Returns the new reader or NULL in case of error. | 
|  | 4323 | */ | 
|  | 4324 | xmlTextReaderPtr | 
|  | 4325 | xmlReaderForMemory(const char *buffer, int size, const char *URL, | 
|  | 4326 | const char *encoding, int options) | 
|  | 4327 | { | 
|  | 4328 | xmlTextReaderPtr reader; | 
|  | 4329 | xmlParserInputBufferPtr buf; | 
|  | 4330 |  | 
|  | 4331 | buf = | 
|  | 4332 | xmlParserInputBufferCreateMem(buffer, size, | 
|  | 4333 | XML_CHAR_ENCODING_NONE); | 
|  | 4334 | if (buf == NULL) { | 
|  | 4335 | return (NULL); | 
|  | 4336 | } | 
|  | 4337 | reader = xmlNewTextReader(buf, URL); | 
|  | 4338 | if (reader == NULL) { | 
|  | 4339 | xmlFreeParserInputBuffer(buf); | 
|  | 4340 | return (NULL); | 
|  | 4341 | } | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4342 | reader->allocs |= XML_TEXTREADER_INPUT; | 
|  | 4343 | xmlTextReaderSetup(reader, NULL, URL, encoding, options); | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4344 | return (reader); | 
|  | 4345 | } | 
|  | 4346 |  | 
|  | 4347 | /** | 
|  | 4348 | * xmlReaderForFd: | 
|  | 4349 | * @fd:  an open file descriptor | 
|  | 4350 | * @URL:  the base URL to use for the document | 
|  | 4351 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4352 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4353 | * | 
|  | 4354 | * Create an xmltextReader for an XML from a file descriptor. | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4355 | * The parsing flags @options are a combination of xmlParserOption. | 
| Daniel Veillard | 4bc5f43 | 2003-12-22 18:13:12 +0000 | [diff] [blame] | 4356 | * NOTE that the file descriptor will not be closed when the | 
|  | 4357 | *      reader is closed or reset. | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4358 | * | 
|  | 4359 | * Returns the new reader or NULL in case of error. | 
|  | 4360 | */ | 
|  | 4361 | xmlTextReaderPtr | 
|  | 4362 | xmlReaderForFd(int fd, const char *URL, const char *encoding, int options) | 
|  | 4363 | { | 
|  | 4364 | xmlTextReaderPtr reader; | 
|  | 4365 | xmlParserInputBufferPtr input; | 
|  | 4366 |  | 
|  | 4367 | if (fd < 0) | 
|  | 4368 | return (NULL); | 
|  | 4369 |  | 
|  | 4370 | input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE); | 
|  | 4371 | if (input == NULL) | 
|  | 4372 | return (NULL); | 
| Daniel Veillard | 4bc5f43 | 2003-12-22 18:13:12 +0000 | [diff] [blame] | 4373 | input->closecallback = NULL; | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4374 | reader = xmlNewTextReader(input, URL); | 
|  | 4375 | if (reader == NULL) { | 
|  | 4376 | xmlFreeParserInputBuffer(input); | 
|  | 4377 | return (NULL); | 
|  | 4378 | } | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4379 | reader->allocs |= XML_TEXTREADER_INPUT; | 
|  | 4380 | xmlTextReaderSetup(reader, NULL, URL, encoding, options); | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4381 | return (reader); | 
|  | 4382 | } | 
|  | 4383 |  | 
|  | 4384 | /** | 
|  | 4385 | * xmlReaderForIO: | 
|  | 4386 | * @ioread:  an I/O read function | 
|  | 4387 | * @ioclose:  an I/O close function | 
|  | 4388 | * @ioctx:  an I/O handler | 
|  | 4389 | * @URL:  the base URL to use for the document | 
|  | 4390 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4391 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4392 | * | 
|  | 4393 | * Create an xmltextReader for an XML document from I/O functions and source. | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4394 | * The parsing flags @options are a combination of xmlParserOption. | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4395 | * | 
|  | 4396 | * Returns the new reader or NULL in case of error. | 
|  | 4397 | */ | 
|  | 4398 | xmlTextReaderPtr | 
|  | 4399 | xmlReaderForIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, | 
|  | 4400 | void *ioctx, const char *URL, const char *encoding, | 
|  | 4401 | int options) | 
|  | 4402 | { | 
|  | 4403 | xmlTextReaderPtr reader; | 
|  | 4404 | xmlParserInputBufferPtr input; | 
|  | 4405 |  | 
|  | 4406 | if (ioread == NULL) | 
|  | 4407 | return (NULL); | 
|  | 4408 |  | 
|  | 4409 | input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, | 
|  | 4410 | XML_CHAR_ENCODING_NONE); | 
|  | 4411 | if (input == NULL) | 
|  | 4412 | return (NULL); | 
|  | 4413 | reader = xmlNewTextReader(input, URL); | 
|  | 4414 | if (reader == NULL) { | 
|  | 4415 | xmlFreeParserInputBuffer(input); | 
|  | 4416 | return (NULL); | 
|  | 4417 | } | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4418 | reader->allocs |= XML_TEXTREADER_INPUT; | 
|  | 4419 | xmlTextReaderSetup(reader, NULL, URL, encoding, options); | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4420 | return (reader); | 
|  | 4421 | } | 
|  | 4422 |  | 
|  | 4423 | /** | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4424 | * xmlReaderNewWalker: | 
|  | 4425 | * @reader:  an XML reader | 
|  | 4426 | * @doc:  a preparsed document | 
|  | 4427 | * | 
|  | 4428 | * Setup an xmltextReader to parse a preparsed XML document. | 
|  | 4429 | * This reuses the existing @reader xmlTextReader. | 
|  | 4430 | * | 
|  | 4431 | * Returns 0 in case of success and -1 in case of error | 
|  | 4432 | */ | 
|  | 4433 | int | 
|  | 4434 | xmlReaderNewWalker(xmlTextReaderPtr reader, xmlDocPtr doc) | 
|  | 4435 | { | 
|  | 4436 | if (doc == NULL) | 
|  | 4437 | return (-1); | 
|  | 4438 | if (reader == NULL) | 
|  | 4439 | return (-1); | 
|  | 4440 |  | 
|  | 4441 | if (reader->ctxt != NULL) { | 
|  | 4442 | xmlCtxtReset(reader->ctxt); | 
|  | 4443 | } | 
|  | 4444 |  | 
|  | 4445 | reader->entNr = 0; | 
|  | 4446 | reader->input = NULL; | 
|  | 4447 | reader->mode = XML_TEXTREADER_MODE_INITIAL; | 
|  | 4448 | reader->node = NULL; | 
|  | 4449 | reader->curnode = NULL; | 
|  | 4450 | reader->base = 0; | 
|  | 4451 | reader->cur = 0; | 
|  | 4452 | reader->allocs = XML_TEXTREADER_CTXT; | 
|  | 4453 | reader->doc = doc; | 
|  | 4454 | reader->state = XML_TEXTREADER_START; | 
|  | 4455 | if (reader->dict == NULL) { | 
|  | 4456 | if ((reader->ctxt != NULL) && (reader->ctxt->dict != NULL)) | 
|  | 4457 | reader->dict = reader->ctxt->dict; | 
|  | 4458 | else | 
|  | 4459 | reader->dict = xmlDictCreate(); | 
|  | 4460 | } | 
|  | 4461 | return(0); | 
|  | 4462 | } | 
|  | 4463 |  | 
|  | 4464 | /** | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4465 | * xmlReaderNewDoc: | 
|  | 4466 | * @reader:  an XML reader | 
|  | 4467 | * @cur:  a pointer to a zero terminated string | 
|  | 4468 | * @URL:  the base URL to use for the document | 
|  | 4469 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4470 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4471 | * | 
|  | 4472 | * Setup an xmltextReader to parse an XML in-memory document. | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4473 | * The parsing flags @options are a combination of xmlParserOption. | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4474 | * This reuses the existing @reader xmlTextReader. | 
|  | 4475 | * | 
|  | 4476 | * Returns 0 in case of success and -1 in case of error | 
|  | 4477 | */ | 
|  | 4478 | int | 
|  | 4479 | xmlReaderNewDoc(xmlTextReaderPtr reader, const xmlChar * cur, | 
|  | 4480 | const char *URL, const char *encoding, int options) | 
|  | 4481 | { | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4482 |  | 
|  | 4483 | int len; | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4484 |  | 
|  | 4485 | if (cur == NULL) | 
|  | 4486 | return (-1); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4487 | if (reader == NULL) | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4488 | return (-1); | 
|  | 4489 |  | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4490 | len = xmlStrlen(cur); | 
|  | 4491 | return (xmlReaderNewMemory(reader, (const char *)cur, len, | 
|  | 4492 | URL, encoding, options)); | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4493 | } | 
|  | 4494 |  | 
|  | 4495 | /** | 
|  | 4496 | * xmlReaderNewFile: | 
|  | 4497 | * @reader:  an XML reader | 
|  | 4498 | * @filename:  a file or URL | 
|  | 4499 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4500 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4501 | * | 
|  | 4502 | * parse an XML file from the filesystem or the network. | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4503 | * The parsing flags @options are a combination of xmlParserOption. | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4504 | * This reuses the existing @reader xmlTextReader. | 
|  | 4505 | * | 
|  | 4506 | * Returns 0 in case of success and -1 in case of error | 
|  | 4507 | */ | 
|  | 4508 | int | 
|  | 4509 | xmlReaderNewFile(xmlTextReaderPtr reader, const char *filename, | 
|  | 4510 | const char *encoding, int options) | 
|  | 4511 | { | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4512 | xmlParserInputBufferPtr input; | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4513 |  | 
|  | 4514 | if (filename == NULL) | 
|  | 4515 | return (-1); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4516 | if (reader == NULL) | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4517 | return (-1); | 
|  | 4518 |  | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4519 | input = | 
|  | 4520 | xmlParserInputBufferCreateFilename(filename, | 
|  | 4521 | XML_CHAR_ENCODING_NONE); | 
|  | 4522 | if (input == NULL) | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4523 | return (-1); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4524 | return (xmlTextReaderSetup(reader, input, filename, encoding, options)); | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4525 | } | 
|  | 4526 |  | 
|  | 4527 | /** | 
|  | 4528 | * xmlReaderNewMemory: | 
|  | 4529 | * @reader:  an XML reader | 
|  | 4530 | * @buffer:  a pointer to a char array | 
|  | 4531 | * @size:  the size of the array | 
|  | 4532 | * @URL:  the base URL to use for the document | 
|  | 4533 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4534 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4535 | * | 
|  | 4536 | * Setup an xmltextReader to parse an XML in-memory document. | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4537 | * The parsing flags @options are a combination of xmlParserOption. | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4538 | * This reuses the existing @reader xmlTextReader. | 
|  | 4539 | * | 
|  | 4540 | * Returns 0 in case of success and -1 in case of error | 
|  | 4541 | */ | 
|  | 4542 | int | 
|  | 4543 | xmlReaderNewMemory(xmlTextReaderPtr reader, const char *buffer, int size, | 
|  | 4544 | const char *URL, const char *encoding, int options) | 
|  | 4545 | { | 
|  | 4546 | xmlParserInputBufferPtr input; | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4547 |  | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4548 | if (reader == NULL) | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4549 | return (-1); | 
|  | 4550 | if (buffer == NULL) | 
|  | 4551 | return (-1); | 
|  | 4552 |  | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4553 | input = xmlParserInputBufferCreateMem(buffer, size, | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4554 | XML_CHAR_ENCODING_NONE); | 
|  | 4555 | if (input == NULL) { | 
|  | 4556 | return (-1); | 
|  | 4557 | } | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4558 | return (xmlTextReaderSetup(reader, input, URL, encoding, options)); | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4559 | } | 
|  | 4560 |  | 
|  | 4561 | /** | 
|  | 4562 | * xmlReaderNewFd: | 
|  | 4563 | * @reader:  an XML reader | 
|  | 4564 | * @fd:  an open file descriptor | 
|  | 4565 | * @URL:  the base URL to use for the document | 
|  | 4566 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4567 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4568 | * | 
|  | 4569 | * Setup an xmltextReader to parse an XML from a file descriptor. | 
| Daniel Veillard | 4bc5f43 | 2003-12-22 18:13:12 +0000 | [diff] [blame] | 4570 | * NOTE that the file descriptor will not be closed when the | 
|  | 4571 | *      reader is closed or reset. | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4572 | * The parsing flags @options are a combination of xmlParserOption. | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4573 | * This reuses the existing @reader xmlTextReader. | 
|  | 4574 | * | 
|  | 4575 | * Returns 0 in case of success and -1 in case of error | 
|  | 4576 | */ | 
|  | 4577 | int | 
|  | 4578 | xmlReaderNewFd(xmlTextReaderPtr reader, int fd, | 
|  | 4579 | const char *URL, const char *encoding, int options) | 
|  | 4580 | { | 
|  | 4581 | xmlParserInputBufferPtr input; | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4582 |  | 
|  | 4583 | if (fd < 0) | 
|  | 4584 | return (-1); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4585 | if (reader == NULL) | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4586 | return (-1); | 
|  | 4587 |  | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4588 | input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE); | 
|  | 4589 | if (input == NULL) | 
|  | 4590 | return (-1); | 
| Daniel Veillard | 4bc5f43 | 2003-12-22 18:13:12 +0000 | [diff] [blame] | 4591 | input->closecallback = NULL; | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4592 | return (xmlTextReaderSetup(reader, input, URL, encoding, options)); | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4593 | } | 
|  | 4594 |  | 
|  | 4595 | /** | 
|  | 4596 | * xmlReaderNewIO: | 
|  | 4597 | * @reader:  an XML reader | 
|  | 4598 | * @ioread:  an I/O read function | 
|  | 4599 | * @ioclose:  an I/O close function | 
|  | 4600 | * @ioctx:  an I/O handler | 
|  | 4601 | * @URL:  the base URL to use for the document | 
|  | 4602 | * @encoding:  the document encoding, or NULL | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4603 | * @options:  a combination of xmlParserOption | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4604 | * | 
|  | 4605 | * Setup an xmltextReader to parse an XML document from I/O functions | 
|  | 4606 | * and source. | 
| Daniel Veillard | 87ab1c1 | 2003-12-21 13:01:56 +0000 | [diff] [blame] | 4607 | * The parsing flags @options are a combination of xmlParserOption. | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4608 | * This reuses the existing @reader xmlTextReader. | 
|  | 4609 | * | 
|  | 4610 | * Returns 0 in case of success and -1 in case of error | 
|  | 4611 | */ | 
|  | 4612 | int | 
|  | 4613 | xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCallback ioread, | 
|  | 4614 | xmlInputCloseCallback ioclose, void *ioctx, | 
|  | 4615 | const char *URL, const char *encoding, int options) | 
|  | 4616 | { | 
|  | 4617 | xmlParserInputBufferPtr input; | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4618 |  | 
|  | 4619 | if (ioread == NULL) | 
|  | 4620 | return (-1); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4621 | if (reader == NULL) | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4622 | return (-1); | 
|  | 4623 |  | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4624 | input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, | 
|  | 4625 | XML_CHAR_ENCODING_NONE); | 
|  | 4626 | if (input == NULL) | 
|  | 4627 | return (-1); | 
| Daniel Veillard | 198c1bf | 2003-10-20 17:07:41 +0000 | [diff] [blame] | 4628 | return (xmlTextReaderSetup(reader, input, URL, encoding, options)); | 
| Daniel Veillard | fc8dc35 | 2003-10-18 09:07:46 +0000 | [diff] [blame] | 4629 | } | 
| Daniel Veillard | 26f7026 | 2003-01-16 22:45:08 +0000 | [diff] [blame] | 4630 | /************************************************************************ | 
|  | 4631 | *									* | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 4632 | *			Utilities					* | 
|  | 4633 | *									* | 
|  | 4634 | ************************************************************************/ | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 4635 | #ifdef NOT_USED_YET | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 4636 | /** | 
|  | 4637 | * xmlBase64Decode: | 
|  | 4638 | * @in:  the input buffer | 
|  | 4639 | * @inlen:  the size of the input (in), the size read from it (out) | 
|  | 4640 | * @to:  the output buffer | 
|  | 4641 | * @tolen:  the size of the output (in), the size written to (out) | 
|  | 4642 | * | 
|  | 4643 | * Base64 decoder, reads from @in and save in @to | 
| Daniel Veillard | d431074 | 2003-02-18 21:12:46 +0000 | [diff] [blame] | 4644 | * TODO: tell jody when this is actually exported | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 4645 | * | 
|  | 4646 | * Returns 0 if all the input was consumer, 1 if the Base64 end was reached, | 
|  | 4647 | *         2 if there wasn't enough space on the output or -1 in case of error. | 
|  | 4648 | */ | 
|  | 4649 | static int | 
|  | 4650 | xmlBase64Decode(const unsigned char *in, unsigned long *inlen, | 
|  | 4651 | unsigned char *to, unsigned long *tolen) { | 
|  | 4652 | unsigned long incur;		/* current index in in[] */ | 
|  | 4653 | unsigned long inblk;		/* last block index in in[] */ | 
|  | 4654 | unsigned long outcur;		/* current index in out[] */ | 
|  | 4655 | unsigned long inmax;		/* size of in[] */ | 
|  | 4656 | unsigned long outmax;		/* size of out[] */ | 
|  | 4657 | unsigned char cur;			/* the current value read from in[] */ | 
| Daniel Veillard | c127adc | 2003-07-23 15:07:08 +0000 | [diff] [blame] | 4658 | unsigned char intmp[4], outtmp[4];	/* temporary buffers for the convert */ | 
| Daniel Veillard | beb70bd | 2002-12-18 14:53:54 +0000 | [diff] [blame] | 4659 | int nbintmp;			/* number of byte in intmp[] */ | 
|  | 4660 | int is_ignore;			/* cur should be ignored */ | 
|  | 4661 | int is_end = 0;			/* the end of the base64 was found */ | 
|  | 4662 | int retval = 1; | 
|  | 4663 | int i; | 
|  | 4664 |  | 
|  | 4665 | if ((in == NULL) || (inlen == NULL) || (to == NULL) || (tolen == NULL)) | 
|  | 4666 | return(-1); | 
|  | 4667 |  | 
|  | 4668 | incur = 0; | 
|  | 4669 | inblk = 0; | 
|  | 4670 | outcur = 0; | 
|  | 4671 | inmax = *inlen; | 
|  | 4672 | outmax = *tolen; | 
|  | 4673 | nbintmp = 0; | 
|  | 4674 |  | 
|  | 4675 | while (1) { | 
|  | 4676 | if (incur >= inmax) | 
|  | 4677 | break; | 
|  | 4678 | cur = in[incur++]; | 
|  | 4679 | is_ignore = 0; | 
|  | 4680 | if ((cur >= 'A') && (cur <= 'Z')) | 
|  | 4681 | cur = cur - 'A'; | 
|  | 4682 | else if ((cur >= 'a') && (cur <= 'z')) | 
|  | 4683 | cur = cur - 'a' + 26; | 
|  | 4684 | else if ((cur >= '0') && (cur <= '9')) | 
|  | 4685 | cur = cur - '0' + 52; | 
|  | 4686 | else if (cur == '+') | 
|  | 4687 | cur = 62; | 
|  | 4688 | else if (cur == '/') | 
|  | 4689 | cur = 63; | 
|  | 4690 | else if (cur == '.') | 
|  | 4691 | cur = 0; | 
|  | 4692 | else if (cur == '=') /*no op , end of the base64 stream */ | 
|  | 4693 | is_end = 1; | 
|  | 4694 | else { | 
|  | 4695 | is_ignore = 1; | 
|  | 4696 | if (nbintmp == 0) | 
|  | 4697 | inblk = incur; | 
|  | 4698 | } | 
|  | 4699 |  | 
|  | 4700 | if (!is_ignore) { | 
|  | 4701 | int nbouttmp = 3; | 
|  | 4702 | int is_break = 0; | 
|  | 4703 |  | 
|  | 4704 | if (is_end) { | 
|  | 4705 | if (nbintmp == 0) | 
|  | 4706 | break; | 
|  | 4707 | if ((nbintmp == 1) || (nbintmp == 2)) | 
|  | 4708 | nbouttmp = 1; | 
|  | 4709 | else | 
|  | 4710 | nbouttmp = 2; | 
|  | 4711 | nbintmp = 3; | 
|  | 4712 | is_break = 1; | 
|  | 4713 | } | 
|  | 4714 | intmp[nbintmp++] = cur; | 
|  | 4715 | /* | 
|  | 4716 | * if intmp is full, push the 4byte sequence as a 3 byte | 
|  | 4717 | * sequence out | 
|  | 4718 | */ | 
|  | 4719 | if (nbintmp == 4) { | 
|  | 4720 | nbintmp = 0; | 
|  | 4721 | outtmp[0] = (intmp[0] << 2) | ((intmp[1] & 0x30) >> 4); | 
|  | 4722 | outtmp[1] = | 
|  | 4723 | ((intmp[1] & 0x0F) << 4) | ((intmp[2] & 0x3C) >> 2); | 
|  | 4724 | outtmp[2] = ((intmp[2] & 0x03) << 6) | (intmp[3] & 0x3F); | 
|  | 4725 | if (outcur + 3 >= outmax) { | 
|  | 4726 | retval = 2; | 
|  | 4727 | break; | 
|  | 4728 | } | 
|  | 4729 |  | 
|  | 4730 | for (i = 0; i < nbouttmp; i++) | 
|  | 4731 | to[outcur++] = outtmp[i]; | 
|  | 4732 | inblk = incur; | 
|  | 4733 | } | 
|  | 4734 |  | 
|  | 4735 | if (is_break) { | 
|  | 4736 | retval = 0; | 
|  | 4737 | break; | 
|  | 4738 | } | 
|  | 4739 | } | 
|  | 4740 | } | 
|  | 4741 |  | 
|  | 4742 | *tolen = outcur; | 
|  | 4743 | *inlen = inblk; | 
|  | 4744 | return (retval); | 
|  | 4745 | } | 
|  | 4746 |  | 
|  | 4747 | /* | 
|  | 4748 | * Test routine for the xmlBase64Decode function | 
|  | 4749 | */ | 
|  | 4750 | #if 0 | 
|  | 4751 | int main(int argc, char **argv) { | 
|  | 4752 | char *input = "  VW4 gcGV0        \n      aXQgdGVzdCAuCg== "; | 
|  | 4753 | char output[100]; | 
|  | 4754 | char output2[100]; | 
|  | 4755 | char output3[100]; | 
|  | 4756 | unsigned long inlen = strlen(input); | 
|  | 4757 | unsigned long outlen = 100; | 
|  | 4758 | int ret; | 
|  | 4759 | unsigned long cons, tmp, tmp2, prod; | 
|  | 4760 |  | 
|  | 4761 | /* | 
|  | 4762 | * Direct | 
|  | 4763 | */ | 
|  | 4764 | ret = xmlBase64Decode(input, &inlen, output, &outlen); | 
|  | 4765 |  | 
|  | 4766 | output[outlen] = 0; | 
|  | 4767 | printf("ret: %d, inlen: %ld , outlen: %ld, output: '%s'\n", ret, inlen, outlen, output); | 
|  | 4768 |  | 
|  | 4769 | /* | 
|  | 4770 | * output chunking | 
|  | 4771 | */ | 
|  | 4772 | cons = 0; | 
|  | 4773 | prod = 0; | 
|  | 4774 | while (cons < inlen) { | 
|  | 4775 | tmp = 5; | 
|  | 4776 | tmp2 = inlen - cons; | 
|  | 4777 |  | 
|  | 4778 | printf("%ld %ld\n", cons, prod); | 
|  | 4779 | ret = xmlBase64Decode(&input[cons], &tmp2, &output2[prod], &tmp); | 
|  | 4780 | cons += tmp2; | 
|  | 4781 | prod += tmp; | 
|  | 4782 | printf("%ld %ld\n", cons, prod); | 
|  | 4783 | } | 
|  | 4784 | output2[outlen] = 0; | 
|  | 4785 | printf("ret: %d, cons: %ld , prod: %ld, output: '%s'\n", ret, cons, prod, output2); | 
|  | 4786 |  | 
|  | 4787 | /* | 
|  | 4788 | * input chunking | 
|  | 4789 | */ | 
|  | 4790 | cons = 0; | 
|  | 4791 | prod = 0; | 
|  | 4792 | while (cons < inlen) { | 
|  | 4793 | tmp = 100 - prod; | 
|  | 4794 | tmp2 = inlen - cons; | 
|  | 4795 | if (tmp2 > 5) | 
|  | 4796 | tmp2 = 5; | 
|  | 4797 |  | 
|  | 4798 | printf("%ld %ld\n", cons, prod); | 
|  | 4799 | ret = xmlBase64Decode(&input[cons], &tmp2, &output3[prod], &tmp); | 
|  | 4800 | cons += tmp2; | 
|  | 4801 | prod += tmp; | 
|  | 4802 | printf("%ld %ld\n", cons, prod); | 
|  | 4803 | } | 
|  | 4804 | output3[outlen] = 0; | 
|  | 4805 | printf("ret: %d, cons: %ld , prod: %ld, output: '%s'\n", ret, cons, prod, output3); | 
|  | 4806 | return(0); | 
|  | 4807 |  | 
|  | 4808 | } | 
|  | 4809 | #endif | 
| Daniel Veillard | 9f7eb0b | 2003-09-17 10:26:25 +0000 | [diff] [blame] | 4810 | #endif /* NOT_USED_YET */ | 
| Daniel Veillard | 8127390 | 2003-09-30 00:43:48 +0000 | [diff] [blame] | 4811 | #endif /* LIBXML_READER_ENABLED */ |