* xmlSchemaValidateStream: * @ctxt: a schema validation context * @input: the input to use for reading the data * @enc: an optional encoding information * @sax: a SAX handler for the resulting events * @user_data: the context to provide to the SAX handler. * * Validate an input based on a flow of SAX event from the parser * and forward the events to the @sax handler with the provided
| 28746 | * number otherwise and -1 in case of internal or API error. |
| 28747 | */ |
| 28748 | int |
| 28749 | xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt, |
| 28750 | xmlParserInputBufferPtr input, xmlCharEncoding enc, |
| 28751 | xmlSAXHandlerPtr sax, void *user_data) |
| 28752 | { |
| 28753 | xmlParserCtxtPtr pctxt = NULL; |
| 28754 | xmlParserInputPtr inputStream = NULL; |
| 28755 | int ret; |
| 28756 | |
| 28757 | if ((ctxt == NULL) || (input == NULL)) |
| 28758 | return (-1); |
| 28759 | |
| 28760 | /* |
| 28761 | * prepare the parser |
| 28762 | */ |
| 28763 | if (sax != NULL) { |
| 28764 | pctxt = xmlNewSAXParserCtxt(sax, user_data); |
| 28765 | if (pctxt == NULL) |
| 28766 | return (-1); |
| 28767 | } else { |
| 28768 | pctxt = xmlNewParserCtxt(); |
| 28769 | if (pctxt == NULL) |
| 28770 | return (-1); |
| 28771 | /* We really want pctxt->sax to be NULL here. */ |
| 28772 | xmlFree(pctxt->sax); |
| 28773 | pctxt->sax = NULL; |
| 28774 | } |
| 28775 | #if 0 |
| 28776 | if (options) |
| 28777 | xmlCtxtUseOptions(pctxt, options); |
| 28778 | #endif |
| 28779 | |
| 28780 | inputStream = xmlNewIOInputStream(pctxt, input, enc);; |
| 28781 | if (inputStream == NULL) { |
| 28782 | ret = -1; |
| 28783 | goto done; |
| 28784 | } |
| 28785 | inputPush(pctxt, inputStream); |
| 28786 | |
| 28787 | ctxt->enc = enc; |
| 28788 | |
| 28789 | ret = xmlSchemaValidateStreamInternal(ctxt, pctxt); |
| 28790 | |
| 28791 | done: |
| 28792 | /* cleanup */ |
| 28793 | if (pctxt != NULL) { |
| 28794 | xmlFreeParserCtxt(pctxt); |
| 28795 | } |
| 28796 | return (ret); |
| 28797 | } |
| 28798 | |
| 28799 | /** |
| 28800 | * xmlSchemaValidateFile: |
no test coverage detected