version 1.1.1.1, 2012/02/21 23:37:58
|
version 1.1.1.2, 2013/07/22 01:22:22
|
Line 152 struct _xmlTextReader {
|
Line 152 struct _xmlTextReader {
|
/* Handling of RelaxNG validation */ |
/* Handling of RelaxNG validation */ |
xmlRelaxNGPtr rngSchemas; /* The Relax NG schemas */ |
xmlRelaxNGPtr rngSchemas; /* The Relax NG schemas */ |
xmlRelaxNGValidCtxtPtr rngValidCtxt;/* The Relax NG validation context */ |
xmlRelaxNGValidCtxtPtr rngValidCtxt;/* The Relax NG validation context */ |
|
int rngPreserveCtxt; /* 1 if the context was provided by the user */ |
int rngValidErrors;/* The number of errors detected */ |
int rngValidErrors;/* The number of errors detected */ |
xmlNodePtr rngFullNode; /* the node if RNG not progressive */ |
xmlNodePtr rngFullNode; /* the node if RNG not progressive */ |
/* Handling of Schemas validation */ |
/* Handling of Schemas validation */ |
Line 854 xmlTextReaderPushData(xmlTextReaderPtr reader) {
|
Line 855 xmlTextReaderPushData(xmlTextReaderPtr reader) {
|
(const char *) &inbuf->content[reader->cur], |
(const char *) &inbuf->content[reader->cur], |
CHUNK_SIZE, 0); |
CHUNK_SIZE, 0); |
reader->cur += CHUNK_SIZE; |
reader->cur += CHUNK_SIZE; |
if ((val != 0) || (reader->ctxt->wellFormed == 0)) | if (val != 0) |
return(-1); | reader->ctxt->wellFormed = 0; |
| if (reader->ctxt->wellFormed == 0) |
| break; |
} else { |
} else { |
s = inbuf->use - reader->cur; |
s = inbuf->use - reader->cur; |
val = xmlParseChunk(reader->ctxt, |
val = xmlParseChunk(reader->ctxt, |
(const char *) &inbuf->content[reader->cur], |
(const char *) &inbuf->content[reader->cur], |
s, 0); |
s, 0); |
reader->cur += s; |
reader->cur += s; |
if ((val != 0) || (reader->ctxt->wellFormed == 0)) | if (val != 0) |
return(-1); | reader->ctxt->wellFormed = 0; |
break; |
break; |
} |
} |
} |
} |
Line 895 xmlTextReaderPushData(xmlTextReaderPtr reader) {
|
Line 898 xmlTextReaderPushData(xmlTextReaderPtr reader) {
|
s, 1); |
s, 1); |
reader->cur = inbuf->use; |
reader->cur = inbuf->use; |
reader->state = XML_TEXTREADER_DONE; |
reader->state = XML_TEXTREADER_DONE; |
if ((val != 0) || (reader->ctxt->wellFormed == 0)) | if (val != 0) { |
return(-1); | if (reader->ctxt->wellFormed) |
| reader->ctxt->wellFormed = 0; |
| else |
| return(-1); |
| } |
} |
} |
} |
} |
reader->state = oldstate; |
reader->state = oldstate; |
|
if (reader->ctxt->wellFormed == 0) |
|
reader->mode = XML_TEXTREADER_MODE_EOF; |
return(0); |
return(0); |
} |
} |
|
|
Line 1264 xmlTextReaderRead(xmlTextReaderPtr reader) {
|
Line 1273 xmlTextReaderRead(xmlTextReaderPtr reader) {
|
return(xmlTextReaderReadTree(reader)); |
return(xmlTextReaderReadTree(reader)); |
if (reader->ctxt == NULL) |
if (reader->ctxt == NULL) |
return(-1); |
return(-1); |
if (reader->ctxt->wellFormed != 1) |
|
return(-1); |
|
|
|
#ifdef DEBUG_READER |
#ifdef DEBUG_READER |
fprintf(stderr, "\nREAD "); |
fprintf(stderr, "\nREAD "); |
Line 2187 xmlFreeTextReader(xmlTextReaderPtr reader) {
|
Line 2194 xmlFreeTextReader(xmlTextReaderPtr reader) {
|
reader->rngSchemas = NULL; |
reader->rngSchemas = NULL; |
} |
} |
if (reader->rngValidCtxt != NULL) { |
if (reader->rngValidCtxt != NULL) { |
xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); | if (! reader->rngPreserveCtxt) |
| xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); |
reader->rngValidCtxt = NULL; |
reader->rngValidCtxt = NULL; |
} |
} |
if (reader->xsdPlug != NULL) { |
if (reader->xsdPlug != NULL) { |
Line 4095 xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader,
|
Line 4103 xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader,
|
reader->rngSchemas = NULL; |
reader->rngSchemas = NULL; |
} |
} |
if (reader->rngValidCtxt != NULL) { |
if (reader->rngValidCtxt != NULL) { |
xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); | if (! reader->rngPreserveCtxt) |
| xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); |
reader->rngValidCtxt = NULL; |
reader->rngValidCtxt = NULL; |
} |
} |
|
reader->rngPreserveCtxt = 0; |
return(0); |
return(0); |
} |
} |
if (reader->mode != XML_TEXTREADER_MODE_INITIAL) |
if (reader->mode != XML_TEXTREADER_MODE_INITIAL) |
Line 4107 xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader,
|
Line 4117 xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader,
|
reader->rngSchemas = NULL; |
reader->rngSchemas = NULL; |
} |
} |
if (reader->rngValidCtxt != NULL) { |
if (reader->rngValidCtxt != NULL) { |
xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); | if (! reader->rngPreserveCtxt) |
| xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); |
reader->rngValidCtxt = NULL; |
reader->rngValidCtxt = NULL; |
} |
} |
|
reader->rngPreserveCtxt = 0; |
reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(schema); |
reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(schema); |
if (reader->rngValidCtxt == NULL) |
if (reader->rngValidCtxt == NULL) |
return(-1); |
return(-1); |
Line 4214 xmlTextReaderSetSchema(xmlTextReaderPtr reader, xmlSch
|
Line 4226 xmlTextReaderSetSchema(xmlTextReaderPtr reader, xmlSch
|
} |
} |
|
|
/** |
/** |
* xmlTextReaderRelaxNGValidate: | * xmlTextReaderRelaxNGValidateInternal: |
* @reader: the xmlTextReaderPtr used |
* @reader: the xmlTextReaderPtr used |
* @rng: the path to a RelaxNG schema or NULL |
* @rng: the path to a RelaxNG schema or NULL |
|
* @ctxt: the RelaxNG schema validation context or NULL |
|
* @options: options (not yet used) |
* |
* |
* Use RelaxNG to validate the document as it is processed. |
* Use RelaxNG to validate the document as it is processed. |
* Activation is only possible before the first Read(). |
* Activation is only possible before the first Read(). |
* if @rng is NULL, then RelaxNG validation is deactivated. | * If both @rng and @ctxt are NULL, then RelaxNG validation is deactivated. |
* |
* |
* Returns 0 in case the RelaxNG validation could be (de)activated and |
* Returns 0 in case the RelaxNG validation could be (de)activated and |
* -1 in case of error. | * -1 in case of error. |
*/ |
*/ |
int | static int |
xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng) { | xmlTextReaderRelaxNGValidateInternal(xmlTextReaderPtr reader, |
xmlRelaxNGParserCtxtPtr ctxt; | const char *rng, |
| xmlRelaxNGValidCtxtPtr ctxt, |
| int options ATTRIBUTE_UNUSED) |
| { |
if (reader == NULL) |
if (reader == NULL) |
return(-1); | return(-1); |
|
|
if (rng == NULL) { | if ((rng != NULL) && (ctxt != NULL)) |
if (reader->rngValidCtxt != NULL) { | return (-1); |
| |
| if (((rng != NULL) || (ctxt != NULL)) && |
| ((reader->mode != XML_TEXTREADER_MODE_INITIAL) || |
| (reader->ctxt == NULL))) |
| return(-1); |
| |
| /* Cleanup previous validation stuff. */ |
| if (reader->rngValidCtxt != NULL) { |
| if ( !reader->rngPreserveCtxt) |
xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); |
xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); |
reader->rngValidCtxt = NULL; | reader->rngValidCtxt = NULL; |
} | |
if (reader->rngSchemas != NULL) { | |
xmlRelaxNGFree(reader->rngSchemas); | |
reader->rngSchemas = NULL; | |
} | |
return(0); | |
} |
} |
if (reader->mode != XML_TEXTREADER_MODE_INITIAL) | reader->rngPreserveCtxt = 0; |
return(-1); | |
if (reader->rngSchemas != NULL) { |
if (reader->rngSchemas != NULL) { |
xmlRelaxNGFree(reader->rngSchemas); |
xmlRelaxNGFree(reader->rngSchemas); |
reader->rngSchemas = NULL; |
reader->rngSchemas = NULL; |
} |
} |
if (reader->rngValidCtxt != NULL) { | |
xmlRelaxNGFreeValidCtxt(reader->rngValidCtxt); | if ((rng == NULL) && (ctxt == NULL)) { |
reader->rngValidCtxt = NULL; | /* We just want to deactivate the validation, so get out. */ |
| return(0); |
} |
} |
ctxt = xmlRelaxNGNewParserCtxt(rng); | |
if (reader->errorFunc != NULL) { | |
xmlRelaxNGSetParserErrors(ctxt, | if (rng != NULL) { |
xmlTextReaderValidityErrorRelay, | xmlRelaxNGParserCtxtPtr pctxt; |
xmlTextReaderValidityWarningRelay, | /* Parse the schema and create validation environment. */ |
reader); | |
| pctxt = xmlRelaxNGNewParserCtxt(rng); |
| if (reader->errorFunc != NULL) { |
| xmlRelaxNGSetParserErrors(pctxt, |
| xmlTextReaderValidityErrorRelay, |
| xmlTextReaderValidityWarningRelay, |
| reader); |
| } |
| if (reader->sErrorFunc != NULL) { |
| xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, |
| xmlTextReaderValidityStructuredRelay, |
| reader); |
| } |
| reader->rngSchemas = xmlRelaxNGParse(pctxt); |
| xmlRelaxNGFreeParserCtxt(pctxt); |
| if (reader->rngSchemas == NULL) |
| return(-1); |
| reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(reader->rngSchemas); |
| if (reader->rngValidCtxt == NULL) { |
| xmlRelaxNGFree(reader->rngSchemas); |
| reader->rngSchemas = NULL; |
| return(-1); |
| } |
| } else { |
| /* Use the given validation context. */ |
| reader->rngValidCtxt = ctxt; |
| reader->rngPreserveCtxt = 1; |
} |
} |
if (reader->sErrorFunc != NULL) { | /* |
xmlRelaxNGSetValidStructuredErrors(reader->rngValidCtxt, | * Redirect the validation context's error channels to use |
xmlTextReaderValidityStructuredRelay, | * the reader channels. |
reader); | * TODO: In case the user provides the validation context we |
} | * could make this redirection optional. |
reader->rngSchemas = xmlRelaxNGParse(ctxt); | */ |
xmlRelaxNGFreeParserCtxt(ctxt); | |
if (reader->rngSchemas == NULL) | |
return(-1); | |
reader->rngValidCtxt = xmlRelaxNGNewValidCtxt(reader->rngSchemas); | |
if (reader->rngValidCtxt == NULL) { | |
xmlRelaxNGFree(reader->rngSchemas); | |
reader->rngSchemas = NULL; | |
return(-1); | |
} | |
if (reader->errorFunc != NULL) { |
if (reader->errorFunc != NULL) { |
xmlRelaxNGSetValidErrors(reader->rngValidCtxt, |
xmlRelaxNGSetValidErrors(reader->rngValidCtxt, |
xmlTextReaderValidityErrorRelay, |
xmlTextReaderValidityErrorRelay, |
Line 4447 xmlTextReaderSchemaValidate(xmlTextReaderPtr reader, c
|
Line 4483 xmlTextReaderSchemaValidate(xmlTextReaderPtr reader, c
|
{ |
{ |
return(xmlTextReaderSchemaValidateInternal(reader, xsd, NULL, 0)); |
return(xmlTextReaderSchemaValidateInternal(reader, xsd, NULL, 0)); |
} |
} |
|
|
|
/** |
|
* xmlTextReaderRelaxNGValidateCtxt: |
|
* @reader: the xmlTextReaderPtr used |
|
* @ctxt: the RelaxNG schema validation context or NULL |
|
* @options: options (not used yet) |
|
* |
|
* Use RelaxNG schema context to validate the document as it is processed. |
|
* Activation is only possible before the first Read(). |
|
* If @ctxt is NULL, then RelaxNG schema validation is deactivated. |
|
* |
|
* Returns 0 in case the schemas validation could be (de)activated and |
|
* -1 in case of error. |
|
*/ |
|
int |
|
xmlTextReaderRelaxNGValidateCtxt(xmlTextReaderPtr reader, |
|
xmlRelaxNGValidCtxtPtr ctxt, |
|
int options) |
|
{ |
|
return(xmlTextReaderRelaxNGValidateInternal(reader, NULL, ctxt, options)); |
|
} |
|
|
|
/** |
|
* xmlTextReaderRelaxNGValidate: |
|
* @reader: the xmlTextReaderPtr used |
|
* @rng: the path to a RelaxNG schema or NULL |
|
* |
|
* Use RelaxNG schema to validate the document as it is processed. |
|
* Activation is only possible before the first Read(). |
|
* If @rng is NULL, then RelaxNG schema validation is deactivated. |
|
* |
|
* Returns 0 in case the schemas validation could be (de)activated and |
|
* -1 in case of error. |
|
*/ |
|
int |
|
xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng) |
|
{ |
|
return(xmlTextReaderRelaxNGValidateInternal(reader, rng, NULL, 0)); |
|
} |
|
|
#endif |
#endif |
|
|
/** |
/** |
Line 5331 xmlReaderForIO(xmlInputReadCallback ioread, xmlInputCl
|
Line 5407 xmlReaderForIO(xmlInputReadCallback ioread, xmlInputCl
|
|
|
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, |
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, |
XML_CHAR_ENCODING_NONE); |
XML_CHAR_ENCODING_NONE); |
if (input == NULL) | if (input == NULL) { |
| if (ioclose != NULL) |
| ioclose(ioctx); |
return (NULL); |
return (NULL); |
|
} |
reader = xmlNewTextReader(input, URL); |
reader = xmlNewTextReader(input, URL); |
if (reader == NULL) { |
if (reader == NULL) { |
xmlFreeParserInputBuffer(input); |
xmlFreeParserInputBuffer(input); |
Line 5549 xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCa
|
Line 5628 xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCa
|
|
|
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, |
input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, |
XML_CHAR_ENCODING_NONE); |
XML_CHAR_ENCODING_NONE); |
if (input == NULL) | if (input == NULL) { |
| if (ioclose != NULL) |
| ioclose(ioctx); |
return (-1); |
return (-1); |
|
} |
return (xmlTextReaderSetup(reader, input, URL, encoding, options)); |
return (xmlTextReaderSetup(reader, input, URL, encoding, options)); |
} |
} |
|
|
/************************************************************************ |
/************************************************************************ |
* * |
* * |
* Utilities * |
* Utilities * |