* xmlValidBuildContentModel: * @ctxt: a validation context * @elem: an element declaration node * * DEPRECATED: Internal function, don't use. * * (Re)Build the automata associated to the content model of this * element * * Returns 1 in case of success, 0 in case of error */
| 604 | * Returns 1 in case of success, 0 in case of error |
| 605 | */ |
| 606 | int |
| 607 | xmlValidBuildContentModel(xmlValidCtxtPtr ctxt, xmlElementPtr elem) { |
| 608 | int ret = 0; |
| 609 | |
| 610 | if ((ctxt == NULL) || (elem == NULL)) |
| 611 | return(0); |
| 612 | if (elem->type != XML_ELEMENT_DECL) |
| 613 | return(0); |
| 614 | if (elem->etype != XML_ELEMENT_TYPE_ELEMENT) |
| 615 | return(1); |
| 616 | /* TODO: should we rebuild in this case ? */ |
| 617 | if (elem->contModel != NULL) { |
| 618 | if (!xmlRegexpIsDeterminist(elem->contModel)) { |
| 619 | ctxt->valid = 0; |
| 620 | return(0); |
| 621 | } |
| 622 | return(1); |
| 623 | } |
| 624 | |
| 625 | ctxt->am = xmlNewAutomata(); |
| 626 | if (ctxt->am == NULL) { |
| 627 | xmlVErrMemory(ctxt); |
| 628 | return(0); |
| 629 | } |
| 630 | ctxt->state = xmlAutomataGetInitState(ctxt->am); |
| 631 | if (xmlValidBuildAContentModel(elem->content, ctxt, elem->name) == 0) |
| 632 | goto done; |
| 633 | xmlAutomataSetFinalState(ctxt->am, ctxt->state); |
| 634 | elem->contModel = xmlAutomataCompile(ctxt->am); |
| 635 | if (elem->contModel == NULL) { |
| 636 | xmlVErrMemory(ctxt); |
| 637 | goto done; |
| 638 | } |
| 639 | if (xmlRegexpIsDeterminist(elem->contModel) != 1) { |
| 640 | char expr[5000]; |
| 641 | expr[0] = 0; |
| 642 | xmlSnprintfElementContent(expr, 5000, elem->content, 1); |
| 643 | xmlErrValidNode(ctxt, (xmlNodePtr) elem, |
| 644 | XML_DTD_CONTENT_NOT_DETERMINIST, |
| 645 | "Content model of %s is not deterministic: %s\n", |
| 646 | elem->name, BAD_CAST expr, NULL); |
| 647 | ctxt->valid = 0; |
| 648 | goto done; |
| 649 | } |
| 650 | |
| 651 | ret = 1; |
| 652 | |
| 653 | done: |
| 654 | ctxt->state = NULL; |
| 655 | xmlFreeAutomata(ctxt->am); |
| 656 | ctxt->am = NULL; |
| 657 | return(ret); |
| 658 | } |
| 659 | |
| 660 | #endif /* LIBXML_REGEXP_ENABLED */ |
| 661 |
no test coverage detected