Lines Matching refs:ctxt
431 * @ctxt: an Relax-NG parser context
437 xmlRngPErrMemory(xmlRelaxNGParserCtxtPtr ctxt, const char *extra)
443 if (ctxt != NULL) {
444 if (ctxt->serror != NULL)
445 schannel = ctxt->serror;
447 channel = ctxt->error;
448 data = ctxt->userData;
449 ctxt->nbErrors++;
466 * @ctxt: a Relax-NG validation context
472 xmlRngVErrMemory(xmlRelaxNGValidCtxtPtr ctxt, const char *extra)
478 if (ctxt != NULL) {
479 if (ctxt->serror != NULL)
480 schannel = ctxt->serror;
482 channel = ctxt->error;
483 data = ctxt->userData;
484 ctxt->nbErrors++;
501 * @ctxt: a Relax-NG parser context
511 xmlRngPErr(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node, int error,
518 if (ctxt != NULL) {
519 if (ctxt->serror != NULL)
520 schannel = ctxt->serror;
522 channel = ctxt->error;
523 data = ctxt->userData;
524 ctxt->nbErrors++;
535 * @ctxt: a Relax-NG validation context
545 xmlRngVErr(xmlRelaxNGValidCtxtPtr ctxt, xmlNodePtr node, int error,
552 if (ctxt != NULL) {
553 if (ctxt->serror != NULL)
554 schannel = ctxt->serror;
556 channel = ctxt->error;
557 data = ctxt->userData;
558 ctxt->nbErrors++;
666 static int xmlRelaxNGEqualValidState(xmlRelaxNGValidCtxtPtr ctxt
670 static void xmlRelaxNGFreeValidState(xmlRelaxNGValidCtxtPtr ctxt,
753 * @ctxt: a Relax-NG validation context (optional)
760 xmlRelaxNGNewRelaxNG(xmlRelaxNGParserCtxtPtr ctxt)
766 xmlRngPErrMemory(ctxt, NULL);
832 * @ctxt: a Relax-NG validation context (optional)
839 xmlRelaxNGNewGrammar(xmlRelaxNGParserCtxtPtr ctxt)
845 xmlRngPErrMemory(ctxt, NULL);
883 * @ctxt: a Relax-NG validation context
891 xmlRelaxNGNewDefine(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
895 if (ctxt->defMax == 0) {
896 ctxt->defMax = 16;
897 ctxt->defNr = 0;
898 ctxt->defTab = (xmlRelaxNGDefinePtr *)
899 xmlMalloc(ctxt->defMax * sizeof(xmlRelaxNGDefinePtr));
900 if (ctxt->defTab == NULL) {
901 xmlRngPErrMemory(ctxt, "allocating define\n");
904 } else if (ctxt->defMax <= ctxt->defNr) {
907 ctxt->defMax *= 2;
908 tmp = (xmlRelaxNGDefinePtr *) xmlRealloc(ctxt->defTab,
909 ctxt->defMax *
913 xmlRngPErrMemory(ctxt, "allocating define\n");
916 ctxt->defTab = tmp;
920 xmlRngPErrMemory(ctxt, "allocating define\n");
924 ctxt->defTab[ctxt->defNr++] = ret;
999 * @ctxt: a Relax-NG validation context
1007 xmlRelaxNGNewStates(xmlRelaxNGValidCtxtPtr ctxt, int size)
1011 if ((ctxt != NULL) &&
1012 (ctxt->freeStates != NULL) && (ctxt->freeStatesNr > 0)) {
1013 ctxt->freeStatesNr--;
1014 ret = ctxt->freeStates[ctxt->freeStatesNr];
1026 xmlRngVErrMemory(ctxt, "allocating states\n");
1035 xmlRngVErrMemory(ctxt, "allocating states\n");
1044 * @ctxt: a Relax-NG validation context
1054 xmlRelaxNGAddStatesUniq(xmlRelaxNGValidCtxtPtr ctxt,
1071 xmlRngVErrMemory(ctxt, "adding states\n");
1083 * @ctxt: a Relax-NG validation context
1092 xmlRelaxNGAddStates(xmlRelaxNGValidCtxtPtr ctxt,
1111 xmlRngVErrMemory(ctxt, "adding states\n");
1118 if (xmlRelaxNGEqualValidState(ctxt, state, states->tabState[i])) {
1119 xmlRelaxNGFreeValidState(ctxt, state);
1129 * @ctxt: a Relax-NG validation context
1135 xmlRelaxNGFreeStates(xmlRelaxNGValidCtxtPtr ctxt,
1140 if ((ctxt != NULL) && (ctxt->freeStates == NULL)) {
1141 ctxt->freeStatesMax = 40;
1142 ctxt->freeStatesNr = 0;
1143 ctxt->freeStates = (xmlRelaxNGStatesPtr *)
1144 xmlMalloc(ctxt->freeStatesMax * sizeof(xmlRelaxNGStatesPtr));
1145 if (ctxt->freeStates == NULL) {
1146 xmlRngVErrMemory(ctxt, "storing states\n");
1148 } else if ((ctxt != NULL)
1149 && (ctxt->freeStatesNr >= ctxt->freeStatesMax)) {
1152 tmp = (xmlRelaxNGStatesPtr *) xmlRealloc(ctxt->freeStates,
1153 2 * ctxt->freeStatesMax *
1157 xmlRngVErrMemory(ctxt, "storing states\n");
1162 ctxt->freeStates = tmp;
1163 ctxt->freeStatesMax *= 2;
1165 if ((ctxt == NULL) || (ctxt->freeStates == NULL)) {
1169 ctxt->freeStates[ctxt->freeStatesNr++] = states;
1175 * @ctxt: a Relax-NG validation context
1183 xmlRelaxNGNewValidState(xmlRelaxNGValidCtxtPtr ctxt, xmlNodePtr node)
1192 root = xmlDocGetRootElement(ctxt->doc);
1205 if ((ctxt->freeState != NULL) && (ctxt->freeState->nbState > 0)) {
1206 ctxt->freeState->nbState--;
1207 ret = ctxt->freeState->tabState[ctxt->freeState->nbState];
1213 xmlRngVErrMemory(ctxt, "allocating states\n");
1221 ret->node = (xmlNodePtr) ctxt->doc;
1237 xmlRngVErrMemory(ctxt, "allocating states\n");
1246 xmlRngVErrMemory(ctxt, "allocating states\n");
1270 * @ctxt: a Relax-NG validation context
1278 xmlRelaxNGCopyValidState(xmlRelaxNGValidCtxtPtr ctxt,
1287 if ((ctxt->freeState != NULL) && (ctxt->freeState->nbState > 0)) {
1288 ctxt->freeState->nbState--;
1289 ret = ctxt->freeState->tabState[ctxt->freeState->nbState];
1295 xmlRngVErrMemory(ctxt, "allocating states\n");
1311 xmlRngVErrMemory(ctxt, "allocating states\n");
1321 xmlRngVErrMemory(ctxt, "allocating states\n");
1336 * @ctxt: a Relax-NG validation context
1345 xmlRelaxNGEqualValidState(xmlRelaxNGValidCtxtPtr ctxt ATTRIBUTE_UNUSED,
1382 xmlRelaxNGFreeValidState(xmlRelaxNGValidCtxtPtr ctxt,
1388 if ((ctxt != NULL) && (ctxt->freeState == NULL)) {
1389 ctxt->freeState = xmlRelaxNGNewStates(ctxt, 40);
1391 if ((ctxt == NULL) || (ctxt->freeState == NULL)) {
1396 xmlRelaxNGAddStatesUniq(ctxt, ctxt->freeState, state);
1408 * @ctxt: a RelaxNG parser context
1417 xmlRelaxParserSetFlag(xmlRelaxNGParserCtxtPtr ctxt, int flags)
1419 if (ctxt == NULL) return(-1);
1421 ctxt->crng |= XML_RELAXNGP_FREE_DOC;
1425 ctxt->crng |= XML_RELAXNGP_CRNG;
1437 static xmlDocPtr xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt,
1442 * @ctxt: the parser context
1450 xmlRelaxNGIncludePush(xmlRelaxNGParserCtxtPtr ctxt,
1453 if (ctxt->incTab == NULL) {
1454 ctxt->incMax = 4;
1455 ctxt->incNr = 0;
1456 ctxt->incTab =
1457 (xmlRelaxNGIncludePtr *) xmlMalloc(ctxt->incMax *
1458 sizeof(ctxt->incTab[0]));
1459 if (ctxt->incTab == NULL) {
1460 xmlRngPErrMemory(ctxt, "allocating include\n");
1464 if (ctxt->incNr >= ctxt->incMax) {
1465 ctxt->incMax *= 2;
1466 ctxt->incTab =
1467 (xmlRelaxNGIncludePtr *) xmlRealloc(ctxt->incTab,
1468 ctxt->incMax *
1469 sizeof(ctxt->incTab[0]));
1470 if (ctxt->incTab == NULL) {
1471 xmlRngPErrMemory(ctxt, "allocating include\n");
1475 ctxt->incTab[ctxt->incNr] = value;
1476 ctxt->inc = value;
1477 return (ctxt->incNr++);
1482 * @ctxt: the parser context
1489 xmlRelaxNGIncludePop(xmlRelaxNGParserCtxtPtr ctxt)
1493 if (ctxt->incNr <= 0)
1495 ctxt->incNr--;
1496 if (ctxt->incNr > 0)
1497 ctxt->inc = ctxt->incTab[ctxt->incNr - 1];
1499 ctxt->inc = NULL;
1500 ret = ctxt->incTab[ctxt->incNr];
1501 ctxt->incTab[ctxt->incNr] = NULL;
1507 * @ctxt: the parser context
1517 xmlRelaxNGRemoveRedefine(xmlRelaxNGParserCtxtPtr ctxt,
1564 if (xmlRelaxNGRemoveRedefine(ctxt, href,
1583 * @ctxt: the parser context
1595 xmlRelaxNGLoadInclude(xmlRelaxNGParserCtxtPtr ctxt, const xmlChar * URL,
1611 for (i = 0; i < ctxt->incNr; i++) {
1612 if (xmlStrEqual(ctxt->incTab[i]->href, URL)) {
1613 xmlRngPErr(ctxt, NULL, XML_RNGP_INCLUDE_RECURSE,
1625 xmlRngPErr(ctxt, node, XML_RNGP_PARSE_ERROR,
1638 xmlRngPErrMemory(ctxt, "allocating include\n");
1645 ret->next = ctxt->includes;
1646 ctxt->includes = ret;
1663 xmlRelaxNGIncludePush(ctxt, ret);
1673 doc = xmlRelaxNGCleanupDoc(ctxt, doc);
1675 ctxt->inc = NULL;
1682 xmlRelaxNGIncludePop(ctxt);
1692 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY,
1698 xmlRngPErr(ctxt, node, XML_RNGP_GRAMMAR_MISSING,
1713 xmlRelaxNGRemoveRedefine(ctxt, URL, root->children, NULL);
1715 xmlRngPErr(ctxt, node, XML_RNGP_START_MISSING,
1724 xmlRngPErr(ctxt, node, XML_RNGP_NAME_MISSING,
1731 found = xmlRelaxNGRemoveRedefine(ctxt, URL,
1734 xmlRngPErr(ctxt, node, XML_RNGP_DEFINE_MISSING,
1750 * @ctxt: the validation context
1761 xmlRelaxNGValidErrorPush(xmlRelaxNGValidCtxtPtr ctxt,
1769 "Pushing error %d at %d on stack\n", err, ctxt->errNr);
1771 if (ctxt->errTab == NULL) {
1772 ctxt->errMax = 8;
1773 ctxt->errNr = 0;
1774 ctxt->errTab =
1775 (xmlRelaxNGValidErrorPtr) xmlMalloc(ctxt->errMax *
1778 if (ctxt->errTab == NULL) {
1779 xmlRngVErrMemory(ctxt, "pushing error\n");
1782 ctxt->err = NULL;
1784 if (ctxt->errNr >= ctxt->errMax) {
1785 ctxt->errMax *= 2;
1786 ctxt->errTab =
1787 (xmlRelaxNGValidErrorPtr) xmlRealloc(ctxt->errTab,
1788 ctxt->errMax *
1791 if (ctxt->errTab == NULL) {
1792 xmlRngVErrMemory(ctxt, "pushing error\n");
1795 ctxt->err = &ctxt->errTab[ctxt->errNr - 1];
1797 if ((ctxt->err != NULL) && (ctxt->state != NULL) &&
1798 (ctxt->err->node == ctxt->state->node) && (ctxt->err->err == err))
1799 return (ctxt->errNr);
1800 cur = &ctxt->errTab[ctxt->errNr];
1811 if (ctxt->state != NULL) {
1812 cur->node = ctxt->state->node;
1813 cur->seq = ctxt->state->seq;
1818 ctxt->err = cur;
1819 return (ctxt->errNr++);
1824 * @ctxt: the validation context
1829 xmlRelaxNGValidErrorPop(xmlRelaxNGValidCtxtPtr ctxt)
1833 if (ctxt->errNr <= 0) {
1834 ctxt->err = NULL;
1837 ctxt->errNr--;
1838 if (ctxt->errNr > 0)
1839 ctxt->err = &ctxt->errTab[ctxt->errNr - 1];
1841 ctxt->err = NULL;
1842 cur = &ctxt->errTab[ctxt->errNr];
1856 * @ctxt: the parser context
1864 xmlRelaxNGDocumentPush(xmlRelaxNGParserCtxtPtr ctxt,
1867 if (ctxt->docTab == NULL) {
1868 ctxt->docMax = 4;
1869 ctxt->docNr = 0;
1870 ctxt->docTab =
1871 (xmlRelaxNGDocumentPtr *) xmlMalloc(ctxt->docMax *
1872 sizeof(ctxt->docTab[0]));
1873 if (ctxt->docTab == NULL) {
1874 xmlRngPErrMemory(ctxt, "adding document\n");
1878 if (ctxt->docNr >= ctxt->docMax) {
1879 ctxt->docMax *= 2;
1880 ctxt->docTab =
1881 (xmlRelaxNGDocumentPtr *) xmlRealloc(ctxt->docTab,
1882 ctxt->docMax *
1883 sizeof(ctxt->docTab[0]));
1884 if (ctxt->docTab == NULL) {
1885 xmlRngPErrMemory(ctxt, "adding document\n");
1889 ctxt->docTab[ctxt->docNr] = value;
1890 ctxt->doc = value;
1891 return (ctxt->docNr++);
1896 * @ctxt: the parser context
1903 xmlRelaxNGDocumentPop(xmlRelaxNGParserCtxtPtr ctxt)
1907 if (ctxt->docNr <= 0)
1909 ctxt->docNr--;
1910 if (ctxt->docNr > 0)
1911 ctxt->doc = ctxt->docTab[ctxt->docNr - 1];
1913 ctxt->doc = NULL;
1914 ret = ctxt->docTab[ctxt->docNr];
1915 ctxt->docTab[ctxt->docNr] = NULL;
1921 * @ctxt: the parser context
1932 xmlRelaxNGLoadExternalRef(xmlRelaxNGParserCtxtPtr ctxt,
1943 for (i = 0; i < ctxt->docNr; i++) {
1944 if (xmlStrEqual(ctxt->docTab[i]->href, URL)) {
1945 xmlRngPErr(ctxt, NULL, XML_RNGP_EXTERNALREF_RECURSE,
1957 xmlRngPErr(ctxt, NULL, XML_RNGP_PARSE_ERROR,
1967 xmlRngPErr(ctxt, (xmlNodePtr) doc, XML_ERR_NO_MEMORY,
1975 ret->next = ctxt->documents;
1977 ctxt->documents = ret;
1994 xmlRelaxNGDocumentPush(ctxt, ret);
1999 doc = xmlRelaxNGCleanupDoc(ctxt, doc);
2001 ctxt->doc = NULL;
2005 xmlRelaxNGDocumentPop(ctxt);
2016 #define VALID_ERR(a) xmlRelaxNGAddValidError(ctxt, a, NULL, NULL, 0);
2017 #define VALID_ERR2(a, b) xmlRelaxNGAddValidError(ctxt, a, b, NULL, 0);
2018 #define VALID_ERR3(a, b, c) xmlRelaxNGAddValidError(ctxt, a, b, c, 0);
2019 #define VALID_ERR2P(a, b) xmlRelaxNGAddValidError(ctxt, a, b, NULL, 1);
2020 #define VALID_ERR3P(a, b, c) xmlRelaxNGAddValidError(ctxt, a, b, c, 1);
2225 * @ctxt: the validation context
2235 xmlRelaxNGShowValidError(xmlRelaxNGValidCtxtPtr ctxt,
2242 if (ctxt->flags & FLAGS_NOERROR)
2252 if (ctxt->errNo == XML_RELAXNG_OK)
2253 ctxt->errNo = err;
2254 xmlRngVErr(ctxt, (child == NULL ? node : child), err,
2261 * @ctxt: the validation context
2267 xmlRelaxNGPopErrors(xmlRelaxNGValidCtxtPtr ctxt, int level)
2276 for (i = level; i < ctxt->errNr; i++) {
2277 err = &ctxt->errTab[i];
2288 ctxt->errNr = level;
2289 if (ctxt->errNr <= 0)
2290 ctxt->err = NULL;
2295 * @ctxt: the validation context
2300 xmlRelaxNGDumpValidError(xmlRelaxNGValidCtxtPtr ctxt)
2307 "Dumping error stack %d errors\n", ctxt->errNr);
2309 for (i = 0, k = 0; i < ctxt->errNr; i++) {
2310 err = &ctxt->errTab[i];
2313 dup = &ctxt->errTab[j];
2320 xmlRelaxNGShowValidError(ctxt, err->err, err->node, err->seq,
2335 ctxt->errNr = 0;
2340 * @ctxt: the validation context
2350 xmlRelaxNGAddValidError(xmlRelaxNGValidCtxtPtr ctxt,
2354 if (ctxt == NULL)
2356 if (ctxt->flags & FLAGS_NOERROR)
2365 if (((ctxt->flags & FLAGS_IGNORABLE) == 0) ||
2366 (ctxt->flags & FLAGS_NEGATIVE)) {
2373 if (ctxt->errNr != 0)
2374 xmlRelaxNGDumpValidError(ctxt);
2375 if (ctxt->state != NULL) {
2376 node = ctxt->state->node;
2377 seq = ctxt->state->seq;
2382 node = ctxt->pnode;
2384 xmlRelaxNGShowValidError(ctxt, err, node, seq, arg1, arg2);
2390 xmlRelaxNGValidErrorPush(ctxt, err, arg1, arg2, dup);
2400 static xmlChar *xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt,
2862 static int xmlRelaxNGTryCompile(xmlRelaxNGParserCtxtPtr ctxt,
3016 * ctxt: the RelaxNG parser context
3025 xmlRelaxNGCompile(xmlRelaxNGParserCtxtPtr ctxt, xmlRelaxNGDefinePtr def)
3030 if ((ctxt == NULL) || (def == NULL))
3036 xmlAutomataPtr oldam = ctxt->am;
3037 xmlAutomataStatePtr oldstate = ctxt->state;
3042 ctxt->am = xmlNewAutomata();
3043 if (ctxt->am == NULL)
3054 xmlAutomataSetFlags(ctxt->am, 1);
3056 ctxt->state = xmlAutomataGetInitState(ctxt->am);
3058 xmlRelaxNGCompile(ctxt, list);
3061 xmlAutomataSetFinalState(ctxt->am, ctxt->state);
3062 if (xmlAutomataIsDeterminist(ctxt->am))
3063 def->contModel = xmlAutomataCompile(ctxt->am);
3065 xmlFreeAutomata(ctxt->am);
3066 ctxt->state = oldstate;
3067 ctxt->am = oldam;
3071 if ((ctxt->am != NULL) && (def->name != NULL)) {
3072 ctxt->state = xmlAutomataNewTransition2(ctxt->am,
3073 ctxt->state, NULL,
3078 xmlAutomataPtr oldam = ctxt->am;
3079 xmlAutomataStatePtr oldstate = ctxt->state;
3084 ctxt->am = xmlNewAutomata();
3085 if (ctxt->am == NULL)
3087 xmlAutomataSetFlags(ctxt->am, 1);
3088 ctxt->state = xmlAutomataGetInitState(ctxt->am);
3090 xmlRelaxNGCompile(ctxt, list);
3093 xmlAutomataSetFinalState(ctxt->am, ctxt->state);
3094 def->contModel = xmlAutomataCompile(ctxt->am);
3107 xmlFreeAutomata(ctxt->am);
3108 ctxt->state = oldstate;
3109 ctxt->am = oldam;
3111 xmlAutomataPtr oldam = ctxt->am;
3118 ret = xmlRelaxNGTryCompile(ctxt, def);
3119 ctxt->am = oldam;
3123 ret = xmlRelaxNGCompile(ctxt, def->content);
3126 xmlAutomataStatePtr oldstate = ctxt->state;
3130 xmlRelaxNGCompile(ctxt, list);
3133 xmlAutomataNewEpsilon(ctxt->am, oldstate, ctxt->state);
3139 ctxt->state =
3140 xmlAutomataNewEpsilon(ctxt->am, ctxt->state, NULL);
3141 oldstate = ctxt->state;
3144 xmlRelaxNGCompile(ctxt, list);
3147 xmlAutomataNewEpsilon(ctxt->am, ctxt
3148 ctxt->state =
3149 xmlAutomataNewEpsilon(ctxt->am, oldstate, NULL);
3157 xmlRelaxNGCompile(ctxt, list);
3160 oldstate = ctxt->state;
3163 xmlRelaxNGCompile(ctxt, list);
3166 xmlAutomataNewEpsilon(ctxt->am, ctxt->state, oldstate);
3167 ctxt->state =
3168 xmlAutomataNewEpsilon(ctxt->am, oldstate, NULL);
3173 xmlAutomataStatePtr oldstate = ctxt->state;
3177 ctxt->state = oldstate;
3178 ret = xmlRelaxNGCompile(ctxt, list);
3182 target = ctxt->state;
3184 xmlAutomataNewEpsilon(ctxt->am, ctxt->state,
3189 ctxt->state = target;
3200 ret = xmlRelaxNGCompile(ctxt, list);
3209 ctxt->state =
3210 xmlAutomataNewEpsilon(ctxt->am, ctxt->state, NULL);
3211 oldstate = ctxt->state;
3212 xmlRelaxNGCompile(ctxt, def->content);
3213 xmlAutomataNewTransition(ctxt->am, ctxt->state,
3214 ctxt->state, BAD_CAST "#text",
3216 ctxt->state =
3217 xmlAutomataNewEpsilon(ctxt->am, oldstate, NULL);
3221 ctxt->state =
3222 xmlAutomataNewEpsilon(ctxt->am, ctxt->state, NULL);
3242 * ctxt: the RelaxNG parser context
3251 xmlRelaxNGTryCompile(xmlRelaxNGParserCtxtPtr ctxt, xmlRelaxNGDefinePtr def)
3256 if ((ctxt == NULL) || (def == NULL))
3263 ctxt->am = NULL;
3264 ret = xmlRelaxNGCompile(ctxt, def);
3288 ret = xmlRelaxNGTryCompile(ctxt, def->content);
3311 ret = xmlRelaxNGTryCompile(ctxt, list);
3334 ctxt, xmlNodePtr node);
3336 ctxt, xmlNodePtr node);
3338 ctxt, xmlNodePtr nodes,
3341 ctxt, xmlNodePtr node);
3342 static xmlRelaxNGPtr xmlRelaxNGParseDocument(xmlRelaxNGParserCtxtPtr ctxt,
3344 static int xmlRelaxNGParseGrammarContent(xmlRelaxNGParserCtxtPtr ctxt,
3347 ctxt, xmlNodePtr node,
3351 ctxt, xmlNodePtr nodes);
3352 static int xmlRelaxNGElementMatch(xmlRelaxNGValidCtxtPtr ctxt,
3461 * @ctxt: a Relax-NG parser context
3469 xmlRelaxNGGetDataTypeLibrary(xmlRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
3514 * @ctxt: a Relax-NG parser context
3522 xmlRelaxNGParseValue(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
3530 def = xmlRelaxNGNewDefine(ctxt, node);
3539 xmlRngPErr(ctxt, node, XML_RNGP_TYPE_VALUE,
3542 library = xmlRelaxNGGetDataTypeLibrary(ctxt, node);
3553 xmlRngPErr(ctxt, node, XML_RNGP_UNKNOWN_TYPE_LIB,
3560 xmlRngPErr(ctxt, node, XML_RNGP_ERROR_TYPE_LIB,
3566 xmlRngPErr(ctxt, node, XML_RNGP_TYPE_NOT_FOUND,
3578 xmlRngPErr(ctxt, node, XML_RNGP_TEXT_EXPECTED,
3584 xmlRngPErr(ctxt, node, XML_RNGP_VALUE_NO_CONTENT,
3592 xmlRngPErr(ctxt, node, XML_RNGP_INVALID_VALUE,
3606 * @ctxt: a Relax-NG parser context
3614 xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
3626 xmlRngPErr(ctxt, node, XML_RNGP_TYPE_MISSING, "data has no type\n", NULL,
3632 xmlRngPErr(ctxt, node, XML_RNGP_TYPE_VALUE,
3635 library = xmlRelaxNGGetDataTypeLibrary(ctxt, node);
3640 def = xmlRelaxNGNewDefine(ctxt, node);
3652 xmlRngPErr(ctxt, node, XML_RNGP_UNKNOWN_TYPE_LIB,
3659 xmlRngPErr(ctxt, node, XML_RNGP_ERROR_TYPE_LIB,
3665 xmlRngPErr(ctxt, node, XML_RNGP_TYPE_NOT_FOUND,
3675 ctxt->idref = 1;
3689 xmlRngPErr(ctxt, node, XML_RNGP_PARAM_FORBIDDEN,
3697 param = xmlRelaxNGNewDefine(ctxt, node);
3702 xmlRngPErr(ctxt, node, XML_RNGP_PARAM_NAME_MISSING,
3726 except = xmlRelaxNGNewDefine(ctxt, node);
3734 xmlRngPErr(ctxt, content, XML_RNGP_EXCEPT_NO_CONTENT,
3738 tmp2 = xmlRelaxNGParsePattern(ctxt, child);
3755 xmlRngPErr(ctxt, content, XML_RNGP_DATA_CONTENT,
3785 xmlRelaxNGValidCtxt ctxt;
3787 memset(&ctxt, 0, sizeof(xmlRelaxNGValidCtxt));
3789 ctxt.flags = FLAGS_IGNORABLE | FLAGS_NOERROR;
3810 if (xmlRelaxNGElementMatch(&ctxt, def2, &node)) {
3851 if (xmlRelaxNGElementMatch(&ctxt, def1, &node)) {
3869 * @ctxt: a Relax-NG parser context
3880 xmlRelaxNGCompareElemDefLists(xmlRelaxNGParserCtxtPtr ctxt
3904 * @ctxt: a Relax-NG parser context
3912 xmlRelaxNGGenerateAttributes(xmlRelaxNGParserCtxtPtr ctxt,
3921 if (ctxt->nbErrors != 0)
3979 * @ctxt: a Relax-NG parser context
3988 xmlRelaxNGGetElements(xmlRelaxNGParserCtxtPtr ctxt,
3999 if (ctxt->nbErrors != 0)
4013 xmlRngPErrMemory(ctxt, "getting element list\n");
4023 xmlRngPErrMemory(ctxt, "getting element list\n");
4079 * @ctxt: a Relax-NG parser context
4085 xmlRelaxNGCheckChoiceDeterminism(xmlRelaxNGParserCtxtPtr ctxt,
4106 if (ctxt->nbErrors != 0)
4121 xmlRngPErrMemory(ctxt, "building choice\n");
4135 list[i] = xmlRelaxNGGetElements(ctxt, cur, 0);
4189 ret = xmlRelaxNGCompareElemDefLists(ctxt, list[i], list[j]);
4215 * @ctxt: a Relax-NG parser context
4221 xmlRelaxNGCheckGroupAttrs(xmlRelaxNGParserCtxtPtr ctxt,
4240 if (ctxt->nbErrors != 0)
4258 xmlRngPErrMemory(ctxt, "building group\n");
4264 list[i] = xmlRelaxNGGetElements(ctxt, cur, 1);
4270 list[i] = xmlRelaxNGGetElements(ctxt, cur, 1);
4281 ret = xmlRelaxNGCompareElemDefLists(ctxt, list[i], list[j]);
4283 xmlRngPErr(ctxt, def->node, XML_RNGP_GROUP_ATTR_CONFLICT,
4300 * @ctxt: a Relax-NG parser context
4314 xmlRelaxNGParserCtxtPtr ctxt,
4332 if (ctxt->nbErrors != 0)
4361 groups[nbgroups]->defs = xmlRelaxNGGetElements(ctxt, cur, 0);
4362 groups[nbgroups]->attrs = xmlRelaxNGGetElements(ctxt, cur, 1);
4386 ret = xmlRelaxNGCompareElemDefLists(ctxt, group->defs,
4389 xmlRngPErr(ctxt, def->node, XML_RNGP_ELEM_TEXT_CONFLICT,
4393 ret = xmlRelaxNGCompareElemDefLists(ctxt, group->attrs,
4396 xmlRngPErr(ctxt, def->node, XML_RNGP_ATTR_CONFLICT,
4459 xmlRngPErrMemory(ctxt, "in interleave computation\n");
4474 * @ctxt: a Relax-NG parser context
4482 xmlRelaxNGParseInterleave(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
4488 def = xmlRelaxNGNewDefine(ctxt, node);
4494 if (ctxt->interleaves == NULL)
4495 ctxt->interleaves = xmlHashCreate(10);
4496 if (ctxt->interleaves == NULL) {
4497 xmlRngPErrMemory(ctxt, "create interleaves\n");
4501 snprintf(name, 32, "interleave%d", ctxt->nbInterleaves++);
4502 if (xmlHashAddEntry(ctxt->interleaves, BAD_CAST name, def) < 0) {
4503 xmlRngPErr(ctxt, node, XML_RNGP_INTERLEAVE_ADD,
4510 xmlRngPErr(ctxt, node, XML_RNGP_INTERLEAVE_NO_CONTENT,
4515 cur = xmlRelaxNGParseElement(ctxt, child);
4517 cur = xmlRelaxNGParsePattern(ctxt, child);
4536 * @ctxt: a Relax-NG parser context
4544 xmlRelaxNGParseInclude(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
4552 xmlRngPErr(ctxt, node, XML_RNGP_INCLUDE_EMPTY,
4558 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY, "Include document is empty\n",
4563 xmlRngPErr(ctxt, node, XML_RNGP_GRAMMAR_MISSING,
4572 tmp = xmlRelaxNGParseGrammarContent(ctxt, root->children);
4577 tmp = xmlRelaxNGParseGrammarContent(ctxt, node->children);
4586 * @ctxt: a Relax-NG parser context
4594 xmlRelaxNGParseDefine(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
4603 xmlRngPErr(ctxt, node, XML_RNGP_DEFINE_NAME_MISSING,
4608 xmlRngPErr(ctxt, node, XML_RNGP_INVALID_DEFINE_NAME,
4611 def = xmlRelaxNGNewDefine(ctxt, node);
4619 xmlRngPErr(ctxt, node, XML_RNGP_DEFINE_EMPTY,
4622 olddefine = ctxt->define;
4623 ctxt->define = name;
4625 xmlRelaxNGParsePatterns(ctxt, node->children, 0);
4626 ctxt->define = olddefine;
4628 if (ctxt->grammar->defs == NULL)
4629 ctxt->grammar->defs = xmlHashCreate(10);
4630 if (ctxt->grammar->defs == NULL) {
4631 xmlRngPErr(ctxt, node, XML_RNGP_DEFINE_CREATE_FAILED,
4635 tmp = xmlHashAddEntry(ctxt->grammar->defs, name, def);
4639 prev = xmlHashLookup(ctxt->grammar->defs, name);
4641 xmlRngPErr(ctxt, node, XML_RNGP_DEFINE_CREATE_FAILED,
4666 xmlRelaxNGParserCtxtPtr ctxt = (xmlRelaxNGParserCtxtPtr) data;
4672 tmp = xmlHashAddEntry(ctxt->grammar->refs, name, def);
4677 xmlHashLookup(ctxt->grammar->refs, def->name);
4680 xmlRngPErr(ctxt, NULL, XML_RNGP_REF_CREATE_FAILED,
4684 xmlRngPErr(ctxt, NULL, XML_RNGP_REF_CREATE_FAILED,
4697 * @ctxt: the parser context
4705 xmlRelaxNGParseImportRefs(xmlRelaxNGParserCtxtPtr ctxt,
4707 if ((ctxt == NULL) || (grammar == NULL) || (ctxt->grammar == NULL))
4711 if (ctxt->grammar->refs == NULL)
4712 ctxt->grammar->refs = xmlHashCreate(10);
4713 if (ctxt->grammar->refs == NULL) {
4714 xmlRngPErr(ctxt, NULL, XML_RNGP_REF_CREATE_FAILED,
4718 xmlHashScan(grammar->refs, xmlRelaxNGParseImportRef, ctxt);
4724 * @ctxt: the parser context
4732 xmlRelaxNGProcessExternalRef(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
4742 def = xmlRelaxNGNewDefine(ctxt, node);
4753 xmlRngPErr(ctxt, node, XML_RNGP_EXTERNALREF_EMTPY,
4754 "xmlRelaxNGParse: %s is empty\n", ctxt->URL,
4783 oldflags = ctxt->flags;
4784 ctxt->flags |= XML_RELAXNG_IN_EXTERNALREF;
4785 docu->schema = xmlRelaxNGParseDocument(ctxt, root);
4786 ctxt->flags = oldflags;
4791 xmlRelaxNGParseImportRefs(ctxt, docu->schema->topgrammar);
4810 * @ctxt: a Relax-NG parser context
4819 xmlRelaxNGParsePattern(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
4827 def = xmlRelaxNGParseElement(ctxt, node);
4829 def = xmlRelaxNGParseAttribute(ctxt, node);
4831 def = xmlRelaxNGNewDefine(ctxt, node);
4836 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_NOT_EMPTY,
4840 def = xmlRelaxNGNewDefine(ctxt, node);
4845 xmlRngPErr(ctxt, node, XML_RNGP_TEXT_HAS_CHILD,
4849 def = xmlRelaxNGNewDefine(ctxt, node);
4854 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4858 xmlRelaxNGParsePatterns(ctxt, node->children, 1);
4861 def = xmlRelaxNGNewDefine(ctxt, node);
4866 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4870 xmlRelaxNGParsePatterns(ctxt, node->children, 1);
4873 def = xmlRelaxNGNewDefine(ctxt, node);
4878 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4882 xmlRelaxNGParsePatterns(ctxt, node->children, 1);
4885 def = xmlRelaxNGNewDefine(ctxt, node);
4890 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4894 xmlRelaxNGParsePatterns(ctxt, node->children, 0);
4897 def = xmlRelaxNGNewDefine(ctxt, node);
4902 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4906 xmlRelaxNGParsePatterns(ctxt, node->children, 0);
4909 def = xmlRelaxNGNewDefine(ctxt, node);
4915 xmlRngPErr(ctxt, node, XML_RNGP_REF_NO_NAME, "ref has no name\n",
4920 xmlRngPErr(ctxt, node, XML_RNGP_REF_NAME_INVALID,
4926 xmlRngPErr(ctxt, node, XML_RNGP_REF_NOT_EMPTY, "ref is not empty\n",
4929 if (ctxt->grammar->refs == NULL)
4930 ctxt->grammar->refs = xmlHashCreate(10);
4931 if (ctxt->grammar->refs == NULL) {
4932 xmlRngPErr(ctxt, node, XML_RNGP_REF_CREATE_FAILED,
4938 tmp = xmlHashAddEntry(ctxt->grammar->refs, def->name, def);
4943 xmlHashLookup(ctxt->grammar->refs, def->name);
4946 xmlRngPErr(ctxt, node, XML_RNGP_REF_CREATE_FAILED,
4950 xmlRngPErr(ctxt, node, XML_RNGP_REF_CREATE_FAILED,
4962 def = xmlRelaxNGParseData(ctxt, node);
4964 def = xmlRelaxNGParseValue(ctxt, node);
4966 def = xmlRelaxNGNewDefine(ctxt, node);
4971 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4975 xmlRelaxNGParsePatterns(ctxt, node->children, 0);
4978 def = xmlRelaxNGParseInterleave(ctxt, node);
4980 def = xmlRelaxNGProcessExternalRef(ctxt, node);
4982 def = xmlRelaxNGNewDefine(ctxt, node);
4987 xmlRngPErr(ctxt, node, XML_RNGP_NOTALLOWED_NOT_EMPTY,
5000 oldparent = ctxt->parentgrammar;
5001 old = ctxt->grammar;
5002 ctxt->parentgrammar = old;
5003 grammar = xmlRelaxNGParseGrammar(ctxt, node->children);
5005 ctxt->grammar = old;
5006 ctxt->parentgrammar = oldparent;
5019 if (ctxt->parentgrammar == NULL) {
5020 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_NO_PARENT,
5025 def = xmlRelaxNGNewDefine(ctxt, node);
5031 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_NO_NAME,
5036 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_NAME_INVALID,
5042 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_NOT_EMPTY,
5045 if (ctxt->parentgrammar->refs == NULL)
5046 ctxt->parentgrammar->refs = xmlHashCreate(10);
5047 if (ctxt->parentgrammar->refs == NULL) {
5048 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_CREATE_FAILED,
5055 xmlHashAddEntry(ctxt->parentgrammar->refs, def->name, def);
5060 xmlHashLookup(ctxt->parentgrammar->refs, def->name);
5062 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_CREATE_FAILED,
5074 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT, "Mixed is empty\n",
5078 def = xmlRelaxNGParseInterleave(ctxt, node);
5083 tmp = xmlRelaxNGNewDefine(ctxt, node);
5091 tmp = xmlRelaxNGNewDefine(ctxt, node);
5100 xmlRngPErr(ctxt, node, XML_RNGP_UNKNOWN_CONSTRUCT,
5110 * @ctxt: a Relax-NG parser context
5118 xmlRelaxNGParseAttribute(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
5124 ret = xmlRelaxNGNewDefine(ctxt, node);
5128 ret->parent = ctxt->def;
5131 xmlRngPErr(ctxt, node, XML_RNGP_ATTRIBUTE_EMPTY,
5136 old_flags = ctxt->flags;
5137 ctxt->flags |= XML_RELAXNG_IN_ATTRIBUTE;
5138 cur = xmlRelaxNGParseNameClass(ctxt, child, ret);
5143 cur = xmlRelaxNGParsePattern(ctxt, child);
5170 xmlRngPErr(ctxt, node, XML_RNGP_ATTRIBUTE_CONTENT,
5175 xmlRngPErr(ctxt, node, XML_RNGP_ATTRIBUTE_NOOP,
5184 xmlRngPErr(ctxt, node, XML_RNGP_ATTRIBUTE_CHILDREN,
5187 ctxt->flags = old_flags;
5193 * @ctxt: a Relax-NG parser context
5202 xmlRelaxNGParseExceptNameClass(xmlRelaxNGParserCtxtPtr ctxt,
5209 xmlRngPErr(ctxt, node, XML_RNGP_EXCEPT_MISSING,
5214 xmlRngPErr(ctxt, node, XML_RNGP_EXCEPT_MULTIPLE,
5219 xmlRngPErr(ctxt, node, XML_RNGP_EXCEPT_EMPTY, "except has no content\n",
5224 ret = xmlRelaxNGNewDefine(ctxt, node);
5230 cur = xmlRelaxNGNewDefine(ctxt, child);
5238 if (xmlRelaxNGParseNameClass(ctxt, child, cur) != NULL) {
5254 * @ctxt: a Relax-NG parser context
5263 xmlRelaxNGParseNameClass(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node,
5274 ret = xmlRelaxNGNewDefine(ctxt, node);
5278 if (ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE)
5289 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_NAME,
5293 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_NAME,
5300 if ((ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE) &&
5303 xmlRngPErr(ctxt, node, XML_RNGP_XML_NS,
5307 if ((ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE) &&
5310 xmlRngPErr(ctxt, node, XML_RNGP_XMLNS_NAME,
5319 xmlRelaxNGParseExceptNameClass(ctxt, node->children,
5327 xmlRngPErr(ctxt, node, XML_RNGP_NSNAME_NO_NS,
5330 if ((ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE) &&
5334 xmlRngPErr(ctxt, node, XML_RNGP_XML_NS,
5340 xmlRelaxNGParseExceptNameClass(ctxt, node->children,
5348 ret = xmlRelaxNGNewDefine(ctxt, node);
5355 xmlRngPErr(ctxt, node, XML_RNGP_CHOICE_EMPTY,
5361 tmp = xmlRelaxNGParseNameClass(ctxt, child, ret);
5374 xmlRngPErr(ctxt, node, XML_RNGP_CHOICE_CONTENT,
5396 * @ctxt: a Relax-NG parser context
5404 xmlRelaxNGParseElement(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
5410 ret = xmlRelaxNGNewDefine(ctxt, node);
5414 ret->parent = ctxt->def;
5417 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_EMPTY,
5422 cur = xmlRelaxNGParseNameClass(ctxt, child, ret);
5427 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_NO_CONTENT,
5432 olddefine = ctxt->define;
5433 ctxt->define = NULL;
5436 cur = xmlRelaxNGParsePattern(ctxt, child);
5462 ret->content = xmlRelaxNGNewDefine(ctxt, node);
5479 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_CONTENT,
5484 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_CONTENT,
5489 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_CONTENT,
5494 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_CONTENT,
5502 ctxt->define = olddefine;
5508 * @ctxt: a Relax-NG parser context
5517 xmlRelaxNGParsePatterns(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr nodes,
5522 parent = ctxt->def;
5525 cur = xmlRelaxNGParseElement(ctxt, nodes);
5531 def = xmlRelaxNGNewDefine(ctxt, nodes);
5540 cur = xmlRelaxNGParsePattern(ctxt, nodes);
5557 * @ctxt: a Relax-NG parser context
5565 xmlRelaxNGParseStart(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr nodes)
5571 xmlRngPErr(ctxt, nodes, XML_RNGP_START_EMPTY, "start has no children\n",
5576 def = xmlRelaxNGNewDefine(ctxt, nodes);
5581 xmlRngPErr(ctxt, nodes, XML_RNGP_EMPTY_CONTENT,
5585 def = xmlRelaxNGNewDefine(ctxt, nodes);
5590 xmlRngPErr(ctxt, nodes, XML_RNGP_NOTALLOWED_NOT_EMPTY,
5594 def = xmlRelaxNGParsePatterns(ctxt, nodes, 1);
5596 if (ctxt->grammar->start != NULL) {
5597 last = ctxt->grammar->start;
5602 ctxt->grammar->start = def;
5606 xmlRngPErr(ctxt, nodes, XML_RNGP_START_CONTENT,
5615 * @ctxt: a Relax-NG parser context
5623 xmlRelaxNGParseGrammarContent(xmlRelaxNGParserCtxtPtr ctxt,
5629 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_EMPTY,
5636 xmlRngPErr(ctxt
5639 tmp = xmlRelaxNGParseStart(ctxt, nodes->children);
5644 tmp = xmlRelaxNGParseDefine(ctxt, nodes);
5648 tmp = xmlRelaxNGParseInclude(ctxt, nodes);
5652 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_CONTENT,
5665 * @ctxt: a Relax-NG parser context
5673 xmlRelaxNGParserCtxtPtr ctxt,
5685 grammar = ctxt->grammar;
5687 xmlRngPErr(ctxt, ref->node, XML_ERR_INTERNAL_ERROR,
5693 xmlRngPErr(ctxt, ref->node, XML_ERR_INTERNAL_ERROR,
5707 xmlRngPErr(ctxt, ref->node, XML_RNGP_REF_NO_DEF,
5712 xmlRngPErr(ctxt, ref->node, XML_RNGP_REF_NO_DEF,
5721 * @ctxt: a Relax-NG parser context
5729 xmlRelaxNGParserCtxtPtr ctxt, const xmlChar * name)
5746 xmlRngPErr(ctxt, define->node, XML_RNGP_DEF_CHOICE_AND_INTERLEAVE,
5754 xmlRngPErr(ctxt, define->node, XML_RNGP_DEF_CHOICE_AND_INTERLEAVE,
5759 xmlRngPErr(ctxt, define->node, XML_RNGP_UNKNOWN_COMBINE,
5768 xmlRngPErr(ctxt, define->node, XML_RNGP_NEED_COMBINE,
5783 cur = xmlRelaxNGNewDefine(ctxt, define->node);
5798 tmp2 = xmlRelaxNGNewDefine(ctxt, tmp->content->node);
5818 if (ctxt->interleaves == NULL)
5819 ctxt->interleaves = xmlHashCreate(10);
5820 if (ctxt->interleaves == NULL) {
5821 xmlRngPErr(ctxt, define->node, XML_RNGP_INTERLEAVE_CREATE_FAILED,
5827 snprintf(tmpname, 32, "interleave%d", ctxt->nbInterleaves++);
5828 if (xmlHashAddEntry(ctxt->interleaves, BAD_CAST tmpname, cur) <
5830 xmlRngPErr(ctxt, define->node, XML_RNGP_INTERLEAVE_CREATE_FAILED,
5840 * @ctxt: a Relax-NG parser context
5847 xmlRelaxNGCombineStart(xmlRelaxNGParserCtxtPtr ctxt,
5864 xmlRngPErr(ctxt, cur->node, XML_RNGP_START_MISSING,
5876 xmlRngPErr(ctxt, cur->node, XML_RNGP_START_CHOICE_AND_INTERLEAVE,
5884 xmlRngPErr(ctxt, cur->node, XML_RNGP_START_CHOICE_AND_INTERLEAVE,
5889 xmlRngPErr(ctxt, cur->node, XML_RNGP_UNKNOWN_COMBINE,
5898 xmlRngPErr(ctxt, cur->node, XML_RNGP_NEED_COMBINE,
5913 cur = xmlRelaxNGNewDefine(ctxt, starts->node);
5923 if (ctxt->interleaves == NULL)
5924 ctxt->interleaves = xmlHashCreate(10);
5925 if (ctxt->interleaves == NULL) {
5926 xmlRngPErr(ctxt, cur->node, XML_RNGP_INTERLEAVE_CREATE_FAILED,
5932 snprintf(tmpname, 32, "interleave%d", ctxt->nbInterleaves++);
5933 if (xmlHashAddEntry(ctxt->interleaves, BAD_CAST tmpname, cur) <
5935 xmlRngPErr(ctxt, cur->node, XML_RNGP_INTERLEAVE_CREATE_FAILED,
5945 * @ctxt: a Relax-NG parser context
5954 xmlRelaxNGCheckCycles(xmlRelaxNGParserCtxtPtr ctxt,
5964 ret = xmlRelaxNGCheckCycles(ctxt, cur->content, depth);
5967 xmlRngPErr(ctxt, cur->node, XML_RNGP_REF_CYCLE,
5973 ret = xmlRelaxNGCheckCycles(ctxt, cur->content, depth + 1);
5975 ret = xmlRelaxNGCheckCycles(ctxt, cur->content, depth);
5984 * @ctxt: a Relax-NG parser context
5994 xmlRelaxNGTryUnlink(xmlRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
6018 * @ctxt: a Relax-NG parser context
6024 xmlRelaxNGSimplify(xmlRelaxNGParserCtxtPtr ctxt,
6034 xmlRelaxNGSimplify(ctxt, cur->content, cur);
6049 prev = xmlRelaxNGTryUnlink(ctxt, cur, parent, prev);
6063 prev = xmlRelaxNGTryUnlink(ctxt, cur, parent, prev);
6069 xmlRelaxNGSimplify(ctxt, cur->content, cur);
6071 xmlRelaxNGSimplify(ctxt, cur->attrs, cur);
6073 xmlRelaxNGSimplify(ctxt, cur->nameClass, cur);
6084 xmlRelaxNGGenerateAttributes(ctxt, cur->content);
6103 attronly = xmlRelaxNGGenerateAttributes(ctxt, tmp);
6143 prev = xmlRelaxNGTryUnlink(ctxt, cur, parent, prev);
6157 prev = xmlRelaxNGTryUnlink(ctxt, cur, parent, prev);
6171 prev = xmlRelaxNGTryUnlink(ctxt, cur, parent, prev);
6235 * @ctxt: a Relax-NG parser context
6245 xmlRelaxNGCheckRules(xmlRelaxNGParserCtxtPtr ctxt,
6263 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_REF,
6269 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_REF,
6275 xmlRngPErr(ctxt, cur->node, XML_RNGP_REF_NO_DEF,
6279 xmlRngPErr(ctxt, cur->node, XML_RNGP_REF_NO_DEF,
6285 ret = xmlRelaxNGCheckRules(ctxt, cur->content,
6297 xmlRelaxNGCheckGroupAttrs(ctxt, cur);
6299 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_ELEM,
6304 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_ELEM,
6309 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_ATTR_ELEM,
6314 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_ATTR_ELEM,
6324 xmlRelaxNGCheckRules(ctxt, cur->attrs, nflags, cur->type);
6326 xmlRngPErr(ctxt, cur->node, XML_RNGP_ELEM_CONTENT_EMPTY,
6331 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6334 xmlRngPErr(ctxt, cur->node, XML_RNGP_ELEM_CONTENT_ERROR,
6342 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_ATTR_ATTR,
6347 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_ATTR,
6352 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_ONEMORE_GROUP_ATTR,
6357 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_ONEMORE_INTERLEAVE_ATTR,
6362 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_ATTR,
6367 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_ATTR,
6374 xmlRngPErr(ctxt, cur->node, XML_RNGP_ANYNAME_ATTR_ANCESTOR,
6378 xmlRngPErr(ctxt, cur->node, XML_RNGP_NSNAME_ATTR_ANCESTOR,
6384 xmlRelaxNGCheckRules(ctxt, cur->content, nflags, cur->type);
6389 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_ONEMORE,
6394 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_ONEMORE,
6400 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6405 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_LIST,
6410 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_LIST,
6415 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_LIST,
6421 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6425 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_GROUP,
6430 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_GROUP,
6439 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6444 xmlRelaxNGCheckGroupAttrs(ctxt, cur);
6447 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_INTERLEAVE,
6452 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_INTERLEAVE,
6457 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_INTERLEAVE,
6466 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6475 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6479 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_DATA,
6483 xmlRelaxNGCheckRules(ctxt, cur->content, flags, cur->type);
6487 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_VALUE,
6491 xmlRelaxNGCheckRules(ctxt, cur->content, flags, cur->type);
6495 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_TEXT,
6500 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_TEXT,
6505 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_TEXT,
6512 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_EMPTY,
6517 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_EMPTY,
6523 xmlRelaxNGCheckChoiceDeterminism(ctxt, cur);
6525 xmlRelaxNGCheckRules(ctxt, cur->content, flags, cur->type);
6528 xmlRelaxNGCheckRules(ctxt, cur->content, flags, cur->type);
6560 * @ctxt: a Relax-NG parser context
6569 xmlRelaxNGParseGrammar(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr nodes)
6577 ret = xmlRelaxNGNewGrammar(ctxt);
6584 ret->parent = ctxt->grammar;
6585 if (ctxt->grammar != NULL) {
6586 tmp = ctxt->grammar->children;
6588 ctxt->grammar->children = ret;
6596 old = ctxt->grammar;
6597 ctxt->grammar = ret;
6598 xmlRelaxNGParseGrammarContent(ctxt, nodes);
6599 ctxt->grammar = ret;
6600 if (ctxt->grammar == NULL) {
6601 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_CONTENT,
6603 } else if (ctxt->grammar->start == NULL) {
6604 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_NO_START,
6611 xmlRelaxNGCombineStart(ctxt, ret);
6614 ctxt);
6622 ctxt);
6628 ctxt->grammar = old;
6634 * @ctxt: a Relax-NG parser context
6644 xmlRelaxNGParseDocument(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
6650 if ((ctxt == NULL) || (node == NULL))
6653 schema = xmlRelaxNGNewRelaxNG(ctxt);
6657 olddefine = ctxt->define;
6658 ctxt->define = NULL;
6660 schema->topgrammar = xmlRelaxNGParseGrammar(ctxt, node->children);
6668 schema->topgrammar = ret = xmlRelaxNGNewGrammar(ctxt);
6676 ret->parent = ctxt->grammar;
6677 if (ctxt->grammar != NULL) {
6678 tmp = ctxt->grammar->children;
6680 ctxt->grammar->children = ret;
6687 old = ctxt->grammar;
6688 ctxt->grammar = ret;
6689 xmlRelaxNGParseStart(ctxt, node);
6691 ctxt->grammar = old;
6693 ctxt->define = olddefine;
6695 xmlRelaxNGCheckCycles(ctxt, schema->topgrammar->start, 0);
6696 if ((ctxt->flags & XML_RELAXNG_IN_EXTERNALREF) == 0) {
6697 xmlRelaxNGSimplify(ctxt, schema->topgrammar->start, NULL);
6703 xmlRelaxNGCheckRules(ctxt, schema->topgrammar->start,
6821 * @ctxt: the schema parser context
6826 xmlRelaxNGFreeParserCtxt(xmlRelaxNGParserCtxtPtr ctxt)
6828 if (ctxt == NULL)
6830 if (ctxt->URL != NULL)
6831 xmlFree(ctxt->URL);
6832 if (ctxt->doc != NULL)
6833 xmlRelaxNGFreeDocument(ctxt->doc);
6834 if (ctxt->interleaves != NULL)
6835 xmlHashFree(ctxt->interleaves, NULL);
6836 if (ctxt->documents != NULL)
6837 xmlRelaxNGFreeDocumentList(ctxt->documents);
6838 if (ctxt->includes != NULL)
6839 xmlRelaxNGFreeIncludeList(ctxt->includes);
6840 if (ctxt->docTab != NULL)
6841 xmlFree(ctxt->docTab);
6842 if (ctxt->incTab != NULL)
6843 xmlFree(ctxt->incTab);
6844 if (ctxt->defTab != NULL) {
6847 for (i = 0; i < ctxt->defNr; i++)
6848 xmlRelaxNGFreeDefine(ctxt->defTab[i]);
6849 xmlFree(ctxt->defTab);
6851 if ((ctxt->document != NULL) && (ctxt->freedoc))
6852 xmlFreeDoc(ctxt->document);
6853 xmlFree(ctxt);
6910 * @ctxt: a Relax-NG parser context
6916 xmlRelaxNGCleanupAttributes(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
6932 xmlRngPErr(ctxt, node, XML_RNGP_FORBIDDEN_ATTRIBUTE,
6939 xmlRngPErr(ctxt, node, XML_RNGP_FORBIDDEN_ATTRIBUTE,
6946 xmlRngPErr(ctxt, node, XML_RNGP_FORBIDDEN_ATTRIBUTE,
6953 xmlRngPErr(ctxt, node, XML_RNGP_FORBIDDEN_ATTRIBUTE,
6966 xmlRngPErr(ctxt, node, XML_RNGP_INVALID_URI,
6971 xmlRngPErr(ctxt, node, XML_RNGP_URI_NOT_ABSOLUTE,
6976 xmlRngPErr(ctxt, node, XML_RNGP_URI_FRAGMENT,
6986 xmlRngPErr(ctxt, node, XML_RNGP_UNKNOWN_ATTRIBUTE,
6997 * @ctxt: a Relax-NG parser context
7004 xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root)
7027 xmlRngPErr(ctxt, cur, XML_RNGP_FOREIGN_ELEMENT,
7034 xmlRelaxNGCleanupAttributes(ctxt, cur);
7054 xmlRngPErr(ctxt, cur, XML_RNGP_MISSING_HREF,
7064 xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR,
7075 xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR,
7090 xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR,
7106 docu = xmlRelaxNGLoadExternalRef(ctxt, URL, ns);
7108 xmlRngPErr(ctxt, cur, XML_RNGP_EXTERNAL_REF_FAILURE,
7128 xmlRngPErr(ctxt, cur, XML_RNGP_MISSING_HREF,
7137 xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR,
7162 incl = xmlRelaxNGLoadInclude(ctxt, URL, cur, ns);
7166 xmlRngPErr(ctxt, cur, XML_RNGP_INCLUDE_FAILURE,
7204 xmlRngPErr(ctxt, cur, XML_RNGP_CREATE_FAILURE,
7263 xmlRngPErr(ctxt, cur,
7282 if (ctxt->flags & XML_RELAXNG_IN_NSEXCEPT) {
7283 xmlRngPErr(ctxt, cur,
7291 int oldflags = ctxt->flags;
7299 ctxt->flags |= XML_RELAXNG_IN_ANYEXCEPT;
7300 xmlRelaxNGCleanupTree(ctxt, cur);
7301 ctxt->flags = oldflags;
7306 ctxt->flags |= XML_RELAXNG_IN_NSEXCEPT;
7307 xmlRelaxNGCleanupTree(ctxt, cur);
7308 ctxt->flags = oldflags;
7315 if (ctxt->flags & XML_RELAXNG_IN_ANYEXCEPT) {
7316 xmlRngPErr(ctxt, cur,
7320 } else if (ctxt->flags & XML_RELAXNG_IN_NSEXCEPT) {
7321 xmlRngPErr(ctxt, cur,
7438 * @ctxt: a Relax-NG parser context
7447 xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt, xmlDocPtr doc)
7456 xmlRngPErr(ctxt, (xmlNodePtr) doc, XML_RNGP_EMPTY, "xmlRelaxNGParse: %s is empty\n",
7457 ctxt->URL, NULL);
7460 xmlRelaxNGCleanupTree(ctxt, root);
7466 * @ctxt: a Relax-NG parser context
7475 xmlRelaxNGParse(xmlRelaxNGParserCtxtPtr ctxt)
7483 if (ctxt == NULL)
7489 if (ctxt->URL != NULL) {
7490 doc = xmlReadFile((const char *) ctxt->URL,NULL,0);
7492 xmlRngPErr(ctxt, NULL, XML_RNGP_PARSE_ERROR,
7493 "xmlRelaxNGParse: could not load %s\n", ctxt->URL,
7497 } else if (ctxt->buffer != NULL) {
7498 doc = xmlReadMemory(ctxt->buffer, ctxt->size,NULL,NULL,0);
7500 xmlRngPErr(ctxt, NULL, XML_RNGP_PARSE_ERROR,
7506 ctxt->URL = xmlStrdup(BAD_CAST "in_memory_buffer");
7507 } else if (ctxt->document != NULL) {
7508 doc = ctxt->document;
7510 xmlRngPErr(ctxt, NULL, XML_RNGP_EMPTY,
7514 ctxt->document = doc;
7519 doc = xmlRelaxNGCleanupDoc(ctxt, doc);
7521 xmlFreeDoc(ctxt->document);
7522 ctxt->document = NULL;
7531 xmlRngPErr(ctxt, (xmlNodePtr) doc,
7533 (ctxt->URL ? ctxt->URL : BAD_CAST "schemas"), NULL);
7535 xmlFreeDoc(ctxt->document);
7536 ctxt->document = NULL;
7539 ret = xmlRelaxNGParseDocument(ctxt, root);
7541 xmlFreeDoc(ctxt->document);
7542 ctxt->document = NULL;
7552 if (ctxt->interleaves != NULL) {
7553 xmlHashScan(ctxt->interleaves,
7554 (xmlHashScanner) xmlRelaxNGComputeInterleaves, ctxt);
7560 if (ctxt->nbErrors > 0) {
7562 ctxt->document = NULL;
7574 def = xmlRelaxNGNewDefine(ctxt, NULL);
7581 xmlRelaxNGTryCompile(ctxt, ret->topgrammar->start);
7588 ctxt->document = NULL;
7589 ret->documents = ctxt->documents;
7590 ctxt->documents = NULL;
7592 ret->includes = ctxt->includes;
7593 ctxt->includes = NULL;
7594 ret->defNr = ctxt->defNr;
7595 ret->defTab = ctxt->defTab;
7596 ctxt->defTab = NULL;
7597 if (ctxt->idref == 1)
7605 * @ctxt: a Relax-NG validation context
7613 xmlRelaxNGSetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
7617 if (ctxt == NULL)
7619 ctxt->error = err;
7620 ctxt->warning = warn;
7621 ctxt->serror = NULL;
7622 ctxt->userData = ctx;
7627 * @ctxt: a Relax-NG validation context
7637 xmlRelaxNGGetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
7641 if (ctxt == NULL)
7644 *err = ctxt->error;
7646 *warn = ctxt->warning;
7648 *ctx = ctxt->userData;
7654 * @ctxt: a Relax-NG parser context
7661 xmlRelaxNGSetParserStructuredErrors(xmlRelaxNGParserCtxtPtr ctxt,
7665 if (ctxt == NULL)
7667 ctxt->serror = serror;
7668 ctxt->error = NULL;
7669 ctxt->warning = NULL;
7670 ctxt->userData = ctx;
7916 static int xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt,
7933 xmlRelaxNGValidCtxtPtr ctxt = (xmlRelaxNGValidCtxtPtr) inputdata;
7941 if (ctxt == NULL) {
7949 if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
7950 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
7953 if ((ctxt == NULL) || (define == NULL)) {
7955 if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
7956 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
7960 if (ctxt->errNo == XML_RELAXNG_OK)
7961 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
7964 ret = xmlRelaxNGValidateDefinition(ctxt, define);
7966 ctxt->perr = ret;
7971 * @ctxt: the RelaxNG validation context
7980 xmlRelaxNGValidateCompiledContent(xmlRelaxNGValidCtxtPtr ctxt,
7988 if ((ctxt == NULL) || (regexp == NULL))
7990 oldperr = ctxt->perr;
7992 xmlRelaxNGValidateCompiledCallback, ctxt);
7993 ctxt->perr = 0;
7996 ctxt->state->seq = cur;
8002 ret = xmlRegExecPushString(exec, BAD_CAST "#text", ctxt);
8011 cur->ns->href, ctxt);
8013 ret = xmlRegExecPushString(exec, cur->name, ctxt);
8032 ctxt->state->seq = NULL;
8039 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
8040 xmlRelaxNGDumpValidError(ctxt);
8049 if ((ret == 0) && (ctxt->perr != 0)) {
8050 ret = ctxt->perr;
8052 ctxt->perr = oldperr;
8061 static int xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt,
8063 static int xmlRelaxNGValidateElementEnd(xmlRelaxNGValidCtxtPtr ctxt,
8065 static void xmlRelaxNGLogBestError(xmlRelaxNGValidCtxtPtr ctxt);
8069 * @ctxt: the validation context
8077 xmlRelaxNGElemPush(xmlRelaxNGValidCtxtPtr ctxt, xmlRegExecCtxtPtr exec)
8079 if (ctxt->elemTab == NULL) {
8080 ctxt->elemMax = 10;
8081 ctxt->elemTab = (xmlRegExecCtxtPtr *) xmlMalloc(ctxt->elemMax *
8084 if (ctxt->elemTab == NULL) {
8085 xmlRngVErrMemory(ctxt, "validating\n");
8089 if (ctxt->elemNr >= ctxt->elemMax) {
8090 ctxt->elemMax *= 2;
8091 ctxt->elemTab = (xmlRegExecCtxtPtr *) xmlRealloc(ctxt->elemTab,
8092 ctxt->elemMax *
8095 if (ctxt->elemTab == NULL) {
8096 xmlRngVErrMemory(ctxt, "validating\n");
8100 ctxt->elemTab[ctxt->elemNr++] = exec;
8101 ctxt->elem = exec;
8107 * @ctxt: the validation context
8114 xmlRelaxNGElemPop(xmlRelaxNGValidCtxtPtr ctxt)
8118 if (ctxt->elemNr <= 0)
8120 ctxt->elemNr--;
8121 ret = ctxt->elemTab[ctxt->elemNr];
8122 ctxt->elemTab[ctxt->elemNr] = NULL;
8123 if (ctxt->elemNr > 0)
8124 ctxt->elem = ctxt->elemTab[ctxt->elemNr - 1];
8126 ctxt->elem = NULL;
8146 xmlRelaxNGValidCtxtPtr ctxt = (xmlRelaxNGValidCtxtPtr) inputdata;
8156 if (ctxt == NULL) {
8160 node = ctxt->pnode;
8161 ctxt->pstate = 1;
8166 if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
8167 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
8168 ctxt->pstate = -1;
8171 if ((ctxt == NULL) || (define == NULL)) {
8173 if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
8174 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
8175 ctxt->pstate = -1;
8179 if (ctxt->errNo == XML_RELAXNG_OK)
8180 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
8181 ctxt->pstate = -1;
8186 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
8187 xmlRelaxNGDumpValidError(ctxt);
8188 ctxt->pstate = -1;
8200 ctxt->pstate = 0;
8201 ctxt->pdef = define;
8205 xmlRelaxNGValidateProgressiveCallback, ctxt);
8207 ctxt->pstate = -1;
8210 xmlRelaxNGElemPush(ctxt, exec);
8215 state = xmlRelaxNGNewValidState(ctxt, node);
8217 ctxt->pstate = -1;
8220 oldstate = ctxt->state;
8221 ctxt->state = state;
8223 ret = xmlRelaxNGValidateAttributeList(ctxt, define->attrs);
8225 ctxt->pstate = -1;
8229 if (ctxt->state != NULL) {
8230 ctxt->state->seq = NULL;
8231 ret = xmlRelaxNGValidateElementEnd(ctxt, 1);
8233 ctxt->pstate = -1;
8235 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
8236 } else if (ctxt->states != NULL) {
8239 oldflags = ctxt->flags;
8241 for (i = 0; i < ctxt->states->nbState; i++) {
8242 state = ctxt->states->tabState[i];
8243 ctxt->state = state;
8244 ctxt->state->seq = NULL;
8246 if (xmlRelaxNGValidateElementEnd(ctxt, 0) == 0) {
8255 ctxt->flags |= FLAGS_IGNORABLE;
8256 xmlRelaxNGLogBestError(ctxt);
8258 for (i = 0; i < ctxt->states->nbState; i++) {
8259 xmlRelaxNGFreeValidState(ctxt, ctxt->states->tabState[i]);
8261 xmlRelaxNGFreeStates(ctxt, ctxt->states);
8262 ctxt->states = NULL;
8264 ctxt->pstate = -1;
8265 ctxt->flags = oldflags;
8267 if (ctxt->pstate == -1) {
8268 if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
8269 xmlRelaxNGDumpValidError(ctxt);
8272 ctxt->state = oldstate;
8277 * @ctxt: the validation context
8287 xmlRelaxNGValidatePushElement(xmlRelaxNGValidCtxtPtr ctxt,
8293 if ((ctxt == NULL) || (elem == NULL))
8299 if (ctxt->elem == 0) {
8305 schema = ctxt->schema;
8317 ctxt->pdef = define;
8322 ctxt);
8326 xmlRelaxNGElemPush(ctxt, exec);
8328 ctxt->pnode = elem;
8329 ctxt->pstate = 0;
8332 xmlRegExecPushString2(ctxt->elem, elem->name, elem->ns->href,
8333 ctxt);
8335 ret = xmlRegExecPushString(ctxt->elem, elem->name, ctxt);
8340 if (ctxt->pstate == 0)
8342 else if (ctxt->pstate < 0)
8357 * @ctxt: the RelaxNG validation context
8366 xmlRelaxNGValidatePushCData(xmlRelaxNGValidCtxtPtr ctxt,
8371 if ((ctxt == NULL) || (ctxt->elem == NULL) || (data == NULL))
8386 ret = xmlRegExecPushString(ctxt->elem, BAD_CAST "#text", ctxt);
8400 * @ctxt: the RelaxNG validation context
8409 xmlRelaxNGValidatePopElement(xmlRelaxNGValidCtxtPtr ctxt,
8416 if ((ctxt == NULL) || (ctxt->elem == NULL) || (elem == NULL))
8424 exec = xmlRelaxNGElemPop(ctxt);
8448 * @ctxt: the validation context
8458 xmlRelaxNGValidateFullElement(xmlRelaxNGValidCtxtPtr ctxt,
8465 if ((ctxt == NULL) || (ctxt->pdef == NULL) || (elem == NULL))
8470 state = xmlRelaxNGNewValidState(ctxt, elem->parent);
8475 ctxt->state = state;
8476 ctxt->errNo = XML_RELAXNG_OK;
8477 ret = xmlRelaxNGValidateDefinition(ctxt, ctxt->pdef);
8478 if ((ret != 0) || (ctxt->errNo != XML_RELAXNG_OK))
8482 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
8483 ctxt->state = NULL;
8497 static int xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
8502 * @ctxt: a schema validation context
8510 xmlRelaxNGSkipIgnored(xmlRelaxNGValidCtxtPtr ctxt ATTRIBUTE_UNUSED,
8523 ((ctxt->flags & FLAGS_MIXED_CONTENT) ||
8532 * @ctxt: a schema validation context
8541 xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt, const xmlChar * str)
8556 xmlRngVErrMemory(ctxt, "validating\n");
8578 * @ctxt: a Relax-NG validation context
8588 xmlRelaxNGValidateDatatype(xmlRelaxNGValidCtxtPtr ctxt,
8637 oldvalue = ctxt->state->value;
8638 oldendvalue = ctxt->state->endvalue;
8639 ctxt->state->value = (xmlChar *) value;
8640 ctxt->state->endvalue = NULL;
8641 ret = xmlRelaxNGValidateValue(ctxt, define->content);
8642 ctxt->state->value = (xmlChar *) oldvalue;
8643 ctxt->state->endvalue = (xmlChar *) oldendvalue;
8652 * @ctxt: a Relax-NG validation context
8659 xmlRelaxNGNextValue(xmlRelaxNGValidCtxtPtr ctxt)
8663 cur = ctxt->state->value;
8664 if ((cur == NULL) || (ctxt->state->endvalue == NULL)) {
8665 ctxt->state->value = NULL;
8666 ctxt->state->endvalue = NULL;
8671 while ((cur != ctxt->state->endvalue) && (*cur == 0))
8673 if (cur == ctxt->state->endvalue)
8674 ctxt->state->value = NULL;
8676 ctxt->state->value = cur;
8682 * @ctxt: a Relax-NG validation context
8690 xmlRelaxNGValidateValueList(xmlRelaxNGValidCtxtPtr ctxt,
8696 ret = xmlRelaxNGValidateValue(ctxt, defines);
8706 * @ctxt: a Relax-NG validation context
8714 xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
8720 value = ctxt->state->value;
8745 value, ctxt->state->node);
8764 nval = xmlRelaxNGNormalize(ctxt, define->value);
8765 nvalue = xmlRelaxNGNormalize(ctxt, value);
8777 xmlRelaxNGNextValue(ctxt);
8781 ret = xmlRelaxNGValidateDatatype(ctxt, value, define,
8782 ctxt->state->seq);
8784 xmlRelaxNGNextValue(ctxt);
8792 oldflags = ctxt->flags;
8793 ctxt->flags |= FLAGS_IGNORABLE;
8795 oldvalue = ctxt->state->value;
8797 ret = xmlRelaxNGValidateValue(ctxt, list);
8801 ctxt->state->value = oldvalue;
8804 ctxt->flags = oldflags;
8806 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
8807 xmlRelaxNGDumpValidError(ctxt);
8809 if (ctxt->errNr > 0)
8810 xmlRelaxNGPopErrors(ctxt, 0);
8822 oldvalue = ctxt->state->value;
8823 oldend = ctxt->state->endvalue;
8852 ctxt->state->endvalue = cur;
8854 while ((*cur == 0) && (cur != ctxt->state->endvalue))
8857 ctxt->state->value = cur;
8860 if (ctxt->state->value == ctxt->state->endvalue)
8861 ctxt->state->value = NULL;
8862 ret = xmlRelaxNGValidateValue(ctxt, list);
8867 ctxt->state->value, nb_values);
8877 if ((ret == 0) && (ctxt->state->value != NULL) &&
8878 (ctxt->state->value != ctxt->state->endvalue)) {
8880 ctxt->state->value);
8884 ctxt->state->value = oldvalue;
8885 ctxt->state->endvalue = oldend;
8889 ret = xmlRelaxNGValidateValueList(ctxt, define->content);
8897 if ((ctxt->state->value == NULL) ||
8898 (*ctxt->state->value == 0)) {
8902 oldflags = ctxt->flags;
8903 ctxt->flags |= FLAGS_IGNORABLE;
8904 cur = ctxt->state->value;
8906 while ((cur != NULL) && (cur != ctxt->state->endvalue) &&
8910 xmlRelaxNGValidateValueList(ctxt, define->content);
8912 ctxt->state->value = temp;
8916 cur = ctxt->state->value;
8918 ctxt->flags = oldflags;
8919 if (ctxt->errNr > 0)
8920 xmlRelaxNGPopErrors(ctxt, 0);
8926 if ((ctxt->state->value == NULL) ||
8927 (*ctxt->state->value == 0)) {
8931 oldflags = ctxt->flags;
8932 ctxt->flags |= FLAGS_IGNORABLE;
8933 temp = ctxt->state->value;
8934 ret = xmlRelaxNGValidateValue(ctxt, define->content);
8935 ctxt->flags = oldflags;
8937 ctxt->state->value = temp;
8938 if (ctxt->errNr > 0)
8939 xmlRelaxNGPopErrors(ctxt, 0);
8943 if (ctxt->errNr > 0)
8944 xmlRelaxNGPopErrors(ctxt, 0);
8952 ret = xmlRelaxNGValidateValue(ctxt, list);
8968 ret = xmlRelaxNGValidateValue(ctxt, list);
8984 ret = xmlRelaxNGValidateValue(ctxt, define->content);
8995 * @ctxt: a Relax-NG validation context
9003 xmlRelaxNGValidateValueContent(xmlRelaxNGValidCtxtPtr ctxt,
9009 ret = xmlRelaxNGValidateValue(ctxt, defines);
9019 * @ctxt: a Relax-NG validation context
9028 xmlRelaxNGAttributeMatch(xmlRelaxNGValidCtxtPtr ctxt,
9055 ret = xmlRelaxNGAttributeMatch(ctxt, list, prop);
9067 ret = xmlRelaxNGAttributeMatch(ctxt, list, prop);
9082 * @ctxt: a Relax-NG validation context
9090 xmlRelaxNGValidateAttribute(xmlRelaxNGValidCtxtPtr ctxt,
9098 if (ctxt->state->nbAttrLeft <= 0)
9101 for (i = 0; i < ctxt->state->nbAttrs; i++) {
9102 tmp = ctxt->state->attrs[i];
9115 oldvalue = ctxt->state->value;
9116 oldseq = ctxt->state->seq;
9117 ctxt->state->seq = (xmlNodePtr) prop;
9118 ctxt->state->value = value;
9119 ctxt->state->endvalue = NULL;
9120 ret = xmlRelaxNGValidateValueContent(ctxt, define->content);
9121 if (ctxt->state->value != NULL)
9122 value = ctxt->state->value;
9125 ctxt->state->value = oldvalue;
9126 ctxt->state->seq = oldseq;
9131 ctxt->state->attrs[i] = NULL;
9132 ctxt->state->nbAttrLeft--;
9143 for (i = 0; i < ctxt->state->nbAttrs; i++) {
9144 tmp = ctxt->state->attrs[i];
9146 (xmlRelaxNGAttributeMatch(ctxt, define, tmp) == 1)) {
9153 oldvalue = ctxt->state->value;
9154 oldseq = ctxt->state->seq;
9155 ctxt->state->seq = (xmlNodePtr) prop;
9156 ctxt->state->value = value;
9157 ret = xmlRelaxNGValidateValueContent(ctxt, define->content);
9158 if (ctxt->state->value != NULL)
9159 value = ctxt->state->value;
9162 ctxt->state->value = oldvalue;
9163 ctxt->state->seq = oldseq;
9168 ctxt->state->attrs[i] = NULL;
9169 ctxt->state->nbAttrLeft--;
9192 * @ctxt: a Relax-NG validation context
9200 xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt,
9210 if (xmlRelaxNGValidateAttribute(ctxt, cur) != 0)
9221 if ((ctxt->state != NULL) || (ctxt->states != NULL)) {
9222 res = xmlRelaxNGValidateDefinition(ctxt, cur);
9275 * @ctxt: a Relax-NG validation context
9283 xmlRelaxNGValidateInterleave(xmlRelaxNGValidCtxtPtr ctxt,
9287 int errNr = ctxt->errNr;
9306 oldflags = ctxt->flags;
9308 ctxt->flags |= FLAGS_MIXED_CONTENT;
9313 if (ctxt->state != NULL)
9314 ctxt->state->seq = xmlRelaxNGSkipIgnored(ctxt,
9315 ctxt->state->seq);
9317 ret = xmlRelaxNGValidateDefinition(ctxt,
9321 ret = xmlRelaxNGValidateDefinition(ctxt,
9325 if (ctxt->state != NULL)
9326 ctxt->state->seq = xmlRelaxNGSkipIgnored(ctxt,
9327 ctxt->state->
9330 ctxt->flags = oldflags;
9341 xmlRngVErrMemory(ctxt, "validating\n");
9347 xmlRngVErrMemory(ctxt, "validating\n");
9356 cur = ctxt->state->seq;
9357 cur = xmlRelaxNGSkipIgnored(ctxt, cur);
9360 ctxt->state->seq = cur;
9423 cur = xmlRelaxNGSkipIgnored(ctxt, cur->next);
9431 oldstate = ctxt->state;
9433 ctxt->state = xmlRelaxNGCopyValidState(ctxt, oldstate);
9434 if (ctxt->state == NULL) {
9443 ctxt->state->seq = list[i];
9444 ret = xmlRelaxNGValidateDefinition(ctxt, group->rule);
9447 if (ctxt->state != NULL) {
9448 cur = ctxt->state->seq;
9449 cur = xmlRelaxNGSkipIgnored(ctxt, cur);
9450 xmlRelaxNGFreeValidState(ctxt, oldstate);
9451 oldstate = ctxt->state;
9452 ctxt->state = NULL;
9456 ctxt->state = oldstate;
9459 } else if (ctxt->states != NULL) {
9469 for (j = 0; j < ctxt->states->nbState; j++) {
9470 cur = ctxt->states->tabState[j]->seq;
9471 cur = xmlRelaxNGSkipIgnored(ctxt, cur);
9474 lowattr = ctxt->states->tabState[j]->nbAttrLeft;
9478 if (ctxt
9480 lowattr = ctxt->states->tabState[j]->nbAttrLeft;
9487 lowattr = ctxt->states->tabState[j]->nbAttrLeft;
9490 if (ctxt->states->tabState[j]->nbAttrLeft <= lowattr) {
9492 lowattr = ctxt->states->tabState[j]->nbAttrLeft;
9500 if (ctxt->states->nbState > 0) {
9501 xmlRelaxNGFreeValidState(ctxt, oldstate);
9503 oldstate = ctxt->states->tabState[best];
9504 ctxt->states->tabState[best] = NULL;
9507 ctxt->states->tabState[ctxt->states->nbState - 1];
9508 ctxt->states->tabState[ctxt->states->nbState - 1] = NULL;
9509 ctxt->states->nbState--;
9512 for (j = 0; j < ctxt->states->nbState ; j++) {
9513 xmlRelaxNGFreeValidState(ctxt, ctxt->states->tabState[j]);
9515 xmlRelaxNGFreeStates(ctxt, ctxt->states);
9516 ctxt->states = NULL;
9525 ctxt->state = oldstate;
9536 if (ctxt->state != NULL)
9537 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
9538 ctxt->state = oldstate;
9539 ctxt->state->seq = lastelem;
9547 ctxt->flags = oldflags;
9559 if (ctxt->errNr > errNr)
9560 xmlRelaxNGPopErrors(ctxt, errNr);
9570 * @ctxt: a Relax-NG validation context
9578 xmlRelaxNGValidateDefinitionList(xmlRelaxNGValidCtxtPtr ctxt,
9590 if ((ctxt->state != NULL) || (ctxt->states != NULL)) {
9591 res = xmlRelaxNGValidateDefinition(ctxt, defines);
9608 * @ctxt: a Relax-NG validation context
9617 xmlRelaxNGElementMatch(xmlRelaxNGValidCtxtPtr ctxt,
9653 if (ctxt != NULL) {
9654 oldflags = ctxt->flags;
9655 ctxt->flags |= FLAGS_IGNORABLE;
9660 ret = xmlRelaxNGElementMatch(ctxt, list, elem);
9662 if (ctxt != NULL)
9663 ctxt->flags = oldflags;
9667 if (ctxt != NULL)
9668 ctxt->flags = oldflags;
9674 if (ctxt != NULL) {
9675 ctxt->flags = oldflags;
9680 if (ctxt != NULL) {
9681 oldflags = ctxt->flags;
9682 ctxt->flags |= FLAGS_IGNORABLE;
9687 ret = xmlRelaxNGElementMatch(ctxt, list, elem);
9689 if (ctxt != NULL)
9690 ctxt->flags = oldflags;
9694 if (ctxt != NULL)
9695 ctxt->flags = oldflags;
9700 if (ctxt != NULL) {
9702 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9703 xmlRelaxNGDumpValidError(ctxt);
9705 if (ctxt->errNr > 0)
9706 xmlRelaxNGPopErrors(ctxt, 0);
9710 if (ctxt != NULL) {
9711 ctxt->flags = oldflags;
9721 * @ctxt: a Relax-NG validation context
9723 * Find the "best" state in the ctxt->states list of states to report
9731 xmlRelaxNGBestState(xmlRelaxNGValidCtxtPtr ctxt)
9738 if ((ctxt == NULL) || (ctxt->states == NULL) ||
9739 (ctxt->states->nbState <= 0))
9742 for (i = 0; i < ctxt->states->nbState; i++) {
9743 state = ctxt->states->tabState[i];
9764 * @ctxt: a Relax-NG validation context
9766 * Find the "best" state in the ctxt->states list of states to report
9770 xmlRelaxNGLogBestError(xmlRelaxNGValidCtxtPtr ctxt)
9774 if ((ctxt == NULL) || (ctxt->states == NULL) ||
9775 (ctxt->states->nbState <= 0))
9778 best = xmlRelaxNGBestState(ctxt);
9779 if ((best >= 0) && (best < ctxt->states->nbState)) {
9780 ctxt->state = ctxt->states->tabState[best];
9782 xmlRelaxNGValidateElementEnd(ctxt, 1);
9788 * @ctxt: a Relax-NG validation context
9798 xmlRelaxNGValidateElementEnd(xmlRelaxNGValidCtxtPtr ctxt, int dolog)
9803 state = ctxt->state;
9805 state->seq = xmlRelaxNGSkipIgnored(ctxt, state->seq);
9828 * @ctxt: a Relax-NG validation context
9836 xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt,
9848 if (ctxt->state != NULL) {
9849 node = ctxt->state->seq;
9854 for (i = 0; i < ctxt->depth; i++)
9865 ctxt->depth++;
9868 xmlRelaxNGSkipIgnored(ctxt, node);
9881 ctxt->state->seq = node;
9884 errNr = ctxt->errNr;
9885 node = xmlRelaxNGSkipIgnored(ctxt, node);
9889 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9890 xmlRelaxNGDumpValidError(ctxt);
9896 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9897 xmlRelaxNGDumpValidError(ctxt);
9905 ctxt->state->seq = xmlRelaxNGSkipIgnored(ctxt, node->next);
9906 if (ctxt->errNr > errNr)
9907 xmlRelaxNGPopErrors(ctxt, errNr);
9908 if (ctxt->errNr != 0) {
9909 while ((ctxt->err != NULL) &&
9910 (((ctxt->err->err == XML_RELAXNG_ERR_ELEMNAME)
9911 && (xmlStrEqual(ctxt->err->arg2, node->name)))
9913 ((ctxt->err->err ==
9915 && (xmlStrEqual(ctxt->err->arg1, node->name)))
9916 || (ctxt->err->err == XML_RELAXNG_ERR_NOELEM)
9917 || (ctxt->err->err ==
9919 xmlRelaxNGValidErrorPop(ctxt);
9924 ret = xmlRelaxNGElementMatch(ctxt, define, node);
9927 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9928 xmlRelaxNGDumpValidError(ctxt);
9932 if (ctxt->errNr != 0) {
9933 if (ctxt->errNr > errNr)
9934 xmlRelaxNGPopErrors(ctxt, errNr);
9935 while ((ctxt->err != NULL) &&
9936 (((ctxt->err->err == XML_RELAXNG_ERR_ELEMNAME) &&
9937 (xmlStrEqual(ctxt->err->arg2, node->name))) ||
9938 ((ctxt->err->err == XML_RELAXNG_ERR_ELEMEXTRANS) &&
9939 (xmlStrEqual(ctxt->err->arg1, node->name))) ||
9940 (ctxt->err->err == XML_RELAXNG_ERR_NOELEM) ||
9941 (ctxt->err->err == XML_RELAXNG_ERR_NOTELEM)))
9942 xmlRelaxNGValidErrorPop(ctxt);
9944 errNr = ctxt->errNr;
9946 oldflags = ctxt->flags;
9947 if (ctxt->flags & FLAGS_MIXED_CONTENT) {
9948 ctxt->flags -= FLAGS_MIXED_CONTENT;
9950 state = xmlRelaxNGNewValidState(ctxt, node);
9953 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9954 xmlRelaxNGDumpValidError(ctxt);
9958 oldstate = ctxt->state;
9959 ctxt->state = state;
9961 tmp = xmlRelaxNGValidateAttributeList(ctxt, define->attrs);
9968 xmlRelaxNGValidStatePtr nstate, tmpstate = ctxt->state;
9969 xmlRelaxNGStatesPtr tmpstates = ctxt->states;
9972 nstate = xmlRelaxNGNewValidState(ctxt, node);
9973 ctxt->state = nstate;
9974 ctxt->states = NULL;
9976 tmp = xmlRelaxNGValidateCompiledContent(ctxt,
9978 ctxt->state->seq);
9979 nseq = ctxt->state->seq;
9980 ctxt->state = tmpstate;
9981 ctxt->states = tmpstates;
9982 xmlRelaxNGFreeValidState(ctxt, nstate);
9992 if (ctxt->states != NULL) {
9995 for (i = 0; i < ctxt->states->nbState; i++) {
9996 state = ctxt->states->tabState[i];
9997 ctxt->state = state;
9998 ctxt->state->seq = nseq;
10000 if (xmlRelaxNGValidateElementEnd(ctxt, 0) == 0) {
10009 ctxt->flags |= FLAGS_IGNORABLE;
10010 xmlRelaxNGLogBestError(ctxt);
10012 for (i = 0; i < ctxt->states->nbState; i++) {
10013 xmlRelaxNGFreeValidState(ctxt,
10014 ctxt->states->
10017 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10018 ctxt->flags = oldflags;
10019 ctxt->states = NULL;
10023 state = ctxt->state;
10024 if (ctxt->state != NULL)
10025 ctxt->state->seq = nseq;
10027 ret = xmlRelaxNGValidateElementEnd(ctxt, 1);
10028 xmlRelaxNGFreeValidState(ctxt, state);
10032 tmp = xmlRelaxNGValidateDefinitionList(ctxt,
10037 if (ctxt->state == NULL) {
10038 ctxt->state = oldstate;
10041 ctxt->state = NULL;
10049 if (ctxt->states != NULL) {
10052 for (i = 0; i < ctxt->states->nbState; i++) {
10053 state = ctxt->states->tabState[i];
10054 ctxt->state = state;
10056 if (xmlRelaxNGValidateElementEnd(ctxt, 0) == 0) {
10065 ctxt->flags |= FLAGS_IGNORABLE;
10066 xmlRelaxNGLogBestError(ctxt);
10068 for (i = 0; i < ctxt->states->nbState; i++) {
10069 xmlRelaxNGFreeValidState(ctxt,
10070 ctxt->states->tabState[i]);
10071 ctxt->states->tabState[i] = NULL;
10073 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10074 ctxt->flags = oldflags;
10075 ctxt->states = NULL;
10079 state = ctxt->state;
10081 ret = xmlRelaxNGValidateElementEnd(ctxt, 1);
10082 xmlRelaxNGFreeValidState(ctxt, state);
10088 ctxt->flags = oldflags;
10089 ctxt->state = oldstate;
10091 oldstate->seq = xmlRelaxNGSkipIgnored(ctxt, node->next);
10093 if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
10094 xmlRelaxNGDumpValidError(ctxt);
10102 if (ctxt->errNr > errNr)
10103 xmlRelaxNGPopErrors(ctxt, errNr);
10123 errNr = ctxt->errNr;
10124 oldflags = ctxt->flags;
10125 ctxt->flags |= FLAGS_IGNORABLE;
10126 oldstate = xmlRelaxNGCopyValidState(ctxt, ctxt->state);
10128 xmlRelaxNGValidateDefinitionList(ctxt,
10131 if (ctxt->state != NULL)
10132 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10133 ctxt->state = oldstate;
10134 ctxt->flags = oldflags;
10136 if (ctxt->errNr > errNr)
10137 xmlRelaxNGPopErrors(ctxt, errNr);
10140 if (ctxt->states != NULL) {
10141 xmlRelaxNGAddStates(ctxt, ctxt->states, oldstate);
10143 ctxt->states = xmlRelaxNGNewStates(ctxt, 1);
10144 if (ctxt->states == NULL) {
10145 xmlRelaxNGFreeValidState(ctxt, oldstate);
10146 ctxt->flags = oldflags;
10148 if (ctxt->errNr > errNr)
10149 xmlRelaxNGPopErrors(ctxt, errNr);
10152 xmlRelaxNGAddStates(ctxt, ctxt->states, oldstate);
10153 xmlRelaxNGAddStates(ctxt, ctxt->states, ctxt->state);
10154 ctxt->state = NULL;
10156 ctxt->flags = oldflags;
10158 if (ctxt->errNr > errNr)
10159 xmlRelaxNGPopErrors(ctxt, errNr);
10163 errNr = ctxt->errNr;
10164 ret = xmlRelaxNGValidateDefinitionList(ctxt, define->content);
10168 if (ctxt->errNr > errNr)
10169 xmlRelaxNGPopErrors(ctxt, errNr);
10176 errNr = ctxt->errNr;
10177 res = xmlRelaxNGNewStates(ctxt, 1);
10185 if (ctxt->state != NULL) {
10186 xmlRelaxNGAddStates(ctxt, res,
10187 xmlRelaxNGCopyValidState(ctxt,
10188 ctxt->
10191 for (j = 0; j < ctxt->states->nbState; j++) {
10192 xmlRelaxNGAddStates(ctxt, res,
10193 xmlRelaxNGCopyValidState(ctxt,
10194 ctxt->states->tabState[j]));
10197 oldflags = ctxt->flags;
10198 ctxt->flags |= FLAGS_IGNORABLE;
10203 if (ctxt->states != NULL) {
10204 states = ctxt->states;
10206 ctxt->state = states->tabState[i];
10207 ctxt->states = NULL;
10208 ret = xmlRelaxNGValidateDefinitionList(ctxt,
10212 if (ctxt->state != NULL) {
10213 tmp = xmlRelaxNGAddStates(ctxt, res,
10214 ctxt->state);
10215 ctxt->state = NULL;
10218 } else if (ctxt->states != NULL) {
10219 for (j = 0; j < ctxt->states->nbState;
10222 xmlRelaxNGAddStates(ctxt, res,
10223 ctxt->states->tabState[j]);
10227 xmlRelaxNGFreeStates(ctxt,
10228 ctxt->states);
10229 ctxt->states = NULL;
10232 if (ctxt->state != NULL) {
10233 xmlRelaxNGFreeValidState(ctxt,
10234 ctxt->state);
10235 ctxt->state = NULL;
10240 ret = xmlRelaxNGValidateDefinitionList(ctxt,
10244 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10245 ctxt->state = NULL;
10248 if (ctxt->state != NULL) {
10249 tmp = xmlRelaxNGAddStates(ctxt, res,
10250 ctxt->state);
10251 ctxt->state = NULL;
10254 } else if (ctxt->states != NULL) {
10255 for (j = 0; j < ctxt->states->nbState; j++) {
10256 tmp = xmlRelaxNGAddStates(ctxt, res,
10257 ctxt->states->tabState[j]);
10262 states = ctxt->states;
10264 xmlRelaxNGFreeStates(ctxt,
10265 ctxt->states);
10267 ctxt->states = NULL;
10277 ctxt->state = xmlRelaxNGCopyValidState(ctxt,
10283 xmlRelaxNGNewStates(ctxt,
10285 states = ctxt->states;
10293 xmlRelaxNGAddStates(ctxt, states,
10295 (ctxt, res->tabState[i]));
10296 ctxt->states = states;
10301 xmlRelaxNGFreeStates(ctxt, states);
10303 ctxt->states = res;
10304 ctxt->flags = oldflags;
10309 if (ctxt->errNr > errNr)
10310 xmlRelaxNGPopErrors(ctxt, errNr);
10319 node = xmlRelaxNGSkipIgnored(ctxt, node);
10321 errNr = ctxt->errNr;
10361 ret = xmlRelaxNGValidateDefinition(ctxt, list);
10368 oldflags = ctxt
10369 ctxt->flags |= FLAGS_IGNORABLE;
10372 oldstate = xmlRelaxNGCopyValidState(ctxt, ctxt->state);
10373 ret = xmlRelaxNGValidateDefinition(ctxt, list);
10376 states = xmlRelaxNGNewStates(ctxt, 1);
10378 if (ctxt->state != NULL) {
10379 xmlRelaxNGAddStates(ctxt, states, ctxt->state);
10380 } else if (ctxt->states != NULL) {
10381 for (i = 0; i < ctxt->states->nbState; i++) {
10382 xmlRelaxNGAddStates(ctxt, states,
10383 ctxt->states->
10386 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10387 ctxt->states = NULL;
10390 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10392 ctxt->state = oldstate;
10396 xmlRelaxNGFreeValidState(ctxt, oldstate);
10397 ctxt->states = states;
10398 ctxt->state = NULL;
10401 ctxt->states = NULL;
10403 ctxt->flags = oldflags;
10405 if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
10406 xmlRelaxNGDumpValidError(ctxt);
10409 if (ctxt->errNr > errNr)
10410 xmlRelaxNGPopErrors(ctxt, errNr);
10416 ret = xmlRelaxNGValidateDefinitionList(ctxt, define->content);
10419 ret = xmlRelaxNGValidateInterleave(ctxt, define);
10422 ret = xmlRelaxNGValidateAttribute(ctxt, define);
10429 ret = xmlRelaxNGValidateDefinition(ctxt, define->content);
10457 xmlRngVErrMemory(ctxt, "validating\n");
10462 ret = xmlRelaxNGValidateDatatype(ctxt, content, define,
10463 ctxt->state->seq);
10467 ctxt->state->seq = NULL;
10500 xmlRngVErrMemory(ctxt, "validating\n");
10505 oldvalue = ctxt->state->value;
10506 ctxt->state->value = content;
10507 ret = xmlRelaxNGValidateValue(ctxt, define);
10508 ctxt->state->value = oldvalue;
10512 ctxt->state->seq = NULL;
10551 xmlRngVErrMemory(ctxt, "validating\n");
10557 oldvalue = ctxt->state->value;
10558 oldendvalue = ctxt->state->endvalue;
10559 ctxt->state->value = content;
10560 ctxt->state->endvalue = content + len;
10561 ret = xmlRelaxNGValidateValue(ctxt, define);
10562 ctxt->state->value = oldvalue;
10563 ctxt->state->endvalue = oldendvalue;
10567 ctxt->state->seq = node->next;
10578 ctxt->depth--;
10580 for (i = 0; i < ctxt->depth; i++)
10596 * @ctxt: a Relax-NG validation context
10604 xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt,
10611 * We should NOT have both ctxt->state and ctxt->states
10613 if ((ctxt->state != NULL) && (ctxt->states != NULL)) {
10614 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10615 ctxt->state = NULL;
10618 if ((ctxt->states == NULL) || (ctxt->states->nbState == 1)) {
10619 if (ctxt->states != NULL) {
10620 ctxt->state = ctxt->states->tabState[0];
10621 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10622 ctxt->states = NULL;
10624 ret = xmlRelaxNGValidateState(ctxt, define);
10625 if ((ctxt->state != NULL) && (ctxt->states != NULL)) {
10626 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10627 ctxt->state = NULL;
10629 if ((ctxt->states != NULL) && (ctxt->states->nbState == 1)) {
10630 ctxt->state = ctxt->states->tabState[0];
10631 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10632 ctxt->states = NULL;
10637 states = ctxt->states;
10638 ctxt->states = NULL;
10641 oldflags = ctxt->flags;
10642 ctxt->flags |= FLAGS_IGNORABLE;
10644 ctxt->state = states->tabState[i];
10645 ctxt->states = NULL;
10646 ret = xmlRelaxNGValidateState(ctxt, define);
10648 * We should NOT have both ctxt->state and ctxt->states
10650 if ((ctxt->state != NULL) && (ctxt->states != NULL)) {
10651 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10652 ctxt->state = NULL;
10655 if (ctxt->states == NULL) {
10658 xmlRelaxNGAddStates(ctxt, res, ctxt->state);
10659 ctxt->state = NULL;
10662 states->tabState[j++] = ctxt->state;
10663 ctxt->state = NULL;
10668 res = ctxt->states;
10669 ctxt->states = NULL;
10671 xmlRelaxNGAddStates(ctxt, res,
10675 for (k = 0; k < ctxt->states->nbState; k++)
10676 xmlRelaxNGAddStates(ctxt, res,
10677 ctxt->states->tabState[k]);
10678 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10679 ctxt->states = NULL;
10683 if (ctxt->state != NULL) {
10684 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10685 ctxt->state = NULL;
10686 } else if (ctxt->states != NULL) {
10687 for (k = 0; k < ctxt->states->nbState; k++)
10688 xmlRelaxNGFreeValidState(ctxt,
10689 ctxt->states->tabState[k]);
10690 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10691 ctxt->states = NULL;
10695 ctxt->flags = oldflags;
10697 xmlRelaxNGFreeStates(ctxt, states);
10698 ctxt->states = res;
10702 ctxt->states = states;
10705 ctxt->state = states->tabState[0];
10706 xmlRelaxNGFreeStates(ctxt, states);
10710 xmlRelaxNGFreeStates(ctxt, states);
10711 if (ctxt->states != NULL) {
10712 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10713 ctxt->states = NULL;
10716 if ((ctxt->state != NULL) && (ctxt->states != NULL)) {
10717 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10718 ctxt->state = NULL;
10725 * @ctxt: a Relax-NG validation context
10733 xmlRelaxNGValidateDocument(xmlRelaxNGValidCtxtPtr ctxt, xmlDocPtr doc)
10741 if ((ctxt == NULL) || (ctxt->schema == NULL) || (doc == NULL))
10744 ctxt->errNo = XML_RELAXNG_OK;
10745 schema = ctxt->schema;
10751 state = xmlRelaxNGNewValidState(ctxt, NULL);
10752 ctxt->state = state;
10753 ret = xmlRelaxNGValidateDefinition(ctxt, grammar->start);
10754 if ((ctxt->state != NULL) && (state->seq != NULL)) {
10755 state = ctxt->state;
10757 node = xmlRelaxNGSkipIgnored(ctxt, node);
10764 } else if (ctxt->states != NULL) {
10768 for (i = 0; i < ctxt->states->nbState; i++) {
10769 state = ctxt->states->tabState[i];
10771 node = xmlRelaxNGSkipIgnored(ctxt, node);
10774 xmlRelaxNGFreeValidState(ctxt, state);
10783 if (ctxt->state != NULL) {
10784 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10785 ctxt->state = NULL;
10788 xmlRelaxNGDumpValidError(ctxt);
10790 else if (ctxt->errNr != 0) {
10791 ctxt->error(ctxt->userData,
10793 ctxt->errNr);
10794 xmlRelaxNGDumpValidError(ctxt);
10798 if (ctxt->idref == 1) {
10803 vctxt.error = ctxt->error;
10804 vctxt.warning = ctxt->warning;
10805 vctxt.userData = ctxt->userData;
10811 if ((ret == 0) && (ctxt->errNo != XML_RELAXNG_OK))
10914 * @ctxt: the schema validation context
10919 xmlRelaxNGFreeValidCtxt(xmlRelaxNGValidCtxtPtr ctxt)
10923 if (ctxt == NULL)
10925 if (ctxt->states != NULL)
10926 xmlRelaxNGFreeStates(NULL, ctxt->states);
10927 if (ctxt->freeState != NULL) {
10928 for (k = 0; k < ctxt->freeState->nbState; k++) {
10929 xmlRelaxNGFreeValidState(NULL, ctxt->freeState->tabState[k]);
10931 xmlRelaxNGFreeStates(NULL, ctxt->freeState);
10933 if (ctxt->freeStates != NULL) {
10934 for (k = 0; k < ctxt->freeStatesNr; k++) {
10935 xmlRelaxNGFreeStates(NULL, ctxt->freeStates[k]);
10937 xmlFree(ctxt->freeStates);
10939 if (ctxt->errTab != NULL)
10940 xmlFree(ctxt->errTab);
10941 if (ctxt->elemTab != NULL) {
10944 exec = xmlRelaxNGElemPop(ctxt);
10947 exec = xmlRelaxNGElemPop(ctxt);
10949 xmlFree(ctxt->elemTab);
10951 xmlFree(ctxt);
10956 * @ctxt: a Relax-NG validation context
10964 xmlRelaxNGSetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
10968 if (ctxt == NULL)
10970 ctxt->error = err;
10971 ctxt->warning = warn;
10972 ctxt->userData = ctx;
10973 ctxt->serror = NULL;
10978 * @ctxt: a Relax-NG validation context
10985 xmlRelaxNGSetValidStructuredErrors(xmlRelaxNGValidCtxtPtr ctxt,
10988 if (ctxt == NULL)
10990 ctxt->serror = serror;
10991 ctxt->error = NULL;
10992 ctxt->warning = NULL;
10993 ctxt->userData = ctx;
10998 * @ctxt: a Relax-NG validation context
11008 xmlRelaxNGGetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
11012 if (ctxt == NULL)
11015 *err = ctxt->error;
11017 *warn = ctxt->warning;
11019 *ctx = ctxt->userData;
11025 * @ctxt: a Relax-NG validation context
11034 xmlRelaxNGValidateDoc(xmlRelaxNGValidCtxtPtr ctxt, xmlDocPtr doc)
11038 if ((ctxt == NULL) || (doc == NULL))
11041 ctxt->doc = doc;
11043 ret = xmlRelaxNGValidateDocument(ctxt, doc);