Paul Cercueil / libxml2

Dependents:   libiio

Committer:
pcercuei
Date:
Thu Aug 25 10:05:35 2016 +0000
Revision:
0:03b5121a232e
Add basic C files of libxml2 2.9.4

Who changed what in which revision?

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