* xmlRelaxNGValidateDocument: * @ctxt: a Relax-NG validation context * @doc: the document * * Validate the given document * * Returns 0 if the validation succeeded or an error code. */
| 10513 | * Returns 0 if the validation succeeded or an error code. |
| 10514 | */ |
| 10515 | static int |
| 10516 | xmlRelaxNGValidateDocument(xmlRelaxNGValidCtxtPtr ctxt, xmlDocPtr doc) |
| 10517 | { |
| 10518 | int ret; |
| 10519 | xmlRelaxNGPtr schema; |
| 10520 | xmlRelaxNGGrammarPtr grammar; |
| 10521 | xmlRelaxNGValidStatePtr state; |
| 10522 | xmlNodePtr node; |
| 10523 | |
| 10524 | if ((ctxt == NULL) || (ctxt->schema == NULL) || (doc == NULL)) |
| 10525 | return (-1); |
| 10526 | |
| 10527 | ctxt->errNo = XML_RELAXNG_OK; |
| 10528 | schema = ctxt->schema; |
| 10529 | grammar = schema->topgrammar; |
| 10530 | if (grammar == NULL) { |
| 10531 | VALID_ERR(XML_RELAXNG_ERR_NOGRAMMAR); |
| 10532 | return (-1); |
| 10533 | } |
| 10534 | state = xmlRelaxNGNewValidState(ctxt, NULL); |
| 10535 | ctxt->state = state; |
| 10536 | ret = xmlRelaxNGValidateDefinition(ctxt, grammar->start); |
| 10537 | if ((ctxt->state != NULL) && (state->seq != NULL)) { |
| 10538 | state = ctxt->state; |
| 10539 | node = state->seq; |
| 10540 | node = xmlRelaxNGSkipIgnored(ctxt, node); |
| 10541 | if (node != NULL) { |
| 10542 | if (ret != -1) { |
| 10543 | VALID_ERR(XML_RELAXNG_ERR_EXTRADATA); |
| 10544 | ret = -1; |
| 10545 | } |
| 10546 | } |
| 10547 | } else if (ctxt->states != NULL) { |
| 10548 | int i; |
| 10549 | int tmp = -1; |
| 10550 | |
| 10551 | for (i = 0; i < ctxt->states->nbState; i++) { |
| 10552 | state = ctxt->states->tabState[i]; |
| 10553 | node = state->seq; |
| 10554 | node = xmlRelaxNGSkipIgnored(ctxt, node); |
| 10555 | if (node == NULL) |
| 10556 | tmp = 0; |
| 10557 | xmlRelaxNGFreeValidState(ctxt, state); |
| 10558 | } |
| 10559 | if (tmp == -1) { |
| 10560 | if (ret != -1) { |
| 10561 | VALID_ERR(XML_RELAXNG_ERR_EXTRADATA); |
| 10562 | ret = -1; |
| 10563 | } |
| 10564 | } |
| 10565 | } |
| 10566 | if (ctxt->state != NULL) { |
| 10567 | xmlRelaxNGFreeValidState(ctxt, ctxt->state); |
| 10568 | ctxt->state = NULL; |
| 10569 | } |
| 10570 | if (ret != 0) |
| 10571 | xmlRelaxNGDumpValidError(ctxt); |
| 10572 | #ifdef LIBXML_VALID_ENABLED |
no test coverage detected