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