Lines Matching full:ctxt
428 * @ctxt: an Relax-NG parser context
434 xmlRngPErrMemory(xmlRelaxNGParserCtxtPtr ctxt, const char *extra)
440 if (ctxt != NULL) {
441 if (ctxt->serror != NULL)
442 schannel = ctxt->serror;
444 channel = ctxt->error;
445 data = ctxt->userData;
446 ctxt->nbErrors++;
463 * @ctxt
469 xmlRngVErrMemory(xmlRelaxNGValidCtxtPtr ctxt, const char *extra)
475 if (ctxt != NULL) {
476 if (ctxt->serror != NULL)
477 schannel = ctxt->serror;
479 channel = ctxt->error;
480 data = ctxt->userData;
481 ctxt->nbErrors++;
498 * @ctxt: a Relax-NG parser context
508 xmlRngPErr(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node, int error,
515 if (ctxt != NULL) {
516 if (ctxt->serror != NULL)
517 schannel = ctxt->serror;
519 channel = ctxt->error;
520 data = ctxt->userData;
521 ctxt->nbErrors++;
532 * @ctxt: a Relax-NG validation context
542 xmlRngVErr(xmlRelaxNGValidCtxtPtr ctxt, xmlNodePtr node, int error,
549 if (ctxt != NULL) {
550 if (ctxt->serror != NULL)
551 schannel = ctxt->serror;
553 channel = ctxt->error;
554 data = ctxt->userData;
555 ctxt->nbErrors++;
663 static int xmlRelaxNGEqualValidState(xmlRelaxNGValidCtxtPtr ctxt
667 static void xmlRelaxNGFreeValidState(xmlRelaxNGValidCtxtPtr ctxt,
750 * @ctxt: a Relax-NG validation context (optional)
757 xmlRelaxNGNewRelaxNG(xmlRelaxNGParserCtxtPtr ctxt)
763 xmlRngPErrMemory(ctxt, NULL);
829 * @ctxt: a Relax-NG validation context (optional)
836 xmlRelaxNGNewGrammar(xmlRelaxNGParserCtxtPtr ctxt)
842 xmlRngPErrMemory(ctxt, NULL);
880 * @ctxt: a Relax-NG validation context
888 xmlRelaxNGNewDefine(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
892 if (ctxt->defMax == 0) {
893 ctxt->defMax = 16;
894 ctxt->defNr = 0;
895 ctxt->defTab = (xmlRelaxNGDefinePtr *)
896 xmlMalloc(ctxt->defMax * sizeof(xmlRelaxNGDefinePtr));
897 if (ctxt->defTab == NULL) {
898 xmlRngPErrMemory(ctxt, "allocating define\n");
901 } else if (ctxt->defMax <= ctxt->defNr) {
904 ctxt->defMax *= 2;
905 tmp = (xmlRelaxNGDefinePtr *) xmlRealloc(ctxt->defTab,
906 ctxt->defMax *
910 xmlRngPErrMemory(ctxt, "allocating define\n");
913 ctxt->defTab = tmp;
917 xmlRngPErrMemory(ctxt, "allocating define\n");
921 ctxt->defTab[ctxt->defNr++] = ret;
996 * @ctxt: a Relax-NG validation context
1004 xmlRelaxNGNewStates(xmlRelaxNGValidCtxtPtr ctxt, int size)
1008 if ((ctxt != NULL) &&
1009 (ctxt->freeState != NULL) && (ctxt->freeStatesNr > 0)) {
1010 ctxt->freeStatesNr--;
1011 ret = ctxt->freeStates[ctxt->freeStatesNr];
1023 xmlRngVErrMemory(ctxt, "allocating states\n");
1032 xmlRngVErrMemory(ctxt, "allocating states\n");
1041 * @ctxt: a Relax-NG validation context
1051 xmlRelaxNGAddStatesUniq(xmlRelaxNGValidCtxtPtr ctxt,
1068 xmlRngVErrMemory(ctxt, "adding states\n");
1080 * @ctxt: a Relax-NG validation context
1089 xmlRelaxNGAddStates(xmlRelaxNGValidCtxtPtr ctxt,
1108 xmlRngVErrMemory(ctxt, "adding states\n");
1115 if (xmlRelaxNGEqualValidState(ctxt, state, states->tabState[i])) {
1116 xmlRelaxNGFreeValidState(ctxt, state);
1126 * @ctxt: a Relax-NG validation context
1132 xmlRelaxNGFreeStates(xmlRelaxNGValidCtxtPtr ctxt,
1137 if ((ctxt != NULL) && (ctxt->freeStates == NULL)) {
1138 ctxt->freeStatesMax = 40;
1139 ctxt->freeStatesNr = 0;
1140 ctxt->freeStates = (xmlRelaxNGStatesPtr *)
1141 xmlMalloc(ctxt->freeStatesMax * sizeof(xmlRelaxNGStatesPtr));
1142 if (ctxt->freeStates == NULL) {
1143 xmlRngVErrMemory(ctxt, "storing states\n");
1145 } else if ((ctxt != NULL)
1146 && (ctxt->freeStatesNr >= ctxt->freeStatesMax)) {
1149 tmp = (xmlRelaxNGStatesPtr *) xmlRealloc(ctxt->freeStates,
1150 2 * ctxt->freeStatesMax *
1154 xmlRngVErrMemory(ctxt, "storing states\n");
1159 ctxt->freeStates = tmp;
1160 ctxt->freeStatesMax *= 2;
1162 if ((ctxt == NULL) || (ctxt->freeStates == NULL)) {
1166 ctxt->freeStates[ctxt->freeStatesNr++] = states;
1172 * @ctxt: a Relax-NG validation context
1180 xmlRelaxNGNewValidState(xmlRelaxNGValidCtxtPtr ctxt, xmlNodePtr node)
1189 root = xmlDocGetRootElement(ctxt->doc);
1202 if ((ctxt->freeState != NULL) && (ctxt->freeState->nbState > 0)) {
1203 ctxt->freeState->nbState--;
1204 ret = ctxt->freeState->tabState[ctxt->freeState->nbState];
1210 xmlRngVErrMemory(ctxt, "allocating states\n");
1218 ret->node = (xmlNodePtr) ctxt->doc;
1234 xmlRngVErrMemory(ctxt, "allocating states\n");
1243 xmlRngVErrMemory(ctxt, "allocating states\n");
1267 * @ctxt: a Relax-NG validation context
1275 xmlRelaxNGCopyValidState(xmlRelaxNGValidCtxtPtr ctxt,
1284 if ((ctxt->freeState != NULL) && (ctxt->freeState->nbState > 0)) {
1285 ctxt->freeState->nbState--;
1286 ret = ctxt->freeState->tabState[ctxt->freeState->nbState];
1292 xmlRngVErrMemory(ctxt, "allocating states\n");
1308 xmlRngVErrMemory(ctxt, "allocating states\n");
1318 xmlRngVErrMemory(ctxt, "allocating states\n");
1333 * @ctxt: a Relax-NG validation context
1342 xmlRelaxNGEqualValidState(xmlRelaxNGValidCtxtPtr ctxt ATTRIBUTE_UNUSED,
1379 xmlRelaxNGFreeValidState(xmlRelaxNGValidCtxtPtr ctxt,
1385 if ((ctxt != NULL) && (ctxt->freeState == NULL)) {
1386 ctxt->freeState = xmlRelaxNGNewStates(ctxt, 40);
1388 if ((ctxt == NULL) || (ctxt->freeState == NULL)) {
1393 xmlRelaxNGAddStatesUniq(ctxt, ctxt->freeState, state);
1405 * @ctxt: a RelaxNG parser context
1414 xmlRelaxParserSetFlag(xmlRelaxNGParserCtxtPtr ctxt, int flags)
1416 if (ctxt == NULL) return(-1);
1418 ctxt->crng |= XML_RELAXNGP_FREE_DOC;
1422 ctxt->crng |= XML_RELAXNGP_CRNG;
1434 static xmlDocPtr xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt,
1439 * @ctxt: the parser context
1447 xmlRelaxNGIncludePush(xmlRelaxNGParserCtxtPtr ctxt,
1450 if (ctxt->incTab == NULL) {
1451 ctxt->incMax = 4;
1452 ctxt->incNr = 0;
1453 ctxt->incTab =
1454 (xmlRelaxNGIncludePtr *) xmlMalloc(ctxt->incMax *
1455 sizeof(ctxt->incTab[0]));
1456 if (ctxt->incTab == NULL) {
1457 xmlRngPErrMemory(ctxt, "allocating include\n");
1461 if (ctxt->incNr >= ctxt->incMax) {
1462 ctxt->incMax *= 2;
1463 ctxt->incTab =
1464 (xmlRelaxNGIncludePtr *) xmlRealloc(ctxt->incTab,
1465 ctxt->incMax *
1466 sizeof(ctxt->incTab[0]));
1467 if (ctxt->incTab == NULL) {
1468 xmlRngPErrMemory(ctxt, "allocating include\n");
1472 ctxt->incTab[ctxt->incNr] = value;
1473 ctxt->inc = value;
1474 return (ctxt->incNr++);
1479 * @ctxt: the parser context
1486 xmlRelaxNGIncludePop(xmlRelaxNGParserCtxtPtr ctxt)
1490 if (ctxt->incNr <= 0)
1492 ctxt->incNr--;
1493 if (ctxt->incNr > 0)
1494 ctxt->inc = ctxt->incTab[ctxt->incNr - 1];
1496 ctxt->inc = NULL;
1497 ret = ctxt->incTab[ctxt->incNr];
1498 ctxt->incTab[ctxt->incNr] = NULL;
1504 * @ctxt: the parser context
1514 xmlRelaxNGRemoveRedefine(xmlRelaxNGParserCtxtPtr ctxt,
1561 if (xmlRelaxNGRemoveRedefine(ctxt, href,
1580 * @ctxt: the parser context
1592 xmlRelaxNGLoadInclude(xmlRelaxNGParserCtxtPtr ctxt, const xmlChar * URL,
1608 for (i = 0; i < ctxt->incNr; i++) {
1609 if (xmlStrEqual(ctxt->incTab[i]->href, URL)) {
1610 xmlRngPErr(ctxt, NULL, XML_RNGP_INCLUDE_RECURSE,
1622 xmlRngPErr(ctxt, node, XML_RNGP_PARSE_ERROR,
1635 xmlRngPErrMemory(ctxt, "allocating include\n");
1642 ret->next = ctxt->includes;
1643 ctxt->includes = ret;
1660 xmlRelaxNGIncludePush(ctxt, ret);
1670 doc = xmlRelaxNGCleanupDoc(ctxt, doc);
1672 ctxt->inc = NULL;
1679 xmlRelaxNGIncludePop(ctxt);
1689 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY,
1695 xmlRngPErr(ctxt, node, XML_RNGP_GRAMMAR_MISSING,
1710 xmlRelaxNGRemoveRedefine(ctxt, URL, root->children, NULL);
1712 xmlRngPErr(ctxt, node, XML_RNGP_START_MISSING,
1721 xmlRngPErr(ctxt, node, XML_RNGP_NAME_MISSING,
1728 found = xmlRelaxNGRemoveRedefine(ctxt, URL,
1731 xmlRngPErr(ctxt, node, XML_RNGP_DEFINE_MISSING,
1747 * @ctxt: the validation context
1758 xmlRelaxNGValidErrorPush(xmlRelaxNGValidCtxtPtr ctxt,
1766 "Pushing error %d at %d on stack\n", err, ctxt->errNr);
1768 if (ctxt->errTab == NULL) {
1769 ctxt->errMax = 8;
1770 ctxt->errNr = 0;
1771 ctxt->errTab =
1772 (xmlRelaxNGValidErrorPtr) xmlMalloc(ctxt->errMax *
1775 if (ctxt->errTab == NULL) {
1776 xmlRngVErrMemory(ctxt, "pushing error\n");
1779 ctxt->err = NULL;
1781 if (ctxt->errNr >= ctxt->errMax) {
1782 ctxt->errMax *= 2;
1783 ctxt->errTab =
1784 (xmlRelaxNGValidErrorPtr) xmlRealloc(ctxt->errTab,
1785 ctxt->errMax *
1788 if (ctxt->errTab == NULL) {
1789 xmlRngVErrMemory(ctxt, "pushing error\n");
1792 ctxt->err = &ctxt->errTab[ctxt->errNr - 1];
1794 if ((ctxt->err != NULL) && (ctxt->state != NULL) &&
1795 (ctxt->err->node == ctxt->state->node) && (ctxt->err->err == err))
1796 return (ctxt->errNr);
1797 cur = &ctxt->errTab[ctxt->errNr];
1808 if (ctxt->state != NULL) {
1809 cur->node = ctxt->state->node;
1810 cur->seq = ctxt->state->seq;
1815 ctxt->err = cur;
1816 return (ctxt->errNr++);
1821 * @ctxt: the validation context
1826 xmlRelaxNGValidErrorPop(xmlRelaxNGValidCtxtPtr ctxt)
1830 if (ctxt->errNr <= 0) {
1831 ctxt->err = NULL;
1834 ctxt->errNr--;
1835 if (ctxt->errNr > 0)
1836 ctxt->err = &ctxt->errTab[ctxt->errNr - 1];
1838 ctxt->err = NULL;
1839 cur = &ctxt->errTab[ctxt->errNr];
1853 * @ctxt: the parser context
1861 xmlRelaxNGDocumentPush(xmlRelaxNGParserCtxtPtr ctxt,
1864 if (ctxt->docTab == NULL) {
1865 ctxt->docMax = 4;
1866 ctxt->docNr = 0;
1867 ctxt->docTab =
1868 (xmlRelaxNGDocumentPtr *) xmlMalloc(ctxt->docMax *
1869 sizeof(ctxt->docTab[0]));
1870 if (ctxt->docTab == NULL) {
1871 xmlRngPErrMemory(ctxt, "adding document\n");
1875 if (ctxt->docNr >= ctxt->docMax) {
1876 ctxt->docMax *= 2;
1877 ctxt->docTab =
1878 (xmlRelaxNGDocumentPtr *) xmlRealloc(ctxt->docTab,
1879 ctxt->docMax *
1880 sizeof(ctxt->docTab[0]));
1881 if (ctxt->docTab == NULL) {
1882 xmlRngPErrMemory(ctxt, "adding document\n");
1886 ctxt->docTab[ctxt->docNr] = value;
1887 ctxt->doc = value;
1888 return (ctxt->docNr++);
1893 * @ctxt: the parser context
1900 xmlRelaxNGDocumentPop(xmlRelaxNGParserCtxtPtr ctxt)
1904 if (ctxt->docNr <= 0)
1906 ctxt->docNr--;
1907 if (ctxt->docNr > 0)
1908 ctxt->doc = ctxt->docTab[ctxt->docNr - 1];
1910 ctxt->doc = NULL;
1911 ret = ctxt->docTab[ctxt->docNr];
1912 ctxt->docTab[ctxt->docNr] = NULL;
1918 * @ctxt: the parser context
1929 xmlRelaxNGLoadExternalRef(xmlRelaxNGParserCtxtPtr ctxt,
1940 for (i = 0; i < ctxt->docNr; i++) {
1941 if (xmlStrEqual(ctxt->docTab[i]->href, URL)) {
1942 xmlRngPErr(ctxt, NULL, XML_RNGP_EXTERNALREF_RECURSE,
1954 xmlRngPErr(ctxt, NULL, XML_RNGP_PARSE_ERROR,
1964 xmlRngPErr(ctxt, (xmlNodePtr) doc, XML_ERR_NO_MEMORY,
1972 ret->next = ctxt->documents;
1973 ctxt->documents = ret;
1990 xmlRelaxNGDocumentPush(ctxt, ret);
1995 doc = xmlRelaxNGCleanupDoc(ctxt, doc);
1997 ctxt->doc = NULL;
2001 xmlRelaxNGDocumentPop(ctxt);
2012 #define VALID_ERR(a) xmlRelaxNGAddValidError(ctxt, a, NULL, NULL, 0);
2013 #define VALID_ERR2(a, b) xmlRelaxNGAddValidError(ctxt, a, b, NULL, 0);
2014 #define VALID_ERR3(a, b, c) xmlRelaxNGAddValidError(ctxt, a, b, c, 0);
2015 #define VALID_ERR2P(a, b) xmlRelaxNGAddValidError(ctxt, a, b, NULL, 1);
2016 #define VALID_ERR3P(a, b, c) xmlRelaxNGAddValidError(ctxt, a, b, c, 1);
2219 * @ctxt: the validation context
2229 xmlRelaxNGShowValidError(xmlRelaxNGValidCtxtPtr ctxt,
2236 if (ctxt->flags & FLAGS_NOERROR)
2246 if (ctxt->errNo == XML_RELAXNG_OK)
2247 ctxt->errNo = err;
2248 xmlRngVErr(ctxt, (child == NULL ? node : child), err,
2255 * @ctxt: the validation context
2261 xmlRelaxNGPopErrors(xmlRelaxNGValidCtxtPtr ctxt, int level)
2270 for (i = level; i < ctxt->errNr; i++) {
2271 err = &ctxt->errTab[i];
2282 ctxt->errNr = level;
2283 if (ctxt->errNr <= 0)
2284 ctxt->err = NULL;
2289 * @ctxt: the validation context
2294 xmlRelaxNGDumpValidError(xmlRelaxNGValidCtxtPtr ctxt)
2301 "Dumping error stack %d errors\n", ctxt->errNr);
2303 for (i = 0, k = 0; i < ctxt->errNr; i++) {
2304 err = &ctxt->errTab[i];
2307 dup = &ctxt->errTab[j];
2314 xmlRelaxNGShowValidError(ctxt, err->err, err->node, err->seq,
2329 ctxt->errNr = 0;
2334 * @ctxt: the validation context
2344 xmlRelaxNGAddValidError(xmlRelaxNGValidCtxtPtr ctxt,
2348 if (ctxt == NULL)
2350 if (ctxt->flags & FLAGS_NOERROR)
2359 if (((ctxt->flags & FLAGS_IGNORABLE) == 0) ||
2360 (ctxt->flags & FLAGS_NEGATIVE)) {
2367 if (ctxt->errNr != 0)
2368 xmlRelaxNGDumpValidError(ctxt);
2369 if (ctxt->state != NULL) {
2370 node = ctxt->state->node;
2371 seq = ctxt->state->seq;
2375 xmlRelaxNGShowValidError(ctxt, err, node, seq, arg1, arg2);
2381 xmlRelaxNGValidErrorPush(ctxt, err, arg1, arg2, dup);
2391 static xmlChar *xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt,
2852 static int xmlRelaxNGTryCompile(xmlRelaxNGParserCtxtPtr ctxt,
3006 * ctxt: the RelaxNG parser context
3015 xmlRelaxNGCompile(xmlRelaxNGParserCtxtPtr ctxt, xmlRelaxNGDefinePtr def)
3020 if ((ctxt == NULL) || (def == NULL))
3026 xmlAutomataPtr oldam = ctxt->am;
3027 xmlAutomataStatePtr oldstate = ctxt->state;
3032 ctxt->am = xmlNewAutomata();
3033 if (ctxt->am == NULL)
3035 ctxt->state = xmlAutomataGetInitState(ctxt->am);
3037 xmlRelaxNGCompile(ctxt, list);
3040 xmlAutomataSetFinalState(ctxt->am, ctxt->state);
3041 def->contModel = xmlAutomataCompile(ctxt->am);
3044 xmlFreeAutomata(ctxt->am);
3045 ctxt->state = oldstate;
3046 ctxt->am = oldam;
3050 if ((ctxt->am != NULL) && (def->name != NULL)) {
3051 ctxt->state = xmlAutomataNewTransition2(ctxt->am,
3052 ctxt->state, NULL,
3057 xmlAutomataPtr oldam = ctxt->am;
3058 xmlAutomataStatePtr oldstate = ctxt->state;
3063 ctxt->am = xmlNewAutomata();
3064 if (ctxt->am == NULL)
3066 ctxt->state = xmlAutomataGetInitState(ctxt->am);
3068 xmlRelaxNGCompile(ctxt, list);
3071 xmlAutomataSetFinalState(ctxt->am, ctxt->state);
3072 def->contModel = xmlAutomataCompile(ctxt->am);
3080 xmlFreeAutomata(ctxt->am);
3081 ctxt->state = oldstate;
3082 ctxt->am = oldam;
3084 xmlAutomataPtr oldam = ctxt->am;
3091 ret = xmlRelaxNGTryCompile(ctxt, def);
3092 ctxt->am = oldam;
3096 ret = xmlRelaxNGCompile(ctxt, def->content);
3099 xmlAutomataStatePtr oldstate = ctxt->state;
3101 xmlRelaxNGCompile(ctxt, def->content);
3102 xmlAutomataNewEpsilon(ctxt->am, oldstate, ctxt->state);
3108 ctxt->state =
3109 xmlAutomataNewEpsilon(ctxt->am, ctxt->state, NULL);
3110 oldstate = ctxt->state;
3113 xmlRelaxNGCompile(ctxt, list);
3116 xmlAutomataNewEpsilon(ctxt->am, ctxt->state, oldstate);
3117 ctxt->state =
3118 xmlAutomataNewEpsilon(ctxt->am, oldstate, NULL);
3126 xmlRelaxNGCompile(ctxt, list);
3129 oldstate = ctxt->state;
3132 xmlRelaxNGCompile(ctxt, list);
3135 xmlAutomataNewEpsilon(ctxt->am, ctxt->state, oldstate);
3136 ctxt->state =
3137 xmlAutomataNewEpsilon(ctxt->am, oldstate, NULL);
3142 xmlAutomataStatePtr oldstate = ctxt->state;
3146 ctxt->state = oldstate;
3147 ret = xmlRelaxNGCompile(ctxt, list);
3151 target = ctxt
3153 xmlAutomataNewEpsilon(ctxt->am, ctxt->state,
3158 ctxt->state = target;
3169 ret = xmlRelaxNGCompile(ctxt, list);
3178 ctxt->state =
3179 xmlAutomataNewEpsilon(ctxt->am, ctxt->state, NULL);
3180 oldstate = ctxt->state;
3181 xmlRelaxNGCompile(ctxt, def->content);
3182 xmlAutomataNewTransition(ctxt->am, ctxt->state,
3183 ctxt->state, BAD_CAST "#text",
3185 ctxt->state =
3186 xmlAutomataNewEpsilon(ctxt->am, oldstate, NULL);
3190 ctxt->state =
3191 xmlAutomataNewEpsilon(ctxt->am, ctxt->state, NULL);
3211 * ctxt: the RelaxNG parser context
3220 xmlRelaxNGTryCompile(xmlRelaxNGParserCtxtPtr ctxt, xmlRelaxNGDefinePtr def)
3225 if ((ctxt == NULL) || (def == NULL))
3232 ctxt->am = NULL;
3233 ret = xmlRelaxNGCompile(ctxt, def);
3257 ret = xmlRelaxNGTryCompile(ctxt, def->content);
3280 ret = xmlRelaxNGTryCompile(ctxt, list);
3303 ctxt, xmlNodePtr node);
3305 ctxt, xmlNodePtr node);
3307 ctxt, xmlNodePtr nodes,
3310 ctxt, xmlNodePtr node);
3311 static xmlRelaxNGPtr xmlRelaxNGParseDocument(xmlRelaxNGParserCtxtPtr ctxt,
3313 static int xmlRelaxNGParseGrammarContent(xmlRelaxNGParserCtxtPtr ctxt,
3316 ctxt, xmlNodePtr node,
3320 ctxt, xmlNodePtr nodes);
3321 static int xmlRelaxNGElementMatch(xmlRelaxNGValidCtxtPtr ctxt,
3430 * @ctxt: a Relax-NG parser context
3438 xmlRelaxNGGetDataTypeLibrary(xmlRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
3480 * @ctxt: a Relax-NG parser context
3488 xmlRelaxNGParseValue(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
3496 def = xmlRelaxNGNewDefine(ctxt, node);
3505 xmlRngPErr(ctxt, node, XML_RNGP_TYPE_VALUE,
3508 library = xmlRelaxNGGetDataTypeLibrary(ctxt, node);
3519 xmlRngPErr(ctxt, node, XML_RNGP_UNKNOWN_TYPE_LIB,
3526 xmlRngPErr(ctxt, node, XML_RNGP_ERROR_TYPE_LIB,
3532 xmlRngPErr(ctxt, node, XML_RNGP_TYPE_NOT_FOUND,
3544 xmlRngPErr(ctxt, node, XML_RNGP_TEXT_EXPECTED,
3550 xmlRngPErr(ctxt, node, XML_RNGP_VALUE_NO_CONTENT,
3558 xmlRngPErr(ctxt, node, XML_RNGP_INVALID_VALUE,
3572 * @ctxt: a Relax-NG parser context
3580 xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
3592 xmlRngPErr(ctxt, node, XML_RNGP_TYPE_MISSING, "data has no type\n", NULL,
3598 xmlRngPErr(ctxt, node, XML_RNGP_TYPE_VALUE,
3601 library = xmlRelaxNGGetDataTypeLibrary(ctxt, node);
3606 def = xmlRelaxNGNewDefine(ctxt, node);
3618 xmlRngPErr(ctxt, node, XML_RNGP_UNKNOWN_TYPE_LIB,
3625 xmlRngPErr(ctxt, node, XML_RNGP_ERROR_TYPE_LIB,
3631 xmlRngPErr(ctxt, node, XML_RNGP_TYPE_NOT_FOUND,
3641 ctxt->idref = 1;
3655 xmlRngPErr(ctxt, node, XML_RNGP_PARAM_FORBIDDEN,
3663 param = xmlRelaxNGNewDefine(ctxt, node);
3668 xmlRngPErr(ctxt, node, XML_RNGP_PARAM_NAME_MISSING,
3692 except = xmlRelaxNGNewDefine(ctxt, node);
3700 xmlRngPErr(ctxt, content, XML_RNGP_EXCEPT_NO_CONTENT,
3704 tmp2 = xmlRelaxNGParsePattern(ctxt, child);
3721 xmlRngPErr(ctxt, content, XML_RNGP_DATA_CONTENT,
3751 xmlRelaxNGValidCtxt ctxt;
3753 memset(&ctxt, 0, sizeof(xmlRelaxNGValidCtxt));
3755 ctxt.flags = FLAGS_IGNORABLE | FLAGS_NOERROR;
3776 if (xmlRelaxNGElementMatch(&ctxt, def2, &node)) {
3813 if (xmlRelaxNGElementMatch(&ctxt, def1, &node)) {
3831 * @ctxt: a Relax-NG parser context
3842 xmlRelaxNGCompareElemDefLists(xmlRelaxNGParserCtxtPtr ctxt
3866 * @ctxt: a Relax-NG parser context
3874 xmlRelaxNGGenerateAttributes(xmlRelaxNGParserCtxtPtr ctxt,
3883 if (ctxt->nbErrors != 0)
3941 * @ctxt: a Relax-NG parser context
3950 xmlRelaxNGGetElements(xmlRelaxNGParserCtxtPtr ctxt,
3961 if (ctxt->nbErrors != 0)
3975 xmlRngPErrMemory(ctxt, "getting element list\n");
3985 xmlRngPErrMemory(ctxt, "getting element list\n");
4041 * @ctxt: a Relax-NG parser context
4047 xmlRelaxNGCheckChoiceDeterminism(xmlRelaxNGParserCtxtPtr ctxt,
4068 if (ctxt->nbErrors != 0)
4083 xmlRngPErrMemory(ctxt, "building choice\n");
4097 list[i] = xmlRelaxNGGetElements(ctxt, cur, 0);
4151 ret = xmlRelaxNGCompareElemDefLists(ctxt, list[i], list[j]);
4177 * @ctxt: a Relax-NG parser context
4183 xmlRelaxNGCheckGroupAttrs(xmlRelaxNGParserCtxtPtr ctxt,
4202 if (ctxt->nbErrors != 0)
4220 xmlRngPErrMemory(ctxt, "building group\n");
4226 list[i] = xmlRelaxNGGetElements(ctxt, cur, 1);
4232 list[i] = xmlRelaxNGGetElements(ctxt, cur, 1);
4243 ret = xmlRelaxNGCompareElemDefLists(ctxt, list[i], list[j]);
4245 xmlRngPErr(ctxt, def->node, XML_RNGP_GROUP_ATTR_CONFLICT,
4262 * @ctxt: a Relax-NG parser context
4276 xmlRelaxNGParserCtxtPtr ctxt,
4294 if (ctxt->nbErrors != 0)
4323 groups[nbgroups]->defs = xmlRelaxNGGetElements(ctxt, cur, 0);
4324 groups[nbgroups]->attrs = xmlRelaxNGGetElements(ctxt, cur, 1);
4348 ret = xmlRelaxNGCompareElemDefLists(ctxt, group->defs,
4351 xmlRngPErr(ctxt, def->node, XML_RNGP_ELEM_TEXT_CONFLICT,
4355 ret = xmlRelaxNGCompareElemDefLists(ctxt, group->attrs,
4358 xmlRngPErr(ctxt, def->node, XML_RNGP_ATTR_CONFLICT,
4421 xmlRngPErrMemory(ctxt, "in interleave computation\n");
4436 * @ctxt: a Relax-NG parser context
4444 xmlRelaxNGParseInterleave(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
4450 def = xmlRelaxNGNewDefine(ctxt, node);
4456 if (ctxt->interleaves == NULL)
4457 ctxt->interleaves = xmlHashCreate(10);
4458 if (ctxt->interleaves == NULL) {
4459 xmlRngPErrMemory(ctxt, "create interleaves\n");
4463 snprintf(name, 32, "interleave%d", ctxt->nbInterleaves++);
4464 if (xmlHashAddEntry(ctxt->interleaves, BAD_CAST name, def) < 0) {
4465 xmlRngPErr(ctxt, node, XML_RNGP_INTERLEAVE_ADD,
4472 xmlRngPErr(ctxt, node, XML_RNGP_INTERLEAVE_NO_CONTENT,
4477 cur = xmlRelaxNGParseElement(ctxt, child);
4479 cur = xmlRelaxNGParsePattern(ctxt, child);
4498 * @ctxt: a Relax-NG parser context
4506 xmlRelaxNGParseInclude(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
4514 xmlRngPErr(ctxt, node, XML_RNGP_INCLUDE_EMPTY,
4520 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY, "Include document is empty\n",
4525 xmlRngPErr(ctxt, node, XML_RNGP_GRAMMAR_MISSING,
4534 tmp = xmlRelaxNGParseGrammarContent(ctxt, root->children);
4539 tmp = xmlRelaxNGParseGrammarContent(ctxt, node->children);
4548 * @ctxt: a Relax-NG parser context
4556 xmlRelaxNGParseDefine(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
4565 xmlRngPErr(ctxt, node, XML_RNGP_DEFINE_NAME_MISSING,
4570 xmlRngPErr(ctxt, node, XML_RNGP_INVALID_DEFINE_NAME,
4573 def = xmlRelaxNGNewDefine(ctxt, node);
4581 xmlRngPErr(ctxt, node, XML_RNGP_DEFINE_EMPTY,
4584 olddefine = ctxt->define;
4585 ctxt->define = name;
4587 xmlRelaxNGParsePatterns(ctxt, node->children, 0);
4588 ctxt->define = olddefine;
4590 if (ctxt->grammar->defs == NULL)
4591 ctxt->grammar->defs = xmlHashCreate(10);
4592 if (ctxt->grammar->defs == NULL) {
4593 xmlRngPErr(ctxt, node, XML_RNGP_DEFINE_CREATE_FAILED,
4597 tmp = xmlHashAddEntry(ctxt->grammar->defs, name, def);
4601 prev = xmlHashLookup(ctxt->grammar->defs, name);
4603 xmlRngPErr(ctxt, node, XML_RNGP_DEFINE_CREATE_FAILED,
4620 * @ctxt: the parser context
4628 xmlRelaxNGProcessExternalRef(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
4638 def = xmlRelaxNGNewDefine(ctxt, node);
4649 xmlRngPErr(ctxt, node, XML_RNGP_EXTERNALREF_EMTPY,
4650 "xmlRelaxNGParse: %s is empty\n", ctxt->URL,
4679 oldflags = ctxt->flags;
4680 ctxt->flags |= XML_RELAXNG_IN_EXTERNALREF;
4681 docu->schema = xmlRelaxNGParseDocument(ctxt, root);
4682 ctxt->flags = oldflags;
4704 * @ctxt: a Relax-NG parser context
4713 xmlRelaxNGParsePattern(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
4721 def = xmlRelaxNGParseElement(ctxt, node);
4723 def = xmlRelaxNGParseAttribute(ctxt, node);
4725 def = xmlRelaxNGNewDefine(ctxt, node);
4730 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_NOT_EMPTY,
4734 def = xmlRelaxNGNewDefine(ctxt, node);
4739 xmlRngPErr(ctxt, node, XML_RNGP_TEXT_HAS_CHILD,
4743 def = xmlRelaxNGNewDefine(ctxt, node);
4748 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4752 xmlRelaxNGParsePatterns(ctxt, node->children, 1);
4755 def = xmlRelaxNGNewDefine(ctxt, node);
4760 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4764 xmlRelaxNGParsePatterns(ctxt, node->children, 1);
4767 def = xmlRelaxNGNewDefine(ctxt, node);
4772 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4776 xmlRelaxNGParsePatterns(ctxt, node->children, 1);
4779 def = xmlRelaxNGNewDefine(ctxt, node);
4784 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4788 xmlRelaxNGParsePatterns(ctxt, node->children, 0);
4791 def = xmlRelaxNGNewDefine(ctxt, node);
4796 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4800 xmlRelaxNGParsePatterns(ctxt, node->children, 0);
4803 def = xmlRelaxNGNewDefine(ctxt, node);
4809 xmlRngPErr(ctxt, node, XML_RNGP_REF_NO_NAME, "ref has no name\n",
4814 xmlRngPErr(ctxt, node, XML_RNGP_REF_NAME_INVALID,
4820 xmlRngPErr(ctxt, node, XML_RNGP_REF_NOT_EMPTY, "ref is not empty\n",
4823 if (ctxt->grammar->refs == NULL)
4824 ctxt->grammar->refs = xmlHashCreate(10);
4825 if (ctxt->grammar->refs == NULL) {
4826 xmlRngPErr(ctxt, node, XML_RNGP_REF_CREATE_FAILED,
4832 tmp = xmlHashAddEntry(ctxt->grammar->refs, def->name, def);
4837 xmlHashLookup(ctxt->grammar->refs, def->name);
4840 xmlRngPErr(ctxt, node, XML_RNGP_REF_CREATE_FAILED,
4844 xmlRngPErr(ctxt, node, XML_RNGP_REF_CREATE_FAILED,
4856 def = xmlRelaxNGParseData(ctxt, node);
4858 def = xmlRelaxNGParseValue(ctxt, node);
4860 def = xmlRelaxNGNewDefine(ctxt, node);
4865 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT,
4869 xmlRelaxNGParsePatterns(ctxt, node->children, 0);
4872 def = xmlRelaxNGParseInterleave(ctxt, node);
4874 def = xmlRelaxNGProcessExternalRef(ctxt, node);
4876 def = xmlRelaxNGNewDefine(ctxt, node);
4881 xmlRngPErr(ctxt, node, XML_RNGP_NOTALLOWED_NOT_EMPTY,
4894 oldparent = ctxt->parentgrammar;
4895 old = ctxt->grammar;
4896 ctxt->parentgrammar = old;
4897 grammar = xmlRelaxNGParseGrammar(ctxt, node->children);
4899 ctxt->grammar = old;
4900 ctxt->parentgrammar = oldparent;
4913 if (ctxt->parentgrammar == NULL) {
4914 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_NO_PARENT,
4919 def = xmlRelaxNGNewDefine(ctxt, node);
4925 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_NO_NAME,
4930 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_NAME_INVALID,
4936 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_NOT_EMPTY,
4939 if (ctxt->parentgrammar->refs == NULL)
4940 ctxt->parentgrammar->refs = xmlHashCreate(10);
4941 if (ctxt->parentgrammar->refs == NULL) {
4942 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_CREATE_FAILED,
4949 xmlHashAddEntry(ctxt->parentgrammar->refs, def->name, def);
4954 xmlHashLookup(ctxt->parentgrammar->refs, def->name);
4956 xmlRngPErr(ctxt, node, XML_RNGP_PARENTREF_CREATE_FAILED,
4968 xmlRngPErr(ctxt, node, XML_RNGP_EMPTY_CONSTRUCT, "Mixed is empty\n",
4972 def = xmlRelaxNGParseInterleave(ctxt, node);
4977 tmp = xmlRelaxNGNewDefine(ctxt, node);
4985 tmp = xmlRelaxNGNewDefine(ctxt, node);
4994 xmlRngPErr(ctxt, node, XML_RNGP_UNKNOWN_CONSTRUCT,
5004 * @ctxt: a Relax-NG parser context
5012 xmlRelaxNGParseAttribute(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
5018 ret = xmlRelaxNGNewDefine(ctxt, node);
5022 ret->parent = ctxt->def;
5025 xmlRngPErr(ctxt, node, XML_RNGP_ATTRIBUTE_EMPTY,
5030 old_flags = ctxt->flags;
5031 ctxt->flags |= XML_RELAXNG_IN_ATTRIBUTE;
5032 cur = xmlRelaxNGParseNameClass(ctxt, child, ret);
5037 cur = xmlRelaxNGParsePattern(ctxt, child);
5064 xmlRngPErr(ctxt, node, XML_RNGP_ATTRIBUTE_CONTENT,
5069 xmlRngPErr(ctxt, node, XML_RNGP_ATTRIBUTE_NOOP,
5078 xmlRngPErr(ctxt, node, XML_RNGP_ATTRIBUTE_CHILDREN,
5081 ctxt->flags = old_flags;
5087 * @ctxt: a Relax-NG parser context
5096 xmlRelaxNGParseExceptNameClass(xmlRelaxNGParserCtxtPtr ctxt,
5103 xmlRngPErr(ctxt, node, XML_RNGP_EXCEPT_MISSING,
5108 xmlRngPErr(ctxt, node, XML_RNGP_EXCEPT_MULTIPLE,
5113 xmlRngPErr(ctxt, node, XML_RNGP_EXCEPT_EMPTY, "except has no content\n",
5118 ret = xmlRelaxNGNewDefine(ctxt, node);
5124 cur = xmlRelaxNGNewDefine(ctxt, child);
5132 if (xmlRelaxNGParseNameClass(ctxt, child, cur) != NULL) {
5148 * @ctxt: a Relax-NG parser context
5157 ctxt, xmlNodePtr node,
5168 ret = xmlRelaxNGNewDefine(ctxt, node);
5172 if (ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE)
5183 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_NAME,
5187 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_NAME,
5194 if ((ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE) &&
5197 xmlRngPErr(ctxt, node, XML_RNGP_XML_NS,
5201 if ((ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE) &&
5204 xmlRngPErr(ctxt, node, XML_RNGP_XMLNS_NAME,
5213 xmlRelaxNGParseExceptNameClass(ctxt, node->children,
5221 xmlRngPErr(ctxt, node, XML_RNGP_NSNAME_NO_NS,
5224 if ((ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE) &&
5228 xmlRngPErr(ctxt, node, XML_RNGP_XML_NS,
5234 xmlRelaxNGParseExceptNameClass(ctxt, node->children,
5242 ret = xmlRelaxNGNewDefine(ctxt, node);
5249 xmlRngPErr(ctxt, node, XML_RNGP_CHOICE_EMPTY,
5255 tmp = xmlRelaxNGParseNameClass(ctxt, child, ret);
5268 xmlRngPErr(ctxt, node, XML_RNGP_CHOICE_CONTENT,
5289 * @ctxt: a Relax-NG parser context
5297 xmlRelaxNGParseElement(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
5303 ret = xmlRelaxNGNewDefine(ctxt, node);
5307 ret->parent = ctxt->def;
5310 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_EMPTY,
5315 cur = xmlRelaxNGParseNameClass(ctxt, child, ret);
5320 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_NO_CONTENT,
5325 olddefine = ctxt->define;
5326 ctxt->define = NULL;
5329 cur = xmlRelaxNGParsePattern(ctxt, child);
5355 ret->content = xmlRelaxNGNewDefine(ctxt, node);
5372 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_CONTENT,
5377 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_CONTENT,
5382 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_CONTENT,
5387 xmlRngPErr(ctxt, node, XML_RNGP_ELEMENT_CONTENT,
5395 ctxt->define = olddefine;
5401 * @ctxt: a Relax-NG parser context
5410 xmlRelaxNGParsePatterns(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr nodes,
5415 parent = ctxt->def;
5418 cur = xmlRelaxNGParseElement(ctxt, nodes);
5424 def = xmlRelaxNGNewDefine(ctxt, nodes);
5433 cur = xmlRelaxNGParsePattern(ctxt, nodes);
5450 * @ctxt: a Relax-NG parser context
5458 xmlRelaxNGParseStart(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr nodes)
5464 xmlRngPErr(ctxt, nodes, XML_RNGP_START_EMPTY, "start has no children\n",
5469 def = xmlRelaxNGNewDefine(ctxt, nodes);
5474 xmlRngPErr(ctxt, nodes, XML_RNGP_EMPTY_CONTENT,
5478 def = xmlRelaxNGNewDefine(ctxt, nodes);
5483 xmlRngPErr(ctxt, nodes, XML_RNGP_NOTALLOWED_NOT_EMPTY,
5487 def = xmlRelaxNGParsePatterns(ctxt, nodes, 1);
5489 if (ctxt->grammar->start != NULL) {
5490 last = ctxt->grammar->start;
5495 ctxt->grammar->start = def;
5499 xmlRngPErr(ctxt, nodes, XML_RNGP_START_CONTENT,
5508 * @ctxt: a Relax-NG parser context
5516 xmlRelaxNGParseGrammarContent(xmlRelaxNGParserCtxtPtr ctxt,
5522 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_EMPTY,
5529 xmlRngPErr(ctxt, nodes, XML_RNGP_START_EMPTY,
5532 tmp = xmlRelaxNGParseStart(ctxt, nodes->children);
5537 tmp = xmlRelaxNGParseDefine(ctxt, nodes);
5541 tmp = xmlRelaxNGParseInclude(ctxt, nodes);
5545 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_CONTENT,
5558 * @ctxt: a Relax-NG parser context
5566 xmlRelaxNGParserCtxtPtr ctxt,
5572 grammar = ctxt->grammar;
5574 xmlRngPErr(ctxt, ref->node, XML_ERR_INTERNAL_ERROR,
5580 xmlRngPErr(ctxt, ref->node, XML_ERR_INTERNAL_ERROR,
5594 xmlRngPErr(ctxt, ref->node, XML_RNGP_REF_NO_DEF,
5599 xmlRngPErr(ctxt, ref->node, XML_RNGP_REF_NO_DEF,
5608 * @ctxt: a Relax-NG parser context
5616 xmlRelaxNGParserCtxtPtr ctxt, const xmlChar * name)
5633 xmlRngPErr(ctxt, define->node, XML_RNGP_DEF_CHOICE_AND_INTERLEAVE,
5641 xmlRngPErr(ctxt, define->node, XML_RNGP_DEF_CHOICE_AND_INTERLEAVE,
5646 xmlRngPErr(ctxt, define->node, XML_RNGP_UNKNOWN_COMBINE,
5655 xmlRngPErr(ctxt, define->node, XML_RNGP_NEED_COMBINE,
5670 cur = xmlRelaxNGNewDefine(ctxt, define->node);
5685 tmp2 = xmlRelaxNGNewDefine(ctxt, tmp->content->node);
5705 if (ctxt->interleaves == NULL)
5706 ctxt->interleaves = xmlHashCreate(10);
5707 if (ctxt->interleaves == NULL) {
5708 xmlRngPErr(ctxt, define->node, XML_RNGP_INTERLEAVE_CREATE_FAILED,
5714 snprintf(tmpname, 32, "interleave%d", ctxt->nbInterleaves++);
5715 if (xmlHashAddEntry(ctxt->interleaves, BAD_CAST tmpname, cur) <
5717 xmlRngPErr(ctxt, define->node, XML_RNGP_INTERLEAVE_CREATE_FAILED,
5727 * @ctxt: a Relax-NG parser context
5734 xmlRelaxNGCombineStart(xmlRelaxNGParserCtxtPtr ctxt,
5751 xmlRngPErr(ctxt, cur->node, XML_RNGP_START_MISSING,
5763 xmlRngPErr(ctxt, cur->node, XML_RNGP_START_CHOICE_AND_INTERLEAVE,
5771 xmlRngPErr(ctxt, cur->node, XML_RNGP_START_CHOICE_AND_INTERLEAVE,
5776 xmlRngPErr(ctxt, cur->node, XML_RNGP_UNKNOWN_COMBINE,
5785 xmlRngPErr(ctxt, cur->node, XML_RNGP_NEED_COMBINE,
5800 cur = xmlRelaxNGNewDefine(ctxt, starts->node);
5810 if (ctxt->interleaves == NULL)
5811 ctxt->interleaves = xmlHashCreate(10);
5812 if (ctxt->interleaves == NULL) {
5813 xmlRngPErr(ctxt, cur->node, XML_RNGP_INTERLEAVE_CREATE_FAILED,
5819 snprintf(tmpname, 32, "interleave%d", ctxt->nbInterleaves++);
5820 if (xmlHashAddEntry(ctxt->interleaves, BAD_CAST tmpname, cur) <
5822 xmlRngPErr(ctxt, cur->node, XML_RNGP_INTERLEAVE_CREATE_FAILED,
5832 * @ctxt: a Relax-NG parser context
5841 xmlRelaxNGCheckCycles(xmlRelaxNGParserCtxtPtr ctxt,
5851 ret = xmlRelaxNGCheckCycles(ctxt, cur->content, depth);
5854 xmlRngPErr(ctxt, cur->node, XML_RNGP_REF_CYCLE,
5860 ret = xmlRelaxNGCheckCycles(ctxt, cur->content, depth + 1);
5862 ret = xmlRelaxNGCheckCycles(ctxt, cur->content, depth);
5871 * @ctxt: a Relax-NG parser context
5881 xmlRelaxNGTryUnlink(xmlRelaxNGParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
5905 * @ctxt: a Relax-NG parser context
5911 xmlRelaxNGSimplify(xmlRelaxNGParserCtxtPtr ctxt,
5921 xmlRelaxNGSimplify(ctxt, cur->content, cur);
5936 prev = xmlRelaxNGTryUnlink(ctxt, cur, parent, prev);
5950 prev = xmlRelaxNGTryUnlink(ctxt, cur, parent, prev);
5956 xmlRelaxNGSimplify(ctxt, cur->content, cur);
5958 xmlRelaxNGSimplify(ctxt, cur->attrs, cur);
5960 xmlRelaxNGSimplify(ctxt, cur->nameClass, cur);
5971 xmlRelaxNGGenerateAttributes(ctxt, cur->content);
5990 attronly = xmlRelaxNGGenerateAttributes(ctxt, tmp);
6030 prev = xmlRelaxNGTryUnlink(ctxt, cur, parent, prev);
6044 prev = xmlRelaxNGTryUnlink(ctxt, cur, parent, prev);
6058 prev = xmlRelaxNGTryUnlink(ctxt, cur, parent, prev);
6122 * @ctxt: a Relax-NG parser context
6132 xmlRelaxNGCheckRules(xmlRelaxNGParserCtxtPtr ctxt,
6150 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_REF,
6156 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_REF,
6162 ret = xmlRelaxNGCheckRules(ctxt, cur->content,
6174 xmlRelaxNGCheckGroupAttrs(ctxt, cur);
6176 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_ELEM,
6181 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_ELEM,
6186 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_ATTR_ELEM,
6191 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_ATTR_ELEM,
6201 xmlRelaxNGCheckRules(ctxt, cur->attrs, nflags, cur->type);
6203 xmlRngPErr(ctxt, cur->node, XML_RNGP_ELEM_CONTENT_EMPTY,
6208 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6211 xmlRngPErr(ctxt, cur->node, XML_RNGP_ELEM_CONTENT_ERROR,
6219 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_ATTR_ATTR,
6224 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_ATTR,
6229 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_ONEMORE_GROUP_ATTR,
6234 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_ONEMORE_INTERLEAVE_ATTR,
6239 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_ATTR,
6244 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_ATTR,
6251 xmlRngPErr(ctxt, cur->node, XML_RNGP_ANYNAME_ATTR_ANCESTOR,
6255 xmlRngPErr(ctxt, cur->node, XML_RNGP_NSNAME_ATTR_ANCESTOR,
6261 xmlRelaxNGCheckRules(ctxt, cur->content, nflags, cur->type);
6266 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_ONEMORE,
6271 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_ONEMORE,
6277 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6282 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_LIST,
6287 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_LIST,
6292 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_LIST,
6298 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6302 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_GROUP,
6307 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_GROUP,
6316 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6321 xmlRelaxNGCheckGroupAttrs(ctxt, cur);
6324 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_INTERLEAVE,
6329 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_INTERLEAVE,
6334 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_INTERLEAVE,
6343 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6352 xmlRelaxNGCheckRules(ctxt, cur->content, nflags,
6356 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_DATA,
6360 xmlRelaxNGCheckRules(ctxt, cur->content, flags, cur->type);
6364 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_VALUE,
6368 xmlRelaxNGCheckRules(ctxt, cur->content, flags, cur->type);
6372 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_LIST_TEXT,
6377 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_TEXT,
6382 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_TEXT,
6389 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_DATA_EXCEPT_EMPTY,
6394 xmlRngPErr(ctxt, cur->node, XML_RNGP_PAT_START_EMPTY,
6400 xmlRelaxNGCheckChoiceDeterminism(ctxt, cur);
6402 xmlRelaxNGCheckRules(ctxt, cur->content, flags, cur->type);
6405 xmlRelaxNGCheckRules(ctxt, cur->content, flags, cur->type);
6433 * @ctxt: a Relax-NG parser context
6442 xmlRelaxNGParseGrammar(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr nodes)
6450 ret = xmlRelaxNGNewGrammar(ctxt);
6457 ret->parent = ctxt->grammar;
6458 if (ctxt->grammar != NULL) {
6459 tmp = ctxt->grammar->children;
6461 ctxt->grammar->children = ret;
6469 old = ctxt->grammar;
6470 ctxt->grammar = ret;
6471 xmlRelaxNGParseGrammarContent(ctxt, nodes);
6472 ctxt->grammar = ret;
6473 if (ctxt->grammar == NULL) {
6474 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_CONTENT,
6476 } else if (ctxt->grammar->start == NULL) {
6477 xmlRngPErr(ctxt, nodes, XML_RNGP_GRAMMAR_NO_START,
6484 xmlRelaxNGCombineStart(ctxt, ret);
6487 ctxt);
6495 ctxt);
6500 ctxt->grammar = old;
6506 * @ctxt: a Relax-NG parser context
6516 xmlRelaxNGParseDocument(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
6522 if ((ctxt == NULL) || (node == NULL))
6525 schema = xmlRelaxNGNewRelaxNG(ctxt);
6529 olddefine = ctxt->define;
6530 ctxt->define = NULL;
6532 schema->topgrammar = xmlRelaxNGParseGrammar(ctxt, node->children);
6536 schema->topgrammar = ret = xmlRelaxNGNewGrammar(ctxt);
6543 ret->parent = ctxt->grammar;
6544 if (ctxt->grammar != NULL) {
6545 tmp = ctxt->grammar->children;
6547 ctxt->grammar->children = ret;
6554 old = ctxt->grammar;
6555 ctxt->grammar = ret;
6556 xmlRelaxNGParseStart(ctxt, node);
6558 ctxt->grammar = old;
6560 ctxt->define = olddefine;
6562 xmlRelaxNGCheckCycles(ctxt, schema->topgrammar->start, 0);
6563 if ((ctxt->flags & XML_RELAXNG_IN_EXTERNALREF) == 0) {
6564 xmlRelaxNGSimplify(ctxt, schema->topgrammar->start, NULL);
6570 xmlRelaxNGCheckRules(ctxt, schema->topgrammar->start,
6688 * @ctxt: the schema parser context
6693 xmlRelaxNGFreeParserCtxt(xmlRelaxNGParserCtxtPtr ctxt)
6695 if (ctxt == NULL)
6697 if (ctxt->URL != NULL)
6698 xmlFree(ctxt->URL);
6699 if (ctxt->doc != NULL)
6700 xmlRelaxNGFreeDocument(ctxt->doc);
6701 if (ctxt->interleaves != NULL)
6702 xmlHashFree(ctxt->interleaves, NULL);
6703 if (ctxt->documents != NULL)
6704 xmlRelaxNGFreeDocumentList(ctxt->documents);
6705 if (ctxt->includes != NULL)
6706 xmlRelaxNGFreeIncludeList(ctxt->includes);
6707 if (ctxt->docTab != NULL)
6708 xmlFree(ctxt->docTab);
6709 if (ctxt->incTab != NULL)
6710 xmlFree(ctxt->incTab);
6711 if (ctxt->defTab != NULL) {
6714 for (i = 0; i < ctxt->defNr; i++)
6715 xmlRelaxNGFreeDefine(ctxt->defTab[i]);
6716 xmlFree(ctxt->defTab);
6718 if ((ctxt->document != NULL) && (ctxt->freedoc))
6719 xmlFreeDoc(ctxt->document);
6720 xmlFree(ctxt);
6777 * @ctxt: a Relax-NG parser context
6783 xmlRelaxNGCleanupAttributes(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr node)
6799 xmlRngPErr(ctxt, node, XML_RNGP_FORBIDDEN_ATTRIBUTE,
6806 xmlRngPErr(ctxt, node, XML_RNGP_FORBIDDEN_ATTRIBUTE,
6813 xmlRngPErr(ctxt, node, XML_RNGP_FORBIDDEN_ATTRIBUTE,
6820 xmlRngPErr(ctxt, node, XML_RNGP_FORBIDDEN_ATTRIBUTE,
6833 xmlRngPErr(ctxt, node, XML_RNGP_INVALID_URI,
6838 xmlRngPErr(ctxt, node, XML_RNGP_URI_NOT_ABSOLUTE,
6843 xmlRngPErr(ctxt, node, XML_RNGP_URI_FRAGMENT,
6853 xmlRngPErr(ctxt, node, XML_RNGP_UNKNOWN_ATTRIBUTE,
6864 * @ctxt: a Relax-NG parser context
6871 xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt, xmlNodePtr root)
6894 xmlRngPErr(ctxt, cur, XML_RNGP_FOREIGN_ELEMENT,
6901 xmlRelaxNGCleanupAttributes(ctxt, cur);
6921 xmlRngPErr(ctxt, cur, XML_RNGP_MISSING_HREF,
6931 xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR,
6942 xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR,
6957 xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR,
6973 docu = xmlRelaxNGLoadExternalRef(ctxt, URL, ns);
6975 xmlRngPErr(ctxt, cur, XML_RNGP_EXTERNAL_REF_FAILURE,
6995 xmlRngPErr(ctxt, cur, XML_RNGP_MISSING_HREF,
7004 xmlRngPErr(ctxt, cur, XML_RNGP_HREF_ERROR,
7029 incl = xmlRelaxNGLoadInclude(ctxt, URL, cur, ns);
7033 xmlRngPErr(ctxt, cur, XML_RNGP_INCLUDE_FAILURE,
7071 xmlRngPErr(ctxt, cur, XML_RNGP_CREATE_FAILURE,
7130 xmlRngPErr(ctxt, cur,
7149 if (ctxt->flags & XML_RELAXNG_IN_NSEXCEPT) {
7150 xmlRngPErr(ctxt, cur,
7158 int oldflags = ctxt->flags;
7166 ctxt->flags |= XML_RELAXNG_IN_ANYEXCEPT;
7167 xmlRelaxNGCleanupTree(ctxt, cur);
7168 ctxt->flags = oldflags;
7173 ctxt->flags |= XML_RELAXNG_IN_NSEXCEPT;
7174 xmlRelaxNGCleanupTree(ctxt, cur);
7175 ctxt->flags = oldflags;
7182 if (ctxt->flags & XML_RELAXNG_IN_ANYEXCEPT) {
7183 xmlRngPErr(ctxt, cur,
7187 } else if (ctxt->flags & XML_RELAXNG_IN_NSEXCEPT) {
7188 xmlRngPErr(ctxt, cur,
7304 * @ctxt: a Relax-NG parser context
7313 xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt, xmlDocPtr doc)
7322 xmlRngPErr(ctxt, (xmlNodePtr) doc, XML_RNGP_EMPTY, "xmlRelaxNGParse: %s is empty\n",
7323 ctxt->URL, NULL);
7326 xmlRelaxNGCleanupTree(ctxt, root);
7332 * @ctxt: a Relax-NG parser context
7341 xmlRelaxNGParse(xmlRelaxNGParserCtxtPtr ctxt)
7349 if (ctxt == NULL)
7355 if (ctxt->URL != NULL) {
7356 doc = xmlReadFile((const char *) ctxt->URL,NULL,0);
7358 xmlRngPErr(ctxt, NULL, XML_RNGP_PARSE_ERROR,
7359 "xmlRelaxNGParse: could not load %s\n", ctxt->URL,
7363 } else if (ctxt->buffer != NULL) {
7364 doc = xmlReadMemory(ctxt->buffer, ctxt->size,NULL,NULL,0);
7366 xmlRngPErr(ctxt, NULL, XML_RNGP_PARSE_ERROR,
7372 ctxt->URL = xmlStrdup(BAD_CAST "in_memory_buffer");
7373 } else if (ctxt->document != NULL) {
7374 doc = ctxt->document;
7376 xmlRngPErr(ctxt, NULL, XML_RNGP_EMPTY,
7380 ctxt->document = doc;
7385 doc = xmlRelaxNGCleanupDoc(ctxt, doc);
7387 xmlFreeDoc(ctxt->document);
7388 ctxt->document = NULL;
7397 xmlRngPErr(ctxt, (xmlNodePtr) doc,
7399 (ctxt->URL ? ctxt->URL : BAD_CAST "schemas"), NULL);
7401 xmlFreeDoc(ctxt->document);
7402 ctxt->document = NULL;
7405 ret = xmlRelaxNGParseDocument(ctxt, root);
7407 xmlFreeDoc(ctxt->document);
7408 ctxt->document = NULL;
7418 if (ctxt->interleaves != NULL) {
7419 xmlHashScan(ctxt->interleaves,
7420 (xmlHashScanner) xmlRelaxNGComputeInterleaves, ctxt);
7426 if (ctxt->nbErrors > 0) {
7428 ctxt->document = NULL;
7440 def = xmlRelaxNGNewDefine(ctxt, NULL);
7447 xmlRelaxNGTryCompile(ctxt, ret->topgrammar->start);
7454 ctxt->document = NULL;
7455 ret->documents = ctxt->documents;
7456 ctxt->documents = NULL;
7458 ret->includes = ctxt->includes;
7459 ctxt->includes = NULL;
7460 ret->defNr = ctxt->defNr;
7461 ret->defTab = ctxt->defTab;
7462 ctxt->defTab = NULL;
7463 if (ctxt->idref == 1)
7471 * @ctxt: a Relax-NG validation context
7479 xmlRelaxNGSetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
7483 if (ctxt == NULL)
7485 ctxt->error = err;
7486 ctxt->warning = warn;
7487 ctxt->serror = NULL;
7488 ctxt->userData = ctx;
7493 * @ctxt: a Relax-NG validation context
7503 xmlRelaxNGGetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
7507 if (ctxt == NULL)
7510 *err = ctxt->error;
7512 *warn = ctxt->warning;
7514 *ctx = ctxt->userData;
7520 * @ctxt: a Relax-NG parser context
7527 xmlRelaxNGSetParserStructuredErrors(xmlRelaxNGParserCtxtPtr ctxt,
7531 if (ctxt == NULL)
7533 ctxt->serror = serror;
7534 ctxt->error = NULL;
7535 ctxt->warning = NULL;
7536 ctxt->userData = ctx;
7782 static int xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt,
7799 xmlRelaxNGValidCtxtPtr ctxt = (xmlRelaxNGValidCtxtPtr) inputdata;
7807 if (ctxt == NULL) {
7815 if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
7816 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
7819 if ((ctxt == NULL) || (define == NULL)) {
7821 if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
7822 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
7826 if (ctxt->errNo == XML_RELAXNG_OK)
7827 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
7830 ret = xmlRelaxNGValidateDefinition(ctxt, define);
7832 ctxt->perr = ret;
7837 * @ctxt: the RelaxNG validation context
7846 xmlRelaxNGValidateCompiledContent(xmlRelaxNGValidCtxtPtr ctxt,
7854 if ((ctxt == NULL) || (regexp == NULL))
7856 oldperr = ctxt->perr;
7858 xmlRelaxNGValidateCompiledCallback, ctxt);
7859 ctxt->perr = 0;
7862 ctxt->state->seq = cur;
7868 ret = xmlRegExecPushString(exec, BAD_CAST "#text", ctxt);
7877 cur->ns->href, ctxt);
7879 ret = xmlRegExecPushString(exec, cur->name, ctxt);
7898 ctxt->state->seq = NULL;
7905 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
7906 xmlRelaxNGDumpValidError(ctxt);
7915 if ((ret == 0) && (ctxt->perr != 0)) {
7916 ctxt->perr;
7918 ctxt->perr = oldperr;
7927 static int xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt,
7929 static int xmlRelaxNGValidateElementEnd(xmlRelaxNGValidCtxtPtr ctxt,
7931 static void xmlRelaxNGLogBestError(xmlRelaxNGValidCtxtPtr ctxt);
7935 * @ctxt: the validation context
7943 xmlRelaxNGElemPush(xmlRelaxNGValidCtxtPtr ctxt, xmlRegExecCtxtPtr exec)
7945 if (ctxt->elemTab == NULL) {
7946 ctxt->elemMax = 10;
7947 ctxt->elemTab = (xmlRegExecCtxtPtr *) xmlMalloc(ctxt->elemMax *
7950 if (ctxt->elemTab == NULL) {
7951 xmlRngVErrMemory(ctxt, "validating\n");
7955 if (ctxt->elemNr >= ctxt->elemMax) {
7956 ctxt->elemMax *= 2;
7957 ctxt->elemTab = (xmlRegExecCtxtPtr *) xmlRealloc(ctxt->elemTab,
7958 ctxt->elemMax *
7961 if (ctxt->elemTab == NULL) {
7962 xmlRngVErrMemory(ctxt, "validating\n");
7966 ctxt->elemTab[ctxt->elemNr++] = exec;
7967 ctxt->elem = exec;
7973 * @ctxt: the validation context
7980 xmlRelaxNGElemPop(xmlRelaxNGValidCtxtPtr ctxt)
7984 if (ctxt->elemNr <= 0)
7986 ctxt->elemNr--;
7987 ret = ctxt->elemTab[ctxt->elemNr];
7988 ctxt->elemTab[ctxt->elemNr] = NULL;
7989 if (ctxt->elemNr > 0)
7990 ctxt->elem = ctxt->elemTab[ctxt->elemNr - 1];
7992 ctxt->elem = NULL;
8012 xmlRelaxNGValidCtxtPtr ctxt = (xmlRelaxNGValidCtxtPtr) inputdata;
8022 if (ctxt == NULL) {
8026 node = ctxt->pnode;
8027 ctxt->pstate = 1;
8032 if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
8033 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
8034 ctxt->pstate = -1;
8037 if ((ctxt == NULL) || (define == NULL)) {
8039 if ((ctxt != NULL) && (ctxt->errNo == XML_RELAXNG_OK))
8040 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
8041 ctxt->pstate = -1;
8045 if (ctxt->errNo == XML_RELAXNG_OK)
8046 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
8047 ctxt->pstate = -1;
8052 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
8053 xmlRelaxNGDumpValidError(ctxt);
8054 ctxt->pstate = -1;
8066 ctxt->pstate = 0;
8067 ctxt->pdef = define;
8071 xmlRelaxNGValidateProgressiveCallback, ctxt);
8073 ctxt->pstate = -1;
8076 xmlRelaxNGElemPush(ctxt, exec);
8081 state = xmlRelaxNGNewValidState(ctxt, node);
8083 ctxt->pstate = -1;
8086 oldstate = ctxt->state;
8087 ctxt->state = state;
8089 ret = xmlRelaxNGValidateAttributeList(ctxt, define->attrs);
8091 ctxt->pstate = -1;
8095 if (ctxt->state != NULL) {
8096 ctxt->state->seq = NULL;
8097 ret = xmlRelaxNGValidateElementEnd(ctxt, 1);
8099 ctxt->pstate = -1;
8101 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
8102 } else if (ctxt->states != NULL) {
8105 oldflags = ctxt->flags;
8107 for (i = 0; i < ctxt->states->nbState; i++) {
8108 state = ctxt->states->tabState[i];
8109 ctxt->state = state;
8110 ctxt->state->seq = NULL;
8112 if (xmlRelaxNGValidateElementEnd(ctxt, 0) == 0) {
8121 ctxt->flags |= FLAGS_IGNORABLE;
8122 xmlRelaxNGLogBestError(ctxt);
8124 for (i = 0; i < ctxt->states->nbState; i++) {
8125 xmlRelaxNGFreeValidState(ctxt, ctxt->states->tabState[i]);
8127 xmlRelaxNGFreeStates(ctxt, ctxt->states);
8128 ctxt->states = NULL;
8130 ctxt->pstate = -1;
8131 ctxt->flags = oldflags;
8133 if (ctxt->pstate == -1) {
8134 if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
8135 xmlRelaxNGDumpValidError(ctxt);
8138 ctxt->state = oldstate;
8143 * @ctxt: the validation context
8153 xmlRelaxNGValidatePushElement(xmlRelaxNGValidCtxtPtr ctxt,
8159 if ((ctxt == NULL) || (elem == NULL))
8165 if (ctxt->elem == 0) {
8171 schema = ctxt->schema;
8183 ctxt->pdef = define;
8188 ctxt);
8192 xmlRelaxNGElemPush(ctxt, exec);
8194 ctxt->pnode = elem;
8195 ctxt->pstate = 0;
8198 xmlRegExecPushString2(ctxt->elem, elem->name, elem->ns->href,
8199 ctxt);
8201 ret = xmlRegExecPushString(ctxt->elem, elem->name, ctxt);
8206 if (ctxt->pstate == 0)
8208 else if (ctxt->pstate < 0)
8223 * @ctxt: the RelaxNG validation context
8232 xmlRelaxNGValidatePushCData(xmlRelaxNGValidCtxtPtr ctxt,
8237 if ((ctxt == NULL) || (ctxt->elem == NULL) || (data == NULL))
8252 ret = xmlRegExecPushString(ctxt->elem, BAD_CAST "#text", ctxt);
8266 * @ctxt: the RelaxNG validation context
8275 xmlRelaxNGValidatePopElement(xmlRelaxNGValidCtxtPtr ctxt,
8282 if ((ctxt == NULL) || (ctxt->elem == NULL) || (elem == NULL))
8290 exec = xmlRelaxNGElemPop(ctxt);
8314 * @ctxt: the validation context
8324 xmlRelaxNGValidateFullElement(xmlRelaxNGValidCtxtPtr ctxt,
8331 if ((ctxt == NULL) || (ctxt->pdef == NULL) || (elem == NULL))
8336 state = xmlRelaxNGNewValidState(ctxt, elem->parent);
8341 ctxt->state = state;
8342 ctxt->errNo = XML_RELAXNG_OK;
8343 ret = xmlRelaxNGValidateDefinition(ctxt, ctxt->pdef);
8344 if ((ret != 0) || (ctxt->errNo != XML_RELAXNG_OK))
8348 xmlRelaxNGFreeValidState(ctxt, state);
8349 ctxt->state = NULL;
8363 static int xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
8368 * @ctxt: a schema validation context
8376 xmlRelaxNGSkipIgnored(xmlRelaxNGValidCtxtPtr ctxt ATTRIBUTE_UNUSED,
8389 ((ctxt->flags & FLAGS_MIXED_CONTENT) ||
8398 * @ctxt: a schema validation context
8407 xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt, const xmlChar * str)
8422 xmlRngVErrMemory(ctxt, "validating\n");
8444 * @ctxt: a Relax-NG validation context
8454 xmlRelaxNGValidateDatatype(xmlRelaxNGValidCtxtPtr ctxt,
8503 oldvalue = ctxt->state->value;
8504 oldendvalue = ctxt->state->endvalue;
8505 ctxt->state->value = (xmlChar *) value;
8506 ctxt->state->endvalue = NULL;
8507 ret = xmlRelaxNGValidateValue(ctxt, define->content);
8508 ctxt->state->value = (xmlChar *) oldvalue;
8509 ctxt->state->endvalue = (xmlChar *) oldendvalue;
8518 * @ctxt: a Relax-NG validation context
8525 xmlRelaxNGNextValue(xmlRelaxNGValidCtxtPtr ctxt)
8529 cur = ctxt->state->value;
8530 if ((cur == NULL) || (ctxt->state->endvalue == NULL)) {
8531 ctxt->state->value = NULL;
8532 ctxt->state->endvalue = NULL;
8537 while ((cur != ctxt->state->endvalue) && (*cur == 0))
8539 if (cur == ctxt->state->endvalue)
8540 ctxt->state->value = NULL;
8542 ctxt->state->value = cur;
8548 * @ctxt: a Relax-NG validation context
8556 xmlRelaxNGValidateValueList(xmlRelaxNGValidCtxtPtr ctxt,
8562 ret = xmlRelaxNGValidateValue(ctxt, defines);
8572 * @ctxt: a Relax-NG validation context
8580 xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
8586 value = ctxt->state->value;
8611 value, ctxt->state->node);
8630 nval = xmlRelaxNGNormalize(ctxt, define->value);
8631 nvalue = xmlRelaxNGNormalize(ctxt, value);
8643 xmlRelaxNGNextValue(ctxt);
8647 ret = xmlRelaxNGValidateDatatype(ctxt, value, define,
8648 ctxt->state->seq);
8650 xmlRelaxNGNextValue(ctxt);
8658 oldflags = ctxt->flags;
8659 ctxt->flags |= FLAGS_IGNORABLE;
8661 oldvalue = ctxt->state->value;
8663 ret = xmlRelaxNGValidateValue(ctxt, list);
8667 ctxt->state->value = oldvalue;
8670 ctxt->flags = oldflags;
8672 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
8673 xmlRelaxNGDumpValidError(ctxt);
8675 if (ctxt->errNr > 0)
8676 xmlRelaxNGPopErrors(ctxt, 0);
8688 oldvalue = ctxt->state->value;
8689 oldend = ctxt->state->endvalue;
8718 ctxt->state->endvalue = cur;
8720 while ((*cur == 0) && (cur != ctxt->state->endvalue))
8723 ctxt->state->value = cur;
8726 if (ctxt->state->value == ctxt->state->endvalue)
8727 ctxt->state->value = NULL;
8728 ret = xmlRelaxNGValidateValue(ctxt, list);
8733 ctxt->state->value, nb_values);
8743 if ((ret == 0) && (ctxt->state->value != NULL) &&
8744 (ctxt->state->value != ctxt->state->endvalue)) {
8746 ctxt->state->value);
8750 ctxt->state->value = oldvalue;
8751 ctxt->state->endvalue = oldend;
8755 ret = xmlRelaxNGValidateValueList(ctxt, define->content);
8763 oldflags = ctxt->flags;
8764 ctxt->flags |= FLAGS_IGNORABLE;
8765 cur = ctxt->state->value;
8767 while ((cur != NULL) && (cur != ctxt->state->endvalue) &&
8771 xmlRelaxNGValidateValueList(ctxt, define->content);
8773 ctxt->state->value = temp;
8777 cur = ctxt->state->value;
8779 ctxt->flags = oldflags;
8780 if (ctxt->errNr > 0)
8781 xmlRelaxNGPopErrors(ctxt, 0);
8789 ret = xmlRelaxNGValidateValue(ctxt, list);
8805 ret = xmlRelaxNGValidateValue(ctxt, list);
8819 ret = xmlRelaxNGValidateValue(ctxt, define->content);
8829 * @ctxt: a Relax-NG validation context
8837 xmlRelaxNGValidateValueContent(xmlRelaxNGValidCtxtPtr ctxt,
8843 ret = xmlRelaxNGValidateValue(ctxt, defines);
8853 * @ctxt: a Relax-NG validation context
8862 xmlRelaxNGAttributeMatch(xmlRelaxNGValidCtxtPtr ctxt,
8889 ret = xmlRelaxNGAttributeMatch(ctxt, list, prop);
8903 * @ctxt: a Relax-NG validation context
8911 xmlRelaxNGValidateAttribute(xmlRelaxNGValidCtxtPtr ctxt,
8919 if (ctxt->state->nbAttrLeft <= 0)
8922 for (i = 0; i < ctxt->state->nbAttrs; i++) {
8923 tmp = ctxt->state->attrs[i];
8936 oldvalue = ctxt->state->value;
8937 oldseq = ctxt->state->seq;
8938 ctxt->state->seq = (xmlNodePtr) prop;
8939 ctxt->state->value = value;
8940 ctxt->state->endvalue = NULL;
8941 ret = xmlRelaxNGValidateValueContent(ctxt, define->content);
8942 if (ctxt->state->value != NULL)
8943 value = ctxt->state->value;
8946 ctxt->state->value = oldvalue;
8947 ctxt->state->seq = oldseq;
8952 ctxt->state->attrs[i] = NULL;
8953 ctxt->state->nbAttrLeft--;
8964 for (i = 0; i < ctxt->state->nbAttrs; i++) {
8965 tmp = ctxt->state->attrs[i];
8967 (xmlRelaxNGAttributeMatch(ctxt, define, tmp) == 1)) {
8974 oldvalue = ctxt->state->value;
8975 oldseq = ctxt->state->seq;
8976 ctxt->state->seq = (xmlNodePtr) prop;
8977 ctxt->state->value = value;
8978 ret = xmlRelaxNGValidateValueContent(ctxt
8979 if (ctxt->state->value != NULL)
8980 value = ctxt->state->value;
8983 ctxt->state->value = oldvalue;
8984 ctxt->state->seq = oldseq;
8989 ctxt->state->attrs[i] = NULL;
8990 ctxt->state->nbAttrLeft--;
9013 * @ctxt: a Relax-NG validation context
9021 xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt,
9031 if (xmlRelaxNGValidateAttribute(ctxt, cur) != 0)
9042 if ((ctxt->state != NULL) || (ctxt->states != NULL)) {
9043 res = xmlRelaxNGValidateDefinition(ctxt, cur);
9096 * @ctxt: a Relax-NG validation context
9104 xmlRelaxNGValidateInterleave(xmlRelaxNGValidCtxtPtr ctxt,
9108 int errNr = ctxt->errNr;
9127 oldflags = ctxt->flags;
9129 ctxt->flags |= FLAGS_MIXED_CONTENT;
9134 if (ctxt->state != NULL)
9135 ctxt->state->seq = xmlRelaxNGSkipIgnored(ctxt,
9136 ctxt->state->seq);
9138 ret = xmlRelaxNGValidateDefinition(ctxt,
9142 ret = xmlRelaxNGValidateDefinition(ctxt,
9146 if (ctxt->state != NULL)
9147 ctxt->state->seq = xmlRelaxNGSkipIgnored(ctxt,
9148 ctxt->state->
9151 ctxt->flags = oldflags;
9162 xmlRngVErrMemory(ctxt, "validating\n");
9168 xmlRngVErrMemory(ctxt, "validating\n");
9177 cur = ctxt->state->seq;
9178 cur = xmlRelaxNGSkipIgnored(ctxt, cur);
9181 ctxt->state->seq = cur;
9244 cur = xmlRelaxNGSkipIgnored(ctxt, cur->next);
9252 oldstate = ctxt->state;
9254 ctxt->state = xmlRelaxNGCopyValidState(ctxt, oldstate);
9260 ctxt->state->seq = list[i];
9261 ret = xmlRelaxNGValidateDefinition(ctxt, group->rule);
9264 if (ctxt->state != NULL) {
9265 cur = ctxt->state->seq;
9266 cur = xmlRelaxNGSkipIgnored(ctxt, cur);
9267 xmlRelaxNGFreeValidState(ctxt, oldstate);
9268 oldstate = ctxt->state;
9269 ctxt->state = NULL;
9273 ctxt->state = oldstate;
9276 } else if (ctxt->states != NULL) {
9286 for (j = 0; j < ctxt->states->nbState; j++) {
9287 cur = ctxt->states->tabState[j]->seq;
9288 cur = xmlRelaxNGSkipIgnored(ctxt, cur);
9291 lowattr = ctxt->states->tabState[j]->nbAttrLeft;
9295 if (ctxt->states->tabState[j]->nbAttrLeft <= lowattr) {
9297 lowattr = ctxt->states->tabState[j]->nbAttrLeft;
9304 lowattr = ctxt->states->tabState[j]->nbAttrLeft;
9307 if (ctxt->states->tabState[j]->nbAttrLeft <= lowattr) {
9309 lowattr = ctxt->states->tabState[j]->nbAttrLeft;
9317 if (ctxt->states->nbState > 0) {
9318 xmlRelaxNGFreeValidState(ctxt, oldstate);
9320 oldstate = ctxt->states->tabState[best];
9321 ctxt->states->tabState[best] = NULL;
9324 ctxt->states->tabState[ctxt->states->nbState - 1];
9325 ctxt->states->tabState[ctxt->states->nbState - 1] = NULL;
9328 for (j = 0; j < ctxt->states->nbState ; j++) {
9329 xmlRelaxNGFreeValidState(ctxt, ctxt->states->tabState[j]);
9331 xmlRelaxNGFreeStates(ctxt, ctxt->states);
9332 ctxt->states = NULL;
9336 ctxt->state = oldstate;
9347 if (ctxt->state != NULL)
9348 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
9349 ctxt->state = oldstate;
9350 ctxt->state->seq = lastelem;
9358 ctxt->flags = oldflags;
9370 if (ctxt->errNr > errNr)
9371 xmlRelaxNGPopErrors(ctxt, errNr);
9381 * @ctxt: a Relax-NG validation context
9389 xmlRelaxNGValidateDefinitionList(xmlRelaxNGValidCtxtPtr ctxt,
9401 if ((ctxt->state != NULL) || (ctxt->states != NULL)) {
9402 res = xmlRelaxNGValidateDefinition(ctxt, defines);
9419 * @ctxt: a Relax-NG validation context
9428 xmlRelaxNGElementMatch(xmlRelaxNGValidCtxtPtr ctxt,
9464 if (ctxt != NULL) {
9465 oldflags = ctxt->flags;
9466 ctxt->flags |= FLAGS_IGNORABLE;
9471 ret = xmlRelaxNGElementMatch(ctxt, list, elem);
9473 if (ctxt != NULL)
9474 ctxt->flags = oldflags;
9478 if (ctxt != NULL)
9479 ctxt->flags = oldflags;
9485 if (ctxt != NULL) {
9486 ctxt->flags = oldflags;
9491 if (ctxt != NULL) {
9492 oldflags = ctxt->flags;
9493 ctxt->flags |= FLAGS_IGNORABLE;
9498 ret = xmlRelaxNGElementMatch(ctxt, list, elem);
9500 if (ctxt != NULL)
9501 ctxt->flags = oldflags;
9505 if (ctxt != NULL)
9506 ctxt->flags = oldflags;
9511 if (ctxt != NULL) {
9513 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9514 xmlRelaxNGDumpValidError(ctxt);
9516 if (ctxt->errNr > 0)
9517 xmlRelaxNGPopErrors(ctxt, 0);
9521 if (ctxt != NULL) {
9522 ctxt->flags = oldflags;
9532 * @ctxt: a Relax-NG validation context
9534 * Find the "best" state in the ctxt->states list of states to report
9542 xmlRelaxNGBestState(xmlRelaxNGValidCtxtPtr ctxt)
9549 if ((ctxt == NULL) || (ctxt->states == NULL) ||
9550 (ctxt->states->nbState <= 0))
9553 for (i = 0; i < ctxt->states->nbState; i++) {
9554 state = ctxt->states->tabState[i];
9575 * @ctxt: a Relax-NG validation context
9577 * Find the "best" state in the ctxt->states list of states to report
9581 xmlRelaxNGLogBestError(xmlRelaxNGValidCtxtPtr ctxt)
9585 if ((ctxt == NULL) || (ctxt->states == NULL) ||
9586 (ctxt->states->nbState <= 0))
9589 best = xmlRelaxNGBestState(ctxt);
9590 if ((best >= 0) && (best < ctxt->states->nbState)) {
9591 ctxt->state = ctxt->states->tabState[best];
9593 xmlRelaxNGValidateElementEnd(ctxt, 1);
9599 * @ctxt: a Relax-NG validation context
9609 xmlRelaxNGValidateElementEnd(xmlRelaxNGValidCtxtPtr ctxt, int dolog)
9614 state = ctxt->state;
9616 state->seq = xmlRelaxNGSkipIgnored(ctxt, state->seq);
9639 * @ctxt: a Relax-NG validation context
9647 xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt,
9659 if (ctxt->state != NULL) {
9660 node = ctxt->state->seq;
9665 for (i = 0; i < ctxt->depth; i++)
9676 ctxt->depth++;
9679 node = xmlRelaxNGSkipIgnored(ctxt, node);
9692 ctxt->state->seq = node;
9695 errNr = ctxt->errNr;
9696 node = xmlRelaxNGSkipIgnored(ctxt, node);
9700 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9701 xmlRelaxNGDumpValidError(ctxt);
9707 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9708 xmlRelaxNGDumpValidError(ctxt);
9716 ctxt->state->seq = xmlRelaxNGSkipIgnored(ctxt, node->next);
9717 if (ctxt->errNr > errNr)
9718 xmlRelaxNGPopErrors(ctxt, errNr);
9719 if (ctxt->errNr != 0) {
9720 while ((ctxt->err != NULL) &&
9721 (((ctxt->err->err == XML_RELAXNG_ERR_ELEMNAME)
9722 && (xmlStrEqual(ctxt->err->arg2, node->name)))
9724 ((ctxt->err->err ==
9726 && (xmlStrEqual(ctxt->err->arg1, node->name)))
9727 || (ctxt->err->err == XML_RELAXNG_ERR_NOELEM)
9728 || (ctxt->err->err ==
9730 xmlRelaxNGValidErrorPop(ctxt);
9735 ret = xmlRelaxNGElementMatch(ctxt, define, node);
9738 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9739 xmlRelaxNGDumpValidError(ctxt);
9743 if (ctxt->errNr != 0) {
9744 if (ctxt->errNr > errNr)
9745 xmlRelaxNGPopErrors(ctxt, errNr);
9746 while ((ctxt->err != NULL) &&
9747 (((ctxt->err->err == XML_RELAXNG_ERR_ELEMNAME) &&
9748 (xmlStrEqual(ctxt->err->arg2, node->name))) ||
9749 ((ctxt->err->err == XML_RELAXNG_ERR_ELEMEXTRANS) &&
9750 (xmlStrEqual(ctxt->err->arg1, node->name))) ||
9751 (ctxt->err->err == XML_RELAXNG_ERR_NOELEM) ||
9752 (ctxt->err->err == XML_RELAXNG_ERR_NOTELEM)))
9753 xmlRelaxNGValidErrorPop(ctxt);
9755 errNr = ctxt->errNr;
9757 oldflags = ctxt->flags;
9758 if (ctxt->flags & FLAGS_MIXED_CONTENT) {
9759 ctxt->flags -= FLAGS_MIXED_CONTENT;
9761 state = xmlRelaxNGNewValidState(ctxt, node);
9764 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9765 xmlRelaxNGDumpValidError(ctxt);
9769 oldstate = ctxt->state;
9770 ctxt->state = state;
9772 tmp = xmlRelaxNGValidateAttributeList(ctxt, define->attrs);
9779 xmlRelaxNGValidStatePtr nstate, tmpstate = ctxt->state;
9780 xmlRelaxNGStatesPtr tmpstates = ctxt->states;
9783 nstate = xmlRelaxNGNewValidState(ctxt, node);
9784 ctxt->state = nstate;
9785 ctxt->states = NULL;
9787 tmp = xmlRelaxNGValidateCompiledContent(ctxt,
9789 ctxt->state->seq);
9790 nseq = ctxt->state->seq;
9791 ctxt->state = tmpstate;
9792 ctxt->states = tmpstates;
9793 xmlRelaxNGFreeValidState(ctxt, nstate);
9803 if (ctxt->states != NULL) {
9806 for (i = 0; i < ctxt->states->nbState; i++) {
9807 state = ctxt->states->tabState[i];
9808 ctxt->state = state;
9809 ctxt->state->seq = nseq;
9811 if (xmlRelaxNGValidateElementEnd(ctxt, 0) == 0) {
9820 ctxt->flags |= FLAGS_IGNORABLE;
9821 xmlRelaxNGLogBestError(ctxt);
9823 for (i = 0; i < ctxt->states->nbState; i++) {
9824 xmlRelaxNGFreeValidState(ctxt,
9825 ctxt->states->
9828 xmlRelaxNGFreeStates(ctxt, ctxt->states);
9829 ctxt->flags = oldflags;
9830 ctxt->states = NULL;
9834 state = ctxt->state;
9835 if (ctxt->state != NULL)
9836 ctxt->state->seq = nseq;
9838 ret = xmlRelaxNGValidateElementEnd(ctxt, 1);
9839 xmlRelaxNGFreeValidState(ctxt, state);
9843 tmp = xmlRelaxNGValidateDefinitionList(ctxt,
9848 if (ctxt->state == NULL) {
9849 ctxt->state = oldstate;
9852 ctxt->state = NULL;
9860 if (ctxt->states != NULL) {
9863 for (i = 0; i < ctxt->states->nbState; i++) {
9864 state = ctxt->states->tabState[i];
9865 ctxt->state = state;
9867 if (xmlRelaxNGValidateElementEnd(ctxt, 0) == 0) {
9876 ctxt->flags |= FLAGS_IGNORABLE;
9877 xmlRelaxNGLogBestError(ctxt);
9879 for (i = 0; i < ctxt->states->nbState; i++) {
9880 xmlRelaxNGFreeValidState(ctxt,
9881 ctxt->states->
9884 xmlRelaxNGFreeStates(ctxt, ctxt->states);
9885 ctxt->flags = oldflags;
9886 ctxt->states = NULL;
9890 state = ctxt->state;
9892 ret = xmlRelaxNGValidateElementEnd(ctxt, 1);
9893 xmlRelaxNGFreeValidState(ctxt, state);
9899 ctxt->flags = oldflags;
9900 ctxt->state = oldstate;
9902 oldstate->seq = xmlRelaxNGSkipIgnored(ctxt, node->next);
9904 if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
9905 xmlRelaxNGDumpValidError(ctxt);
9913 if (ctxt->errNr > errNr)
9914 xmlRelaxNGPopErrors(ctxt, errNr);
9934 errNr = ctxt->errNr;
9935 oldflags = ctxt->flags;
9936 ctxt->flags |= FLAGS_IGNORABLE;
9937 oldstate = xmlRelaxNGCopyValidState(ctxt, ctxt->state);
9939 xmlRelaxNGValidateDefinitionList(ctxt,
9942 if (ctxt->state != NULL)
9943 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
9944 ctxt->state = oldstate;
9945 ctxt->flags = oldflags;
9947 if (ctxt->errNr > errNr)
9948 xmlRelaxNGPopErrors(ctxt, errNr);
9951 if (ctxt->states != NULL) {
9952 xmlRelaxNGAddStates(ctxt, ctxt->states, oldstate);
9954 ctxt->states = xmlRelaxNGNewStates(ctxt, 1);
9955 if (ctxt->states == NULL) {
9956 xmlRelaxNGFreeValidState(ctxt, oldstate);
9957 ctxt->flags = oldflags;
9959 if (ctxt->errNr > errNr)
9960 xmlRelaxNGPopErrors(ctxt, errNr);
9963 ctxt, ctxt->states, oldstate);
9964 xmlRelaxNGAddStates(ctxt, ctxt->states, ctxt->state);
9965 ctxt->state = NULL;
9967 ctxt->flags = oldflags;
9969 if (ctxt->errNr > errNr)
9970 xmlRelaxNGPopErrors(ctxt, errNr);
9974 errNr = ctxt->errNr;
9975 ret = xmlRelaxNGValidateDefinitionList(ctxt, define->content);
9979 if (ctxt->errNr > errNr)
9980 xmlRelaxNGPopErrors(ctxt, errNr);
9987 errNr = ctxt->errNr;
9988 res = xmlRelaxNGNewStates(ctxt, 1);
9996 if (ctxt->state != NULL) {
9997 xmlRelaxNGAddStates(ctxt, res,
9998 xmlRelaxNGCopyValidState(ctxt,
9999 ctxt->
10002 for (j = 0; j < ctxt->states->nbState; j++) {
10003 xmlRelaxNGAddStates(ctxt, res,
10004 xmlRelaxNGCopyValidState(ctxt,
10005 ctxt->
10011 oldflags = ctxt->flags;
10012 ctxt->flags |= FLAGS_IGNORABLE;
10017 if (ctxt->states != NULL) {
10018 states = ctxt->states;
10020 ctxt->state = states->tabState[i];
10021 ctxt->states = NULL;
10022 ret = xmlRelaxNGValidateDefinitionList(ctxt,
10026 if (ctxt->state != NULL) {
10027 tmp = xmlRelaxNGAddStates(ctxt, res,
10028 ctxt->state);
10029 ctxt->state = NULL;
10032 } else if (ctxt->states != NULL) {
10033 for (j = 0; j < ctxt->states->nbState;
10036 xmlRelaxNGAddStates(ctxt, res,
10037 ctxt->
10044 xmlRelaxNGFreeStates(ctxt,
10045 ctxt->states);
10046 ctxt->states = NULL;
10049 if (ctxt->state != NULL) {
10050 xmlRelaxNGFreeValidState(ctxt,
10051 ctxt->state);
10052 ctxt->state = NULL;
10057 ret = xmlRelaxNGValidateDefinitionList(ctxt,
10061 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10062 ctxt->state = NULL;
10065 if (ctxt->state != NULL) {
10066 tmp = xmlRelaxNGAddStates(ctxt, res,
10067 ctxt->state);
10068 ctxt->state = NULL;
10071 } else if (ctxt->states != NULL) {
10072 for (j = 0; j < ctxt->states->nbState; j++) {
10073 tmp = xmlRelaxNGAddStates(ctxt, res,
10074 ctxt->
10081 states = ctxt->states;
10083 xmlRelaxNGFreeStates(ctxt,
10084 ctxt->states);
10086 ctxt->states = NULL;
10096 ctxt->state = xmlRelaxNGCopyValidState(ctxt,
10102 xmlRelaxNGNewStates(ctxt,
10104 states = ctxt->states;
10112 xmlRelaxNGAddStates(ctxt, states,
10114 (ctxt,
10116 ctxt->states = states;
10121 xmlRelaxNGFreeStates(ctxt, states);
10123 ctxt->states = res;
10124 ctxt->flags = oldflags;
10129 if (ctxt->errNr > errNr)
10130 xmlRelaxNGPopErrors(ctxt, errNr);
10139 node = xmlRelaxNGSkipIgnored(ctxt, node);
10141 errNr = ctxt->errNr;
10181 ret = xmlRelaxNGValidateDefinition(ctxt, list);
10188 oldflags = ctxt->flags;
10189 ctxt->flags |= FLAGS_IGNORABLE;
10192 oldstate = xmlRelaxNGCopyValidState(ctxt, ctxt->state);
10193 ret = xmlRelaxNGValidateDefinition(ctxt, list);
10196 states = xmlRelaxNGNewStates(ctxt, 1);
10198 if (ctxt->state != NULL) {
10199 xmlRelaxNGAddStates(ctxt, states, ctxt->state);
10200 } else if (ctxt->states != NULL) {
10201 for (i = 0; i < ctxt->states->nbState; i++) {
10202 xmlRelaxNGAddStates(ctxt, states,
10203 ctxt->states->
10206 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10207 ctxt->states = NULL;
10210 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10212 ctxt->state = oldstate;
10216 xmlRelaxNGFreeValidState(ctxt, oldstate);
10217 ctxt->states = states;
10218 ctxt->state = NULL;
10221 ctxt->states = NULL;
10223 ctxt->flags = oldflags;
10225 if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
10226 xmlRelaxNGDumpValidError(ctxt);
10229 if (ctxt->errNr > errNr)
10230 xmlRelaxNGPopErrors(ctxt, errNr);
10236 ret = xmlRelaxNGValidateDefinitionList(ctxt, define->content);
10239 ret = xmlRelaxNGValidateInterleave(ctxt, define);
10242 ret = xmlRelaxNGValidateAttribute(ctxt, define);
10249 ret = xmlRelaxNGValidateDefinition(ctxt, define->content);
10277 xmlRngVErrMemory(ctxt, "validating\n");
10282 ret = xmlRelaxNGValidateDatatype(ctxt, content, define,
10283 ctxt->state->seq);
10287 ctxt->state->seq = NULL;
10320 xmlRngVErrMemory(ctxt, "validating\n");
10325 oldvalue = ctxt->state->value;
10326 ctxt->state->value = content;
10327 ret = xmlRelaxNGValidateValue(ctxt, define);
10328 ctxt->state->value = oldvalue;
10332 ctxt->state->seq = NULL;
10371 xmlRngVErrMemory(ctxt, "validating\n");
10377 oldvalue = ctxt->state->value;
10378 oldendvalue = ctxt->state->endvalue;
10379 ctxt->state->value = content;
10380 ctxt->state->endvalue = content + len;
10381 ret = xmlRelaxNGValidateValue(ctxt, define);
10382 ctxt->state->value = oldvalue;
10383 ctxt->state->endvalue = oldendvalue;
10387 ctxt->state->seq = node->next;
10398 ctxt->depth--;
10400 for (i = 0; i < ctxt->depth; i++)
10416 * @ctxt: a Relax-NG validation context
10424 xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt,
10431 * We should NOT have both ctxt->state and ctxt->states
10433 if ((ctxt->state != NULL) && (ctxt->states != NULL)) {
10434 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10435 ctxt->state = NULL;
10438 if ((ctxt->states == NULL) || (ctxt->states->nbState == 1)) {
10439 if (ctxt->states != NULL) {
10440 ctxt->state = ctxt->states->tabState[0];
10441 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10442 ctxt->states = NULL;
10444 ret = xmlRelaxNGValidateState(ctxt, define);
10445 if ((ctxt->state != NULL) && (ctxt->states != NULL)) {
10446 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10447 ctxt->state = NULL;
10449 if ((ctxt->states != NULL) && (ctxt->states->nbState == 1)) {
10450 ctxt->state = ctxt->states->tabState[0];
10451 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10452 ctxt->states = NULL;
10457 states = ctxt->states;
10458 ctxt->states = NULL;
10461 oldflags = ctxt->flags;
10462 ctxt->flags |= FLAGS_IGNORABLE;
10464 ctxt->state = states->tabState[i];
10465 ctxt->states = NULL;
10466 ret = xmlRelaxNGValidateState(ctxt, define);
10468 * We should NOT have both ctxt->state and ctxt->states
10470 if ((ctxt->state != NULL) && (ctxt->states != NULL)) {
10471 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10472 ctxt->state = NULL;
10475 if (ctxt->states == NULL) {
10478 xmlRelaxNGAddStates(ctxt, res, ctxt->state);
10479 ctxt->state = NULL;
10482 states->tabState[j++] = ctxt->state;
10483 ctxt->state = NULL;
10488 res = ctxt->states;
10489 ctxt->states = NULL;
10491 xmlRelaxNGAddStates(ctxt, res,
10495 for (k = 0; k < ctxt->states->nbState; k++)
10496 xmlRelaxNGAddStates(ctxt, res,
10497 ctxt->states->tabState[k]);
10498 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10499 ctxt->states = NULL;
10503 if (ctxt->state != NULL) {
10504 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10505 ctxt->state = NULL;
10506 } else if (ctxt->states != NULL) {
10507 for (k = 0; k < ctxt->states->nbState; k++)
10508 xmlRelaxNGFreeValidState(ctxt,
10509 ctxt->states->tabState[k]);
10510 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10511 ctxt->states = NULL;
10515 ctxt->flags = oldflags;
10517 xmlRelaxNGFreeStates(ctxt, states);
10518 ctxt->states = res;
10522 ctxt->states = states;
10525 ctxt->state = states->tabState[0];
10526 xmlRelaxNGFreeStates(ctxt, states);
10530 xmlRelaxNGFreeStates(ctxt, states);
10531 if (ctxt->states != NULL) {
10532 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10533 ctxt->states = NULL;
10536 if ((ctxt->state != NULL) && (ctxt->states != NULL)) {
10537 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10538 ctxt->state = NULL;
10545 * @ctxt: a Relax-NG validation context
10553 xmlRelaxNGValidateDocument(xmlRelaxNGValidCtxtPtr ctxt, xmlDocPtr doc)
10561 if ((ctxt == NULL) || (ctxt->schema == NULL) || (doc == NULL))
10564 ctxt->errNo = XML_RELAXNG_OK;
10565 schema = ctxt->schema;
10571 state = xmlRelaxNGNewValidState(ctxt, NULL);
10572 ctxt->state = state;
10573 ret = xmlRelaxNGValidateDefinition(ctxt, grammar->start);
10574 if ((ctxt->state != NULL) && (state->seq != NULL)) {
10575 state = ctxt->state;
10577 node = xmlRelaxNGSkipIgnored(ctxt, node);
10584 } else if (ctxt->states != NULL) {
10588 for (i = 0; i < ctxt->states->nbState; i++) {
10589 state = ctxt->states->tabState[i];
10591 node = xmlRelaxNGSkipIgnored(ctxt, node);
10594 xmlRelaxNGFreeValidState(ctxt, state);
10603 if (ctxt->state != NULL) {
10604 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10605 ctxt->state = NULL;
10608 xmlRelaxNGDumpValidError(ctxt);
10610 else if (ctxt->errNr != 0) {
10611 ctxt->error(ctxt->userData,
10613 ctxt->errNr);
10614 xmlRelaxNGDumpValidError(ctxt);
10618 if (ctxt->idref == 1) {
10623 vctxt.error = ctxt->error;
10624 vctxt.warning = ctxt->warning;
10625 vctxt.userData = ctxt->userData;
10631 if ((ret == 0) && (ctxt->errNo != XML_RELAXNG_OK))
10680 * @ctxt: the schema validation context
10685 xmlRelaxNGFreeValidCtxt(xmlRelaxNGValidCtxtPtr ctxt)
10689 if (ctxt == NULL)
10691 if (ctxt->states != NULL)
10692 xmlRelaxNGFreeStates(NULL, ctxt->states);
10693 if (ctxt->freeState != NULL) {
10694 for (k = 0; k < ctxt->freeState->nbState; k++) {
10695 xmlRelaxNGFreeValidState(NULL, ctxt->freeState->tabState[k]);
10697 xmlRelaxNGFreeStates(NULL, ctxt->freeState);
10699 if (ctxt->freeStates != NULL) {
10700 for (k = 0; k < ctxt->freeStatesNr; k++) {
10701 xmlRelaxNGFreeStates(NULL, ctxt->freeStates[k]);
10703 xmlFree(ctxt->freeStates);
10705 if (ctxt->errTab != NULL)
10706 xmlFree(ctxt->errTab);
10707 if (ctxt->elemTab != NULL) {
10710 exec = xmlRelaxNGElemPop(ctxt);
10713 exec = xmlRelaxNGElemPop(ctxt);
10715 xmlFree(ctxt->elemTab);
10717 xmlFree(ctxt);
10722 * @ctxt: a Relax-NG validation context
10730 xmlRelaxNGSetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
10734 if (ctxt == NULL)
10736 ctxt->error = err;
10737 ctxt->warning = warn;
10738 ctxt->userData = ctx;
10739 ctxt->serror = NULL;
10744 * @ctxt: a Relax-NG validation context
10751 xmlRelaxNGSetValidStructuredErrors(xmlRelaxNGValidCtxtPtr ctxt,
10754 if (ctxt == NULL)
10756 ctxt->serror = serror;
10757 ctxt->error = NULL;
10758 ctxt->warning = NULL;
10759 ctxt->userData = ctx;
10764 * @ctxt: a Relax-NG validation context
10774 xmlRelaxNGGetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
10778 if (ctxt == NULL)
10781 *err = ctxt->error;
10783 *warn = ctxt->warning;
10785 *ctx = ctxt->userData;
10791 * @ctxt: a Relax-NG validation context
10800 xmlRelaxNGValidateDoc(xmlRelaxNGValidCtxtPtr ctxt, xmlDocPtr doc)
10804 if ((ctxt == NULL) || (doc == NULL))
10807 ctxt->doc = doc;
10809 ret = xmlRelaxNGValidateDocument(ctxt, doc);