19#ifdef LIBXML_SCHEMAS_ENABLED
41 "http://relaxng.org/ns/structure/1.0";
43#define IS_RELAXNG(node, typ) \
44 ((node != NULL) && (node->ns != NULL) && \
45 (node->type == XML_ELEMENT_NODE) && \
46 (xmlStrEqual(node->name, (const xmlChar *) typ)) && \
47 (xmlStrEqual(node->ns->href, xmlRelaxNGNs)))
53#define DEBUG_GRAMMAR 1
55#define DEBUG_CONTENT 1
61#define DEBUG_INTERLEAVE 1
65#define DEBUG_INCLUDE 1
69#define DEBUG_COMPILE 1
71#define DEBUG_PROGRESSIVE 1
77 xmlGenericError(xmlGenericErrorContext, \
78 "Unimplemented block at %s:%d\n", \
81typedef struct _xmlRelaxNGSchema xmlRelaxNGSchema;
82typedef xmlRelaxNGSchema *xmlRelaxNGSchemaPtr;
84typedef struct _xmlRelaxNGDefine xmlRelaxNGDefine;
85typedef xmlRelaxNGDefine *xmlRelaxNGDefinePtr;
87typedef struct _xmlRelaxNGDocument xmlRelaxNGDocument;
88typedef xmlRelaxNGDocument *xmlRelaxNGDocumentPtr;
90typedef struct _xmlRelaxNGInclude xmlRelaxNGInclude;
91typedef xmlRelaxNGInclude *xmlRelaxNGIncludePtr;
94 XML_RELAXNG_COMBINE_UNDEFINED = 0,
95 XML_RELAXNG_COMBINE_CHOICE,
96 XML_RELAXNG_COMBINE_INTERLEAVE
100 XML_RELAXNG_CONTENT_ERROR = -1,
101 XML_RELAXNG_CONTENT_EMPTY = 0,
102 XML_RELAXNG_CONTENT_SIMPLE,
103 XML_RELAXNG_CONTENT_COMPLEX
104} xmlRelaxNGContentType;
106typedef struct _xmlRelaxNGGrammar xmlRelaxNGGrammar;
107typedef xmlRelaxNGGrammar *xmlRelaxNGGrammarPtr;
109struct _xmlRelaxNGGrammar {
110 xmlRelaxNGGrammarPtr
parent;
111 xmlRelaxNGGrammarPtr children;
112 xmlRelaxNGGrammarPtr
next;
113 xmlRelaxNGDefinePtr
start;
114 xmlRelaxNGCombine combine;
115 xmlRelaxNGDefinePtr startList;
122 XML_RELAXNG_NOOP = -1,
123 XML_RELAXNG_EMPTY = 0,
124 XML_RELAXNG_NOT_ALLOWED,
128 XML_RELAXNG_DATATYPE,
132 XML_RELAXNG_ATTRIBUTE,
135 XML_RELAXNG_EXTERNALREF,
136 XML_RELAXNG_PARENTREF,
137 XML_RELAXNG_OPTIONAL,
138 XML_RELAXNG_ZEROORMORE,
139 XML_RELAXNG_ONEORMORE,
142 XML_RELAXNG_INTERLEAVE,
146#define IS_NULLABLE (1 << 0)
147#define IS_NOT_NULLABLE (1 << 1)
148#define IS_INDETERMINIST (1 << 2)
149#define IS_MIXED (1 << 3)
150#define IS_TRIABLE (1 << 4)
151#define IS_PROCESSED (1 << 5)
152#define IS_COMPILABLE (1 << 6)
153#define IS_NOT_COMPILABLE (1 << 7)
154#define IS_EXTERNAL_REF (1 << 8)
156struct _xmlRelaxNGDefine {
164 xmlRelaxNGDefinePtr
parent;
165 xmlRelaxNGDefinePtr
next;
166 xmlRelaxNGDefinePtr attrs;
167 xmlRelaxNGDefinePtr nameClass;
168 xmlRelaxNGDefinePtr nextHash;
171 xmlRegexpPtr contModel;
181 xmlRelaxNGGrammarPtr topgrammar;
188 xmlRelaxNGDocumentPtr documents;
191 xmlRelaxNGDefinePtr *defTab;
195#define XML_RELAXNG_IN_ATTRIBUTE (1 << 0)
196#define XML_RELAXNG_IN_ONEORMORE (1 << 1)
197#define XML_RELAXNG_IN_LIST (1 << 2)
198#define XML_RELAXNG_IN_DATAEXCEPT (1 << 3)
199#define XML_RELAXNG_IN_START (1 << 4)
200#define XML_RELAXNG_IN_OOMGROUP (1 << 5)
201#define XML_RELAXNG_IN_OOMINTERLEAVE (1 << 6)
202#define XML_RELAXNG_IN_EXTERNALREF (1 << 7)
203#define XML_RELAXNG_IN_ANYEXCEPT (1 << 8)
204#define XML_RELAXNG_IN_NSEXCEPT (1 << 9)
206struct _xmlRelaxNGParserCtxt {
208 xmlRelaxNGValidityErrorFunc
error;
209 xmlRelaxNGValidityWarningFunc
warning;
211 xmlRelaxNGValidErr
err;
214 xmlRelaxNGGrammarPtr grammar;
215 xmlRelaxNGGrammarPtr parentgrammar;
220 xmlRelaxNGDefinePtr def;
225 xmlRelaxNGDocumentPtr documents;
232 xmlRelaxNGDefinePtr *defTab;
238 xmlRelaxNGDocumentPtr doc;
241 xmlRelaxNGDocumentPtr *docTab;
244 xmlRelaxNGIncludePtr inc;
247 xmlRelaxNGIncludePtr *incTab;
253 xmlAutomataStatePtr
state;
259#define FLAGS_IGNORABLE 1
260#define FLAGS_NEGATIVE 2
261#define FLAGS_MIXED_CONTENT 4
262#define FLAGS_NOERROR 8
269typedef struct _xmlRelaxNGInterleaveGroup xmlRelaxNGInterleaveGroup;
270typedef xmlRelaxNGInterleaveGroup *xmlRelaxNGInterleaveGroupPtr;
271struct _xmlRelaxNGInterleaveGroup {
272 xmlRelaxNGDefinePtr rule;
273 xmlRelaxNGDefinePtr *defs;
274 xmlRelaxNGDefinePtr *attrs;
277#define IS_DETERMINIST 1
278#define IS_NEEDCHECK 2
285typedef struct _xmlRelaxNGPartition xmlRelaxNGPartition;
286typedef xmlRelaxNGPartition *xmlRelaxNGPartitionPtr;
287struct _xmlRelaxNGPartition {
292 xmlRelaxNGInterleaveGroupPtr *
groups;
301typedef struct _xmlRelaxNGValidState xmlRelaxNGValidState;
302typedef xmlRelaxNGValidState *xmlRelaxNGValidStatePtr;
303struct _xmlRelaxNGValidState {
319typedef struct _xmlRelaxNGStates xmlRelaxNGStates;
320typedef xmlRelaxNGStates *xmlRelaxNGStatesPtr;
321struct _xmlRelaxNGStates {
324 xmlRelaxNGValidStatePtr *tabState;
327#define ERROR_IS_DUP 1
334typedef struct _xmlRelaxNGValidError xmlRelaxNGValidError;
335typedef xmlRelaxNGValidError *xmlRelaxNGValidErrorPtr;
336struct _xmlRelaxNGValidError {
337 xmlRelaxNGValidErr
err;
351struct _xmlRelaxNGValidCtxt {
353 xmlRelaxNGValidityErrorFunc
error;
354 xmlRelaxNGValidityWarningFunc
warning;
369 xmlRelaxNGValidErrorPtr
err;
372 xmlRelaxNGValidErrorPtr errTab;
374 xmlRelaxNGValidStatePtr
state;
375 xmlRelaxNGStatesPtr states;
377 xmlRelaxNGStatesPtr freeState;
380 xmlRelaxNGStatesPtr *freeStates;
385 xmlRegExecCtxtPtr
elem;
388 xmlRegExecCtxtPtr *elemTab;
391 xmlRelaxNGDefinePtr pdef;
401struct _xmlRelaxNGInclude {
402 xmlRelaxNGIncludePtr
next;
414struct _xmlRelaxNGDocument {
415 xmlRelaxNGDocumentPtr
next;
438xmlRngPErrMemory(xmlRelaxNGParserCtxtPtr ctxt,
const char *
extra)
445 if (ctxt->serror !=
NULL)
446 schannel = ctxt->serror;
448 channel = ctxt->error;
449 data = ctxt->userData;
453 __xmlRaiseError(schannel, channel,
data,
457 "Memory allocation failed : %s\n",
extra);
459 __xmlRaiseError(schannel, channel,
data,
462 NULL,
NULL, 0, 0,
"Memory allocation failed\n");
473xmlRngVErrMemory(xmlRelaxNGValidCtxtPtr ctxt,
const char *
extra)
480 if (ctxt->serror !=
NULL)
481 schannel = ctxt->serror;
483 channel = ctxt->error;
484 data = ctxt->userData;
488 __xmlRaiseError(schannel, channel,
data,
492 "Memory allocation failed : %s\n",
extra);
494 __xmlRaiseError(schannel, channel,
data,
497 NULL,
NULL, 0, 0,
"Memory allocation failed\n");
520 if (ctxt->serror !=
NULL)
521 schannel = ctxt->serror;
523 channel = ctxt->error;
524 data = ctxt->userData;
527 __xmlRaiseError(schannel, channel,
data,
530 (
const char *) str1, (
const char *) str2,
NULL, 0, 0,
554 if (ctxt->serror !=
NULL)
555 schannel = ctxt->serror;
557 channel = ctxt->error;
558 data = ctxt->userData;
561 __xmlRaiseError(schannel, channel,
data,
564 (
const char *) str1, (
const char *) str2,
NULL, 0, 0,
646typedef struct _xmlRelaxNGTypeLibrary xmlRelaxNGTypeLibrary;
647typedef xmlRelaxNGTypeLibrary *xmlRelaxNGTypeLibraryPtr;
648struct _xmlRelaxNGTypeLibrary {
651 xmlRelaxNGTypeHave have;
652 xmlRelaxNGTypeCheck
check;
653 xmlRelaxNGTypeCompare comp;
654 xmlRelaxNGFacetCheck facet;
655 xmlRelaxNGTypeFree freef;
663static void xmlRelaxNGFreeGrammar(xmlRelaxNGGrammarPtr grammar);
664static void xmlRelaxNGFreeDefine(xmlRelaxNGDefinePtr
define);
666static void xmlRelaxNGFreeInnerSchema(xmlRelaxNGPtr
schema);
667static int xmlRelaxNGEqualValidState(xmlRelaxNGValidCtxtPtr ctxt
669 xmlRelaxNGValidStatePtr state1,
670 xmlRelaxNGValidStatePtr state2);
671static void xmlRelaxNGFreeValidState(xmlRelaxNGValidCtxtPtr ctxt,
672 xmlRelaxNGValidStatePtr
state);
681xmlRelaxNGFreeDocument(xmlRelaxNGDocumentPtr docu)
686 if (docu->href !=
NULL)
688 if (docu->doc !=
NULL)
690 if (docu->schema !=
NULL)
691 xmlRelaxNGFreeInnerSchema(docu->schema);
702xmlRelaxNGFreeDocumentList(xmlRelaxNGDocumentPtr docu)
704 xmlRelaxNGDocumentPtr
next;
706 while (docu !=
NULL) {
708 xmlRelaxNGFreeDocument(docu);
720xmlRelaxNGFreeInclude(xmlRelaxNGIncludePtr incl)
725 if (incl->href !=
NULL)
727 if (incl->doc !=
NULL)
729 if (incl->schema !=
NULL)
730 xmlRelaxNGFree(incl->schema);
741xmlRelaxNGFreeIncludeList(xmlRelaxNGIncludePtr incl)
743 xmlRelaxNGIncludePtr
next;
745 while (incl !=
NULL) {
747 xmlRelaxNGFreeInclude(incl);
761xmlRelaxNGNewRelaxNG(xmlRelaxNGParserCtxtPtr ctxt)
767 xmlRngPErrMemory(ctxt,
NULL);
782xmlRelaxNGFreeInnerSchema(xmlRelaxNGPtr
schema)
793 xmlRelaxNGFreeDefine(
schema->defTab[
i]);
807xmlRelaxNGFree(xmlRelaxNGPtr
schema)
813 xmlRelaxNGFreeGrammar(
schema->topgrammar);
817 xmlRelaxNGFreeDocumentList(
schema->documents);
819 xmlRelaxNGFreeIncludeList(
schema->includes);
824 xmlRelaxNGFreeDefine(
schema->defTab[
i]);
839static xmlRelaxNGGrammarPtr
840xmlRelaxNGNewGrammar(xmlRelaxNGParserCtxtPtr ctxt)
842 xmlRelaxNGGrammarPtr
ret;
844 ret = (xmlRelaxNGGrammarPtr)
xmlMalloc(
sizeof(xmlRelaxNGGrammar));
846 xmlRngPErrMemory(ctxt,
NULL);
849 memset(
ret, 0,
sizeof(xmlRelaxNGGrammar));
861xmlRelaxNGFreeGrammar(xmlRelaxNGGrammarPtr grammar)
866 if (grammar->children !=
NULL) {
867 xmlRelaxNGFreeGrammar(grammar->children);
869 if (grammar->next !=
NULL) {
870 xmlRelaxNGFreeGrammar(grammar->next);
872 if (grammar->refs !=
NULL) {
875 if (grammar->defs !=
NULL) {
891static xmlRelaxNGDefinePtr
894 xmlRelaxNGDefinePtr
ret;
896 if (ctxt->defMax == 0) {
899 ctxt->defTab = (xmlRelaxNGDefinePtr *)
900 xmlMalloc(ctxt->defMax *
sizeof(xmlRelaxNGDefinePtr));
901 if (ctxt->defTab ==
NULL) {
902 xmlRngPErrMemory(ctxt,
"allocating define\n");
905 }
else if (ctxt->defMax <= ctxt->defNr) {
906 xmlRelaxNGDefinePtr *tmp;
909 tmp = (xmlRelaxNGDefinePtr *)
xmlRealloc(ctxt->defTab,
912 (xmlRelaxNGDefinePtr));
914 xmlRngPErrMemory(ctxt,
"allocating define\n");
919 ret = (xmlRelaxNGDefinePtr)
xmlMalloc(
sizeof(xmlRelaxNGDefine));
921 xmlRngPErrMemory(ctxt,
"allocating define\n");
924 memset(
ret, 0,
sizeof(xmlRelaxNGDefine));
925 ctxt->defTab[ctxt->defNr++] =
ret;
938xmlRelaxNGFreePartition(xmlRelaxNGPartitionPtr partitions)
940 xmlRelaxNGInterleaveGroupPtr
group;
943 if (partitions !=
NULL) {
944 if (partitions->groups !=
NULL) {
945 for (
j = 0;
j < partitions->nbgroups;
j++) {
946 group = partitions->groups[
j];
957 if (partitions->triage !=
NULL) {
971xmlRelaxNGFreeDefine(xmlRelaxNGDefinePtr
define)
977 xmlRelaxNGTypeLibraryPtr lib;
979 lib = (xmlRelaxNGTypeLibraryPtr)
define->data;
981 lib->freef(lib->data, (
void *)
define->attrs);
984 xmlRelaxNGFreePartition((xmlRelaxNGPartitionPtr)
define->data);
994 xmlRegFreeRegexp(
define->contModel);
1007static xmlRelaxNGStatesPtr
1008xmlRelaxNGNewStates(xmlRelaxNGValidCtxtPtr ctxt,
int size)
1010 xmlRelaxNGStatesPtr
ret;
1012 if ((ctxt !=
NULL) &&
1013 (ctxt->freeStates !=
NULL) && (ctxt->freeStatesNr > 0)) {
1014 ctxt->freeStatesNr--;
1015 ret = ctxt->freeStates[ctxt->freeStatesNr];
1022 ret = (xmlRelaxNGStatesPtr)
xmlMalloc(
sizeof(xmlRelaxNGStates) +
1025 sizeof(xmlRelaxNGValidStatePtr));
1027 xmlRngVErrMemory(ctxt,
"allocating states\n");
1034 (xmlRelaxNGValidStatePtr));
1036 xmlRngVErrMemory(ctxt,
"allocating states\n");
1055xmlRelaxNGAddStatesUniq(xmlRelaxNGValidCtxtPtr ctxt,
1056 xmlRelaxNGStatesPtr states,
1057 xmlRelaxNGValidStatePtr
state)
1062 if (states->nbState >= states->maxState) {
1063 xmlRelaxNGValidStatePtr *tmp;
1066 size = states->maxState * 2;
1067 tmp = (xmlRelaxNGValidStatePtr *)
xmlRealloc(states->tabState,
1070 (xmlRelaxNGValidStatePtr));
1072 xmlRngVErrMemory(ctxt,
"adding states\n");
1075 states->tabState = tmp;
1076 states->maxState =
size;
1078 states->tabState[states->nbState++] =
state;
1093xmlRelaxNGAddStates(xmlRelaxNGValidCtxtPtr ctxt,
1094 xmlRelaxNGStatesPtr states,
1095 xmlRelaxNGValidStatePtr
state)
1102 if (states->nbState >= states->maxState) {
1103 xmlRelaxNGValidStatePtr *tmp;
1106 size = states->maxState * 2;
1107 tmp = (xmlRelaxNGValidStatePtr *)
xmlRealloc(states->tabState,
1110 (xmlRelaxNGValidStatePtr));
1112 xmlRngVErrMemory(ctxt,
"adding states\n");
1115 states->tabState = tmp;
1116 states->maxState =
size;
1118 for (
i = 0;
i < states->nbState;
i++) {
1119 if (xmlRelaxNGEqualValidState(ctxt,
state, states->tabState[
i])) {
1120 xmlRelaxNGFreeValidState(ctxt,
state);
1124 states->tabState[states->nbState++] =
state;
1136xmlRelaxNGFreeStates(xmlRelaxNGValidCtxtPtr ctxt,
1137 xmlRelaxNGStatesPtr states)
1141 if ((ctxt !=
NULL) && (ctxt->freeStates ==
NULL)) {
1142 ctxt->freeStatesMax = 40;
1143 ctxt->freeStatesNr = 0;
1144 ctxt->freeStates = (xmlRelaxNGStatesPtr *)
1145 xmlMalloc(ctxt->freeStatesMax *
sizeof(xmlRelaxNGStatesPtr));
1146 if (ctxt->freeStates ==
NULL) {
1147 xmlRngVErrMemory(ctxt,
"storing states\n");
1149 }
else if ((ctxt !=
NULL)
1150 && (ctxt->freeStatesNr >= ctxt->freeStatesMax)) {
1151 xmlRelaxNGStatesPtr *tmp;
1153 tmp = (xmlRelaxNGStatesPtr *)
xmlRealloc(ctxt->freeStates,
1154 2 * ctxt->freeStatesMax *
1156 (xmlRelaxNGStatesPtr));
1158 xmlRngVErrMemory(ctxt,
"storing states\n");
1163 ctxt->freeStates = tmp;
1164 ctxt->freeStatesMax *= 2;
1166 if ((ctxt ==
NULL) || (ctxt->freeStates ==
NULL)) {
1170 ctxt->freeStates[ctxt->freeStatesNr++] = states;
1183static xmlRelaxNGValidStatePtr
1184xmlRelaxNGNewValidState(xmlRelaxNGValidCtxtPtr ctxt,
xmlNodePtr node)
1186 xmlRelaxNGValidStatePtr
ret;
1199 if (nbAttrs < MAX_ATTR)
1200 attrs[nbAttrs++] =
attr;
1206 if ((ctxt->freeState !=
NULL) && (ctxt->freeState->nbState > 0)) {
1207 ctxt->freeState->nbState--;
1208 ret = ctxt->freeState->tabState[ctxt->freeState->nbState];
1211 (xmlRelaxNGValidStatePtr)
1212 xmlMalloc(
sizeof(xmlRelaxNGValidState));
1214 xmlRngVErrMemory(ctxt,
"allocating states\n");
1217 memset(
ret, 0,
sizeof(xmlRelaxNGValidState));
1234 ret->maxAttrs = nbAttrs;
1238 xmlRngVErrMemory(ctxt,
"allocating states\n");
1241 }
else if (
ret->maxAttrs < nbAttrs) {
1247 xmlRngVErrMemory(ctxt,
"allocating states\n");
1251 ret->maxAttrs = nbAttrs;
1253 ret->nbAttrs = nbAttrs;
1254 if (nbAttrs < MAX_ATTR) {
1265 ret->nbAttrLeft =
ret->nbAttrs;
1278static xmlRelaxNGValidStatePtr
1279xmlRelaxNGCopyValidState(xmlRelaxNGValidCtxtPtr ctxt,
1280 xmlRelaxNGValidStatePtr
state)
1282 xmlRelaxNGValidStatePtr
ret;
1283 unsigned int maxAttrs;
1288 if ((ctxt->freeState !=
NULL) && (ctxt->freeState->nbState > 0)) {
1289 ctxt->freeState->nbState--;
1290 ret = ctxt->freeState->tabState[ctxt->freeState->nbState];
1293 (xmlRelaxNGValidStatePtr)
1294 xmlMalloc(
sizeof(xmlRelaxNGValidState));
1296 xmlRngVErrMemory(ctxt,
"allocating states\n");
1299 memset(
ret, 0,
sizeof(xmlRelaxNGValidState));
1302 maxAttrs =
ret->maxAttrs;
1305 ret->maxAttrs = maxAttrs;
1306 if (
state->nbAttrs > 0) {
1312 xmlRngVErrMemory(ctxt,
"allocating states\n");
1316 }
else if (
ret->maxAttrs <
state->nbAttrs) {
1322 xmlRngVErrMemory(ctxt,
"allocating states\n");
1347 xmlRelaxNGValidStatePtr state1,
1348 xmlRelaxNGValidStatePtr state2)
1352 if ((state1 ==
NULL) || (state2 ==
NULL))
1354 if (state1 == state2)
1356 if (state1->node != state2->node)
1358 if (state1->seq != state2->seq)
1360 if (state1->nbAttrLeft != state2->nbAttrLeft)
1362 if (state1->nbAttrs != state2->nbAttrs)
1364 if (state1->endvalue != state2->endvalue)
1366 if ((state1->value != state2->value) &&
1369 for (
i = 0;
i < state1->nbAttrs;
i++) {
1370 if (state1->attrs[
i] != state2->attrs[
i])
1383xmlRelaxNGFreeValidState(xmlRelaxNGValidCtxtPtr ctxt,
1384 xmlRelaxNGValidStatePtr
state)
1389 if ((ctxt !=
NULL) && (ctxt->freeState ==
NULL)) {
1390 ctxt->freeState = xmlRelaxNGNewStates(ctxt, 40);
1392 if ((ctxt ==
NULL) || (ctxt->freeState ==
NULL)) {
1397 xmlRelaxNGAddStatesUniq(ctxt, ctxt->freeState,
state);
1418xmlRelaxParserSetFlag(xmlRelaxNGParserCtxtPtr ctxt,
int flags)
1420 if (ctxt ==
NULL)
return(-1);
1421 if (
flags & XML_RELAXNGP_FREE_DOC) {
1422 ctxt->crng |= XML_RELAXNGP_FREE_DOC;
1423 flags -= XML_RELAXNGP_FREE_DOC;
1425 if (
flags & XML_RELAXNGP_CRNG) {
1426 ctxt->crng |= XML_RELAXNGP_CRNG;
1427 flags -= XML_RELAXNGP_CRNG;
1429 if (
flags != 0)
return(-1);
1438static xmlDocPtr xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt,
1451xmlRelaxNGIncludePush(xmlRelaxNGParserCtxtPtr ctxt,
1452 xmlRelaxNGIncludePtr
value)
1454 if (ctxt->incTab ==
NULL) {
1458 (xmlRelaxNGIncludePtr *)
xmlMalloc(ctxt->incMax *
1459 sizeof(ctxt->incTab[0]));
1460 if (ctxt->incTab ==
NULL) {
1461 xmlRngPErrMemory(ctxt,
"allocating include\n");
1465 if (ctxt->incNr >= ctxt->incMax) {
1468 (xmlRelaxNGIncludePtr *)
xmlRealloc(ctxt->incTab,
1470 sizeof(ctxt->incTab[0]));
1471 if (ctxt->incTab ==
NULL) {
1472 xmlRngPErrMemory(ctxt,
"allocating include\n");
1476 ctxt->incTab[ctxt->incNr] =
value;
1478 return (ctxt->incNr++);
1489static xmlRelaxNGIncludePtr
1490xmlRelaxNGIncludePop(xmlRelaxNGParserCtxtPtr ctxt)
1492 xmlRelaxNGIncludePtr
ret;
1494 if (ctxt->incNr <= 0)
1497 if (ctxt->incNr > 0)
1498 ctxt->inc = ctxt->incTab[ctxt->incNr - 1];
1501 ret = ctxt->incTab[ctxt->incNr];
1502 ctxt->incTab[ctxt->incNr] =
NULL;
1518xmlRelaxNGRemoveRedefine(xmlRelaxNGParserCtxtPtr ctxt,
1529 "Elimination of <include> start from %s\n", URL);
1532 "Elimination of <include> define %s from %s\n",
1536 while (tmp !=
NULL) {
1538 if ((
name ==
NULL) && (IS_RELAXNG(tmp,
"start"))) {
1542 }
else if ((
name !=
NULL) && (IS_RELAXNG(tmp,
"define"))) {
1544 xmlRelaxNGNormExtSpace(
name2);
1553 }
else if (IS_RELAXNG(tmp,
"include")) {
1555 xmlRelaxNGDocumentPtr inc = tmp->
psvi;
1557 if ((inc !=
NULL) && (inc->doc !=
NULL) &&
1558 (inc->doc->children !=
NULL)) {
1561 (inc->doc->children->name,
BAD_CAST "grammar")) {
1565 if (xmlRelaxNGRemoveRedefine(ctxt, href,
1576 if (xmlRelaxNGRemoveRedefine(ctxt, URL, tmp->
children,
name) == 1) {
1598static xmlRelaxNGIncludePtr
1599xmlRelaxNGLoadInclude(xmlRelaxNGParserCtxtPtr ctxt,
const xmlChar * URL,
1602 xmlRelaxNGIncludePtr
ret =
NULL;
1609 "xmlRelaxNGLoadInclude(%s)\n", URL);
1615 for (
i = 0;
i < ctxt->incNr;
i++) {
1618 "Detected an Include recursion for %s\n", URL,
1630 "xmlRelaxNG: could not load %s\n", URL,
NULL);
1640 ret = (xmlRelaxNGIncludePtr)
xmlMalloc(
sizeof(xmlRelaxNGInclude));
1642 xmlRngPErrMemory(ctxt,
"allocating include\n");
1646 memset(
ret, 0,
sizeof(xmlRelaxNGInclude));
1649 ret->next = ctxt->includes;
1650 ctxt->includes =
ret;
1667 xmlRelaxNGIncludePush(ctxt,
ret);
1677 doc = xmlRelaxNGCleanupDoc(ctxt, doc);
1686 xmlRelaxNGIncludePop(ctxt);
1697 "xmlRelaxNG: included document is empty %s\n", URL,
1701 if (!IS_RELAXNG(
root,
"grammar")) {
1703 "xmlRelaxNG: included document %s root is not a grammar\n",
1713 if (IS_RELAXNG(
cur,
"start")) {
1717 xmlRelaxNGRemoveRedefine(ctxt, URL,
root->children,
NULL);
1720 "xmlRelaxNG: include %s has a start but not the included grammar\n",
1723 }
else if (IS_RELAXNG(
cur,
"define")) {
1729 "xmlRelaxNG: include %s has define without name\n",
1734 xmlRelaxNGNormExtSpace(
name);
1735 found = xmlRelaxNGRemoveRedefine(ctxt, URL,
1739 "xmlRelaxNG: include %s has a define %s but not the included grammar\n",
1745 if (IS_RELAXNG(
cur,
"div") &&
cur->children !=
NULL) {
1776xmlRelaxNGValidErrorPush(xmlRelaxNGValidCtxtPtr ctxt,
1780 xmlRelaxNGValidErrorPtr
cur;
1784 "Pushing error %d at %d on stack\n",
err, ctxt->errNr);
1786 if (ctxt->errTab ==
NULL) {
1790 (xmlRelaxNGValidErrorPtr)
xmlMalloc(ctxt->errMax *
1792 (xmlRelaxNGValidError));
1793 if (ctxt->errTab ==
NULL) {
1794 xmlRngVErrMemory(ctxt,
"pushing error\n");
1799 if (ctxt->errNr >= ctxt->errMax) {
1802 (xmlRelaxNGValidErrorPtr)
xmlRealloc(ctxt->errTab,
1805 (xmlRelaxNGValidError));
1806 if (ctxt->errTab ==
NULL) {
1807 xmlRngVErrMemory(ctxt,
"pushing error\n");
1810 ctxt->err = &ctxt->errTab[ctxt->errNr - 1];
1812 if ((ctxt->err !=
NULL) && (ctxt->state !=
NULL) &&
1813 (ctxt->err->node == ctxt->state->node) && (ctxt->err->err ==
err))
1814 return (ctxt->errNr);
1815 cur = &ctxt->errTab[ctxt->errNr];
1820 cur->flags = ERROR_IS_DUP;
1826 if (ctxt->state !=
NULL) {
1827 cur->node = ctxt->state->node;
1828 cur->seq = ctxt->state->seq;
1834 return (ctxt->errNr++);
1844xmlRelaxNGValidErrorPop(xmlRelaxNGValidCtxtPtr ctxt)
1846 xmlRelaxNGValidErrorPtr
cur;
1848 if (ctxt->errNr <= 0) {
1853 if (ctxt->errNr > 0)
1854 ctxt->err = &ctxt->errTab[ctxt->errNr - 1];
1857 cur = &ctxt->errTab[ctxt->errNr];
1858 if (
cur->flags & ERROR_IS_DUP) {
1879xmlRelaxNGDocumentPush(xmlRelaxNGParserCtxtPtr ctxt,
1880 xmlRelaxNGDocumentPtr
value)
1882 if (ctxt->docTab ==
NULL) {
1886 (xmlRelaxNGDocumentPtr *)
xmlMalloc(ctxt->docMax *
1887 sizeof(ctxt->docTab[0]));
1888 if (ctxt->docTab ==
NULL) {
1889 xmlRngPErrMemory(ctxt,
"adding document\n");
1893 if (ctxt->docNr >= ctxt->docMax) {
1896 (xmlRelaxNGDocumentPtr *)
xmlRealloc(ctxt->docTab,
1898 sizeof(ctxt->docTab[0]));
1899 if (ctxt->docTab ==
NULL) {
1900 xmlRngPErrMemory(ctxt,
"adding document\n");
1904 ctxt->docTab[ctxt->docNr] =
value;
1906 return (ctxt->docNr++);
1917static xmlRelaxNGDocumentPtr
1918xmlRelaxNGDocumentPop(xmlRelaxNGParserCtxtPtr ctxt)
1920 xmlRelaxNGDocumentPtr
ret;
1922 if (ctxt->docNr <= 0)
1925 if (ctxt->docNr > 0)
1926 ctxt->doc = ctxt->docTab[ctxt->docNr - 1];
1929 ret = ctxt->docTab[ctxt->docNr];
1930 ctxt->docTab[ctxt->docNr] =
NULL;
1946static xmlRelaxNGDocumentPtr
1947xmlRelaxNGLoadExternalRef(xmlRelaxNGParserCtxtPtr ctxt,
1950 xmlRelaxNGDocumentPtr
ret =
NULL;
1958 for (
i = 0;
i < ctxt->docNr;
i++) {
1961 "Detected an externalRef recursion for %s\n", URL,
1973 "xmlRelaxNG: could not load %s\n", URL,
NULL);
1980 ret = (xmlRelaxNGDocumentPtr)
xmlMalloc(
sizeof(xmlRelaxNGDocument));
1983 "xmlRelaxNG: allocate memory for doc %s\n", URL,
NULL);
1987 memset(
ret, 0,
sizeof(xmlRelaxNGDocument));
1990 ret->next = ctxt->documents;
1991 ret->externalRef = 1;
1992 ctxt->documents =
ret;
2009 xmlRelaxNGDocumentPush(ctxt,
ret);
2014 doc = xmlRelaxNGCleanupDoc(ctxt, doc);
2020 xmlRelaxNGDocumentPop(ctxt);
2031#define VALID_ERR(a) xmlRelaxNGAddValidError(ctxt, a, NULL, NULL, 0);
2032#define VALID_ERR2(a, b) xmlRelaxNGAddValidError(ctxt, a, b, NULL, 0);
2033#define VALID_ERR3(a, b, c) xmlRelaxNGAddValidError(ctxt, a, b, c, 0);
2034#define VALID_ERR2P(a, b) xmlRelaxNGAddValidError(ctxt, a, b, NULL, 1);
2035#define VALID_ERR3P(a, b, c) xmlRelaxNGAddValidError(ctxt, a, b, c, 1);
2038xmlRelaxNGDefName(xmlRelaxNGDefinePtr def)
2042 switch (def->type) {
2043 case XML_RELAXNG_EMPTY:
2045 case XML_RELAXNG_NOT_ALLOWED:
2046 return (
"notAllowed");
2047 case XML_RELAXNG_EXCEPT:
2049 case XML_RELAXNG_TEXT:
2051 case XML_RELAXNG_ELEMENT:
2053 case XML_RELAXNG_DATATYPE:
2054 return (
"datatype");
2055 case XML_RELAXNG_VALUE:
2057 case XML_RELAXNG_LIST:
2059 case XML_RELAXNG_ATTRIBUTE:
2060 return (
"attribute");
2061 case XML_RELAXNG_DEF:
2063 case XML_RELAXNG_REF:
2065 case XML_RELAXNG_EXTERNALREF:
2066 return (
"externalRef");
2067 case XML_RELAXNG_PARENTREF:
2068 return (
"parentRef");
2069 case XML_RELAXNG_OPTIONAL:
2070 return (
"optional");
2071 case XML_RELAXNG_ZEROORMORE:
2072 return (
"zeroOrMore");
2073 case XML_RELAXNG_ONEORMORE:
2074 return (
"oneOrMore");
2075 case XML_RELAXNG_CHOICE:
2077 case XML_RELAXNG_GROUP:
2079 case XML_RELAXNG_INTERLEAVE:
2080 return (
"interleave");
2081 case XML_RELAXNG_START:
2083 case XML_RELAXNG_NOOP:
2085 case XML_RELAXNG_PARAM:
2102xmlRelaxNGGetErrorString(xmlRelaxNGValidErr
err,
const xmlChar *
arg1,
2115 case XML_RELAXNG_OK:
2117 case XML_RELAXNG_ERR_MEMORY:
2119 case XML_RELAXNG_ERR_TYPE:
2122 case XML_RELAXNG_ERR_TYPEVAL:
2126 case XML_RELAXNG_ERR_DUPID:
2129 case XML_RELAXNG_ERR_TYPECMP:
2132 case XML_RELAXNG_ERR_NOSTATE:
2134 case XML_RELAXNG_ERR_NODEFINE:
2136 case XML_RELAXNG_ERR_INTERNAL:
2139 case XML_RELAXNG_ERR_LISTEXTRA:
2142 case XML_RELAXNG_ERR_INTERNODATA:
2144 (
"Internal: interleave block has no data\n"));
2145 case XML_RELAXNG_ERR_INTERSEQ:
2147 case XML_RELAXNG_ERR_INTEREXTRA:
2150 case XML_RELAXNG_ERR_ELEMNAME:
2154 case XML_RELAXNG_ERR_ELEMNONS:
2155 snprintf(
msg, 1000,
"Expecting a namespace for element %s\n",
2158 case XML_RELAXNG_ERR_ELEMWRONGNS:
2160 "Element %s has wrong namespace: expecting %s\n",
arg1,
2163 case XML_RELAXNG_ERR_ELEMWRONG:
2166 case XML_RELAXNG_ERR_TEXTWRONG:
2168 "Did not expect text in element %s content\n",
arg1);
2170 case XML_RELAXNG_ERR_ELEMEXTRANS:
2171 snprintf(
msg, 1000,
"Expecting no namespace for element %s\n",
2174 case XML_RELAXNG_ERR_ELEMNOTEMPTY:
2177 case XML_RELAXNG_ERR_NOELEM:
2178 snprintf(
msg, 1000,
"Expecting an element %s, got nothing\n",
2181 case XML_RELAXNG_ERR_NOTELEM:
2183 case XML_RELAXNG_ERR_ATTRVALID:
2184 snprintf(
msg, 1000,
"Element %s failed to validate attributes\n",
2187 case XML_RELAXNG_ERR_CONTENTVALID:
2188 snprintf(
msg, 1000,
"Element %s failed to validate content\n",
2191 case XML_RELAXNG_ERR_EXTRACONTENT:
2192 snprintf(
msg, 1000,
"Element %s has extra content: %s\n",
2195 case XML_RELAXNG_ERR_INVALIDATTR:
2196 snprintf(
msg, 1000,
"Invalid attribute %s for element %s\n",
2199 case XML_RELAXNG_ERR_LACKDATA:
2200 snprintf(
msg, 1000,
"Datatype element %s contains no data\n",
2203 case XML_RELAXNG_ERR_DATAELEM:
2204 snprintf(
msg, 1000,
"Datatype element %s has child elements\n",
2207 case XML_RELAXNG_ERR_VALELEM:
2208 snprintf(
msg, 1000,
"Value element %s has child elements\n",
2211 case XML_RELAXNG_ERR_LISTELEM:
2212 snprintf(
msg, 1000,
"List element %s has child elements\n",
2215 case XML_RELAXNG_ERR_DATATYPE:
2218 case XML_RELAXNG_ERR_VALUE:
2221 case XML_RELAXNG_ERR_LIST:
2223 case XML_RELAXNG_ERR_NOGRAMMAR:
2225 case XML_RELAXNG_ERR_EXTRADATA:
2250xmlRelaxNGShowValidError(xmlRelaxNGValidCtxtPtr ctxt,
2257 if (ctxt->flags & FLAGS_NOERROR)
2267 if (ctxt->errNo == XML_RELAXNG_OK)
2282xmlRelaxNGPopErrors(xmlRelaxNGValidCtxtPtr ctxt,
int level)
2285 xmlRelaxNGValidErrorPtr
err;
2289 "Pop errors till level %d\n",
level);
2291 for (
i =
level;
i < ctxt->errNr;
i++) {
2292 err = &ctxt->errTab[
i];
2293 if (
err->flags & ERROR_IS_DUP) {
2303 ctxt->errNr =
level;
2304 if (ctxt->errNr <= 0)
2315xmlRelaxNGDumpValidError(xmlRelaxNGValidCtxtPtr ctxt)
2318 xmlRelaxNGValidErrorPtr
err,
dup;
2322 "Dumping error stack %d errors\n", ctxt->errNr);
2324 for (
i = 0,
k = 0;
i < ctxt->errNr;
i++) {
2325 err = &ctxt->errTab[
i];
2326 if (
k < MAX_ERROR) {
2327 for (
j = 0;
j <
i;
j++) {
2328 dup = &ctxt->errTab[
j];
2329 if ((
err->err ==
dup->err) && (
err->node ==
dup->node) &&
2335 xmlRelaxNGShowValidError(ctxt,
err->err,
err->node,
err->seq,
2340 if (
err->flags & ERROR_IS_DUP) {
2365xmlRelaxNGAddValidError(xmlRelaxNGValidCtxtPtr ctxt,
2371 if (ctxt->flags & FLAGS_NOERROR)
2380 if (((ctxt->flags & FLAGS_IGNORABLE) == 0) ||
2381 (ctxt->flags & FLAGS_NEGATIVE)) {
2388 if (ctxt->errNr != 0)
2389 xmlRelaxNGDumpValidError(ctxt);
2390 if (ctxt->state !=
NULL) {
2391 node = ctxt->state->node;
2392 seq = ctxt->state->seq;
2415static xmlChar *xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt,
2431 xmlSchemaTypePtr typ;
2435 typ = xmlSchemaGetPredefinedType(
type,
2437 "http://www.w3.org/2001/XMLSchema");
2461 xmlSchemaTypePtr typ;
2466 typ = xmlSchemaGetPredefinedType(
type,
2468 "http://www.w3.org/2001/XMLSchema");
2471 ret = xmlSchemaValPredefTypeNode(typ,
value,
2501 xmlSchemaFacetPtr facet;
2502 xmlSchemaTypePtr typ;
2507 typ = xmlSchemaGetPredefinedType(
type,
2509 "http://www.w3.org/2001/XMLSchema");
2513 facet = xmlSchemaNewFacet();
2518 facet->type = XML_SCHEMA_FACET_MININCLUSIVE;
2520 facet->type = XML_SCHEMA_FACET_MINEXCLUSIVE;
2522 facet->type = XML_SCHEMA_FACET_MAXINCLUSIVE;
2524 facet->type = XML_SCHEMA_FACET_MAXEXCLUSIVE;
2526 facet->type = XML_SCHEMA_FACET_TOTALDIGITS;
2528 facet->type = XML_SCHEMA_FACET_FRACTIONDIGITS;
2530 facet->type = XML_SCHEMA_FACET_PATTERN;
2532 facet->type = XML_SCHEMA_FACET_ENUMERATION;
2534 facet->type = XML_SCHEMA_FACET_WHITESPACE;
2536 facet->type = XML_SCHEMA_FACET_LENGTH;
2538 facet->type = XML_SCHEMA_FACET_MAXLENGTH;
2540 facet->type = XML_SCHEMA_FACET_MINLENGTH;
2542 xmlSchemaFreeFacet(facet);
2546 ret = xmlSchemaCheckFacet(facet, typ,
NULL,
type);
2548 xmlSchemaFreeFacet(facet);
2552 xmlSchemaFreeFacet(facet);
2570 xmlSchemaFreeValue(
value);
2594 xmlSchemaTypePtr typ;
2595 xmlSchemaValPtr res1 =
NULL, res2 =
NULL;
2599 typ = xmlSchemaGetPredefinedType(
type,
2601 "http://www.w3.org/2001/XMLSchema");
2604 if (comp1 ==
NULL) {
2605 ret = xmlSchemaValPredefTypeNode(typ, value1, &res1, ctxt1);
2611 res1 = (xmlSchemaValPtr) comp1;
2613 ret = xmlSchemaValPredefTypeNode(typ, value2, &res2, ctxt2);
2615 if (res1 != (xmlSchemaValPtr) comp1)
2616 xmlSchemaFreeValue(res1);
2619 ret = xmlSchemaCompareValues(res1, res2);
2620 if (res1 != (xmlSchemaValPtr) comp1)
2621 xmlSchemaFreeValue(res1);
2622 xmlSchemaFreeValue(res2);
2716 nval = xmlRelaxNGNormalize(
NULL, value1);
2717 nvalue = xmlRelaxNGNormalize(
NULL, value2);
2719 if ((nval ==
NULL) || (nvalue ==
NULL))
2735static int xmlRelaxNGTypeInitialized = 0;
2746xmlRelaxNGFreeTypeLibrary(
void *payload,
2749 xmlRelaxNGTypeLibraryPtr lib = (xmlRelaxNGTypeLibraryPtr) payload;
2752 if (lib->namespace !=
NULL)
2770xmlRelaxNGRegisterTypeLibrary(
const xmlChar *
namespace,
void *
data,
2771 xmlRelaxNGTypeHave have,
2772 xmlRelaxNGTypeCheck
check,
2773 xmlRelaxNGTypeCompare comp,
2774 xmlRelaxNGFacetCheck facet,
2775 xmlRelaxNGTypeFree freef)
2777 xmlRelaxNGTypeLibraryPtr lib;
2780 if ((xmlRelaxNGRegisteredTypes ==
NULL) || (
namespace ==
NULL) ||
2785 "Relax-NG types library '%s' already registered\n",
2790 (xmlRelaxNGTypeLibraryPtr)
2791 xmlMalloc(
sizeof(xmlRelaxNGTypeLibrary));
2793 xmlRngVErrMemory(
NULL,
"adding types library\n");
2796 memset(lib, 0,
sizeof(xmlRelaxNGTypeLibrary));
2807 "Relax-NG types library failed to register '%s'\n",
2809 xmlRelaxNGFreeTypeLibrary(lib,
namespace);
2823xmlRelaxNGInitTypes(
void)
2825 if (xmlRelaxNGTypeInitialized != 0)
2828 if (xmlRelaxNGRegisteredTypes ==
NULL) {
2830 "Failed to allocate sh table for Relax-NG types\n");
2833 xmlRelaxNGRegisterTypeLibrary(
BAD_CAST
2834 "http://www.w3.org/2001/XMLSchema-datatypes",
2835 NULL, xmlRelaxNGSchemaTypeHave,
2836 xmlRelaxNGSchemaTypeCheck,
2837 xmlRelaxNGSchemaTypeCompare,
2838 xmlRelaxNGSchemaFacetCheck,
2839 xmlRelaxNGSchemaFreeValue);
2840 xmlRelaxNGRegisterTypeLibrary(xmlRelaxNGNs,
NULL,
2841 xmlRelaxNGDefaultTypeHave,
2842 xmlRelaxNGDefaultTypeCheck,
2843 xmlRelaxNGDefaultTypeCompare,
NULL,
2845 xmlRelaxNGTypeInitialized = 1;
2860xmlRelaxNGCleanupTypes(
void)
2862 xmlSchemaCleanupTypes();
2863 if (xmlRelaxNGTypeInitialized == 0)
2865 xmlHashFree(xmlRelaxNGRegisteredTypes, xmlRelaxNGFreeTypeLibrary);
2866 xmlRelaxNGTypeInitialized = 0;
2879void xmlAutomataSetFlags(xmlAutomataPtr am,
int flags);
2882static int xmlRelaxNGTryCompile(xmlRelaxNGParserCtxtPtr ctxt,
2883 xmlRelaxNGDefinePtr def);
2894xmlRelaxNGIsCompilable(xmlRelaxNGDefinePtr def)
2901 if ((def->type != XML_RELAXNG_ELEMENT) &&
2902 (def->dflags & IS_COMPILABLE))
2904 if ((def->type != XML_RELAXNG_ELEMENT) &&
2905 (def->dflags & IS_NOT_COMPILABLE))
2907 switch (def->type) {
2908 case XML_RELAXNG_NOOP:
2909 ret = xmlRelaxNGIsCompilable(def->content);
2911 case XML_RELAXNG_TEXT:
2912 case XML_RELAXNG_EMPTY:
2915 case XML_RELAXNG_ELEMENT:
2919 if (((def->dflags & IS_NOT_COMPILABLE) == 0) &&
2920 ((def->dflags & IS_COMPILABLE) == 0)) {
2921 xmlRelaxNGDefinePtr
list;
2923 list = def->content;
2925 ret = xmlRelaxNGIsCompilable(
list);
2935 def->dflags &= ~IS_COMPILABLE;
2936 def->dflags |= IS_NOT_COMPILABLE;
2938 if ((
ret == 1) && !(def->dflags &= IS_NOT_COMPILABLE))
2939 def->dflags |= IS_COMPILABLE;
2943 "element content for %s is compilable\n",
2945 }
else if (
ret == 0) {
2947 "element content for %s is not compilable\n",
2951 "Problem in RelaxNGIsCompilable for element %s\n",
2960 if ((def->nameClass !=
NULL) || (def->name ==
NULL))
2965 case XML_RELAXNG_REF:
2966 case XML_RELAXNG_EXTERNALREF:
2967 case XML_RELAXNG_PARENTREF:
2968 if (def->depth == -20) {
2971 xmlRelaxNGDefinePtr
list;
2974 list = def->content;
2976 ret = xmlRelaxNGIsCompilable(
list);
2983 case XML_RELAXNG_START:
2984 case XML_RELAXNG_OPTIONAL:
2985 case XML_RELAXNG_ZEROORMORE:
2986 case XML_RELAXNG_ONEORMORE:
2987 case XML_RELAXNG_CHOICE:
2988 case XML_RELAXNG_GROUP:
2989 case XML_RELAXNG_DEF:{
2990 xmlRelaxNGDefinePtr
list;
2992 list = def->content;
2994 ret = xmlRelaxNGIsCompilable(
list);
3001 case XML_RELAXNG_EXCEPT:
3002 case XML_RELAXNG_ATTRIBUTE:
3003 case XML_RELAXNG_INTERLEAVE:
3004 case XML_RELAXNG_DATATYPE:
3005 case XML_RELAXNG_LIST:
3006 case XML_RELAXNG_PARAM:
3007 case XML_RELAXNG_VALUE:
3008 case XML_RELAXNG_NOT_ALLOWED:
3013 def->dflags |= IS_NOT_COMPILABLE;
3015 def->dflags |= IS_COMPILABLE;
3019 "RelaxNGIsCompilable %s : true\n",
3020 xmlRelaxNGDefName(def));
3021 }
else if (
ret == 0) {
3023 "RelaxNGIsCompilable %s : false\n",
3024 xmlRelaxNGDefName(def));
3027 "Problem in RelaxNGIsCompilable %s\n",
3028 xmlRelaxNGDefName(def));
3045xmlRelaxNGCompile(xmlRelaxNGParserCtxtPtr ctxt, xmlRelaxNGDefinePtr def)
3048 xmlRelaxNGDefinePtr
list;
3050 if ((ctxt ==
NULL) || (def ==
NULL))
3053 switch (def->type) {
3054 case XML_RELAXNG_START:
3055 if ((xmlRelaxNGIsCompilable(def) == 1) && (def->depth != -25)) {
3056 xmlAutomataPtr oldam = ctxt->am;
3057 xmlAutomataStatePtr oldstate = ctxt->state;
3061 list = def->content;
3062 ctxt->am = xmlNewAutomata();
3063 if (ctxt->am ==
NULL)
3074 xmlAutomataSetFlags(ctxt->am, 1);
3076 ctxt->state = xmlAutomataGetInitState(ctxt->am);
3078 xmlRelaxNGCompile(ctxt,
list);
3081 xmlAutomataSetFinalState(ctxt->am, ctxt->state);
3082 if (xmlAutomataIsDeterminist(ctxt->am))
3083 def->contModel = xmlAutomataCompile(ctxt->am);
3085 xmlFreeAutomata(ctxt->am);
3086 ctxt->state = oldstate;
3090 case XML_RELAXNG_ELEMENT:
3091 if ((ctxt->am !=
NULL) && (def->name !=
NULL)) {
3092 ctxt->state = xmlAutomataNewTransition2(ctxt->am,
3097 if ((def->dflags & IS_COMPILABLE) && (def->depth != -25)) {
3098 xmlAutomataPtr oldam = ctxt->am;
3099 xmlAutomataStatePtr oldstate = ctxt->state;
3103 list = def->content;
3104 ctxt->am = xmlNewAutomata();
3105 if (ctxt->am ==
NULL)
3107 xmlAutomataSetFlags(ctxt->am, 1);
3108 ctxt->state = xmlAutomataGetInitState(ctxt->am);
3110 xmlRelaxNGCompile(ctxt,
list);
3113 xmlAutomataSetFinalState(ctxt->am, ctxt->state);
3114 def->contModel = xmlAutomataCompile(ctxt->am);
3115 if (!xmlRegexpIsDeterminist(def->contModel)) {
3118 "Content model not determinist %s\n",
3124 xmlRegFreeRegexp(def->contModel);
3125 def->contModel =
NULL;
3127 xmlFreeAutomata(ctxt->am);
3128 ctxt->state = oldstate;
3131 xmlAutomataPtr oldam = ctxt->am;
3138 ret = xmlRelaxNGTryCompile(ctxt, def);
3142 case XML_RELAXNG_NOOP:
3143 ret = xmlRelaxNGCompile(ctxt, def->content);
3145 case XML_RELAXNG_OPTIONAL:{
3146 xmlAutomataStatePtr oldstate = ctxt->state;
3148 list = def->content;
3150 xmlRelaxNGCompile(ctxt,
list);
3153 xmlAutomataNewEpsilon(ctxt->am, oldstate, ctxt->state);
3156 case XML_RELAXNG_ZEROORMORE:{
3157 xmlAutomataStatePtr oldstate;
3160 xmlAutomataNewEpsilon(ctxt->am, ctxt->state,
NULL);
3161 oldstate = ctxt->state;
3162 list = def->content;
3164 xmlRelaxNGCompile(ctxt,
list);
3167 xmlAutomataNewEpsilon(ctxt->am, ctxt->state, oldstate);
3169 xmlAutomataNewEpsilon(ctxt->am, oldstate,
NULL);
3172 case XML_RELAXNG_ONEORMORE:{
3173 xmlAutomataStatePtr oldstate;
3175 list = def->content;
3177 xmlRelaxNGCompile(ctxt,
list);
3180 oldstate = ctxt->state;
3181 list = def->content;
3183 xmlRelaxNGCompile(ctxt,
list);
3186 xmlAutomataNewEpsilon(ctxt->am, ctxt->state, oldstate);
3188 xmlAutomataNewEpsilon(ctxt->am, oldstate,
NULL);
3191 case XML_RELAXNG_CHOICE:{
3193 xmlAutomataStatePtr oldstate = ctxt->state;
3195 list = def->content;
3197 ctxt->state = oldstate;
3198 ret = xmlRelaxNGCompile(ctxt,
list);
3204 xmlAutomataNewEpsilon(ctxt->am, ctxt->state,
3213 case XML_RELAXNG_REF:
3214 case XML_RELAXNG_EXTERNALREF:
3215 case XML_RELAXNG_PARENTREF:
3216 case XML_RELAXNG_GROUP:
3217 case XML_RELAXNG_DEF:
3218 list = def->content;
3220 ret = xmlRelaxNGCompile(ctxt,
list);
3226 case XML_RELAXNG_TEXT:{
3227 xmlAutomataStatePtr oldstate;
3230 xmlAutomataNewEpsilon(ctxt->am, ctxt->state,
NULL);
3231 oldstate = ctxt->state;
3232 xmlRelaxNGCompile(ctxt, def->content);
3233 xmlAutomataNewTransition(ctxt->am, ctxt->state,
3237 xmlAutomataNewEpsilon(ctxt->am, oldstate,
NULL);
3240 case XML_RELAXNG_EMPTY:
3242 xmlAutomataNewEpsilon(ctxt->am, ctxt->state,
NULL);
3244 case XML_RELAXNG_EXCEPT:
3245 case XML_RELAXNG_ATTRIBUTE:
3246 case XML_RELAXNG_INTERLEAVE:
3247 case XML_RELAXNG_NOT_ALLOWED:
3248 case XML_RELAXNG_DATATYPE:
3249 case XML_RELAXNG_LIST:
3250 case XML_RELAXNG_PARAM:
3251 case XML_RELAXNG_VALUE:
3253 fprintf(
stderr,
"RNG internal error trying to compile %s\n",
3254 xmlRelaxNGDefName(def));
3271xmlRelaxNGTryCompile(xmlRelaxNGParserCtxtPtr ctxt, xmlRelaxNGDefinePtr def)
3274 xmlRelaxNGDefinePtr
list;
3276 if ((ctxt ==
NULL) || (def ==
NULL))
3279 if ((def->type == XML_RELAXNG_START) ||
3280 (def->type == XML_RELAXNG_ELEMENT)) {
3281 ret = xmlRelaxNGIsCompilable(def);
3282 if ((def->dflags & IS_COMPILABLE) && (def->depth != -25)) {
3284 ret = xmlRelaxNGCompile(ctxt, def);
3285#ifdef DEBUG_PROGRESSIVE
3287 if (def->type == XML_RELAXNG_START)
3289 "compiled the start\n");
3292 "compiled element %s\n", def->name);
3294 if (def->type == XML_RELAXNG_START)
3296 "failed to compile the start\n");
3299 "failed to compile element %s\n",
3306 switch (def->type) {
3307 case XML_RELAXNG_NOOP:
3308 ret = xmlRelaxNGTryCompile(ctxt, def->content);
3310 case XML_RELAXNG_TEXT:
3311 case XML_RELAXNG_DATATYPE:
3312 case XML_RELAXNG_LIST:
3313 case XML_RELAXNG_PARAM:
3314 case XML_RELAXNG_VALUE:
3315 case XML_RELAXNG_EMPTY:
3316 case XML_RELAXNG_ELEMENT:
3319 case XML_RELAXNG_OPTIONAL:
3320 case XML_RELAXNG_ZEROORMORE:
3321 case XML_RELAXNG_ONEORMORE:
3322 case XML_RELAXNG_CHOICE:
3323 case XML_RELAXNG_GROUP:
3324 case XML_RELAXNG_DEF:
3325 case XML_RELAXNG_START:
3326 case XML_RELAXNG_REF:
3327 case XML_RELAXNG_EXTERNALREF:
3328 case XML_RELAXNG_PARENTREF:
3329 list = def->content;
3331 ret = xmlRelaxNGTryCompile(ctxt,
list);
3337 case XML_RELAXNG_EXCEPT:
3338 case XML_RELAXNG_ATTRIBUTE:
3339 case XML_RELAXNG_INTERLEAVE:
3340 case XML_RELAXNG_NOT_ALLOWED:
3353static xmlRelaxNGDefinePtr xmlRelaxNGParseAttribute(xmlRelaxNGParserCtxtPtr
3355static xmlRelaxNGDefinePtr xmlRelaxNGParseElement(xmlRelaxNGParserCtxtPtr
3357static xmlRelaxNGDefinePtr xmlRelaxNGParsePatterns(xmlRelaxNGParserCtxtPtr
3360static xmlRelaxNGDefinePtr xmlRelaxNGParsePattern(xmlRelaxNGParserCtxtPtr
3362static xmlRelaxNGPtr xmlRelaxNGParseDocument(xmlRelaxNGParserCtxtPtr ctxt,
3364static int xmlRelaxNGParseGrammarContent(xmlRelaxNGParserCtxtPtr ctxt,
3366static xmlRelaxNGDefinePtr xmlRelaxNGParseNameClass(xmlRelaxNGParserCtxtPtr
3370static xmlRelaxNGGrammarPtr xmlRelaxNGParseGrammar(xmlRelaxNGParserCtxtPtr
3372static int xmlRelaxNGElementMatch(xmlRelaxNGValidCtxtPtr ctxt,
3373 xmlRelaxNGDefinePtr
define,
3377#define IS_BLANK_NODE(n) (xmlRelaxNGIsBlank((n)->content))
3388xmlRelaxNGIsNullable(xmlRelaxNGDefinePtr
define)
3395 if (
define->dflags & IS_NULLABLE)
3397 if (
define->dflags & IS_NOT_NULLABLE)
3400 case XML_RELAXNG_EMPTY:
3401 case XML_RELAXNG_TEXT:
3404 case XML_RELAXNG_NOOP:
3405 case XML_RELAXNG_DEF:
3406 case XML_RELAXNG_REF:
3407 case XML_RELAXNG_EXTERNALREF:
3408 case XML_RELAXNG_PARENTREF:
3409 case XML_RELAXNG_ONEORMORE:
3410 ret = xmlRelaxNGIsNullable(
define->content);
3412 case XML_RELAXNG_EXCEPT:
3413 case XML_RELAXNG_NOT_ALLOWED:
3414 case XML_RELAXNG_ELEMENT:
3415 case XML_RELAXNG_DATATYPE:
3416 case XML_RELAXNG_PARAM:
3417 case XML_RELAXNG_VALUE:
3418 case XML_RELAXNG_LIST:
3419 case XML_RELAXNG_ATTRIBUTE:
3422 case XML_RELAXNG_CHOICE:{
3426 ret = xmlRelaxNGIsNullable(
list);
3434 case XML_RELAXNG_START:
3435 case XML_RELAXNG_INTERLEAVE:
3436 case XML_RELAXNG_GROUP:{
3440 ret = xmlRelaxNGIsNullable(
list);
3452 define->dflags |= IS_NOT_NULLABLE;
3454 define->dflags |= IS_NULLABLE;
3497 if ((IS_RELAXNG(
node,
"data")) || (IS_RELAXNG(
node,
"value"))) {
3541static xmlRelaxNGDefinePtr
3542xmlRelaxNGParseValue(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node)
3544 xmlRelaxNGDefinePtr def =
NULL;
3545 xmlRelaxNGTypeLibraryPtr lib =
NULL;
3550 def = xmlRelaxNGNewDefine(ctxt,
node);
3553 def->type = XML_RELAXNG_VALUE;
3557 xmlRelaxNGNormExtSpace(
type);
3558 if (xmlValidateNCName(
type, 0)) {
3560 "value type '%s' is not an NCName\n",
type,
NULL);
3562 library = xmlRelaxNGGetDataTypeLibrary(ctxt,
node);
3570 lib = (xmlRelaxNGTypeLibraryPtr)
3574 "Use of unregistered type library '%s'\n",
library,
3579 if (lib->have ==
NULL) {
3581 "Internal error with type library '%s': no 'have'\n",
3584 success = lib->have(lib->data, def->name);
3587 "Error type '%s' is not exported by type library '%s'\n",
3599 "Expecting a single text value for <value>content\n",
3601 }
else if (def !=
NULL) {
3603 if (def->value ==
NULL) {
3605 "Element <value> has no content\n",
NULL,
NULL);
3610 lib->check(lib->data, def->name, def->value, &
val,
node);
3613 "Value '%s' is not acceptable for type '%s'\n",
3614 def->value, def->name);
3633static xmlRelaxNGDefinePtr
3634xmlRelaxNGParseData(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node)
3637 xmlRelaxNGDefinePtr
param, lastparam =
NULL;
3638 xmlRelaxNGTypeLibraryPtr lib;
3650 xmlRelaxNGNormExtSpace(
type);
3651 if (xmlValidateNCName(
type, 0)) {
3653 "data type '%s' is not an NCName\n",
type,
NULL);
3655 library = xmlRelaxNGGetDataTypeLibrary(ctxt,
node);
3660 def = xmlRelaxNGNewDefine(ctxt,
node);
3666 def->type = XML_RELAXNG_DATATYPE;
3670 lib = (xmlRelaxNGTypeLibraryPtr)
3674 "Use of unregistered type library '%s'\n",
library,
3679 if (lib->have ==
NULL) {
3681 "Internal error with type library '%s': no 'have'\n",
3684 tmp = lib->have(lib->data, def->name);
3687 "Error type '%s' is not exported by type library '%s'\n",
3693 "http://www.w3.org/2001/XMLSchema-datatypes"))
3709 BAD_CAST "http://relaxng.org/ns/structure/1.0")) {
3711 "Type library '%s' does not allow type parameters\n",
3718 param = xmlRelaxNGNewDefine(ctxt,
node);
3720 param->type = XML_RELAXNG_PARAM;
3724 "param has no name\n",
NULL,
NULL);
3727 if (lastparam ==
NULL) {
3728 def->attrs = lastparam =
param;
3730 lastparam->next =
param;
3745 xmlRelaxNGDefinePtr tmp2,
last =
NULL;
3751 except->type = XML_RELAXNG_EXCEPT;
3756 "except has no content\n",
NULL,
NULL);
3759 tmp2 = xmlRelaxNGParsePattern(ctxt,
child);
3777 "Element data has unexpected content %s\n",
3800xmlRelaxNGCompareNameClasses(xmlRelaxNGDefinePtr def1,
3801 xmlRelaxNGDefinePtr def2)
3806 xmlRelaxNGValidCtxt ctxt;
3808 memset(&ctxt, 0,
sizeof(xmlRelaxNGValidCtxt));
3810 ctxt.flags = FLAGS_IGNORABLE | FLAGS_NOERROR;
3812 if ((def1->type == XML_RELAXNG_ELEMENT) ||
3813 (def1->type == XML_RELAXNG_ATTRIBUTE)) {
3814 if (def2->type == XML_RELAXNG_TEXT)
3816 if (def1->name !=
NULL) {
3817 node.name = def1->name;
3819 node.name = invalidName;
3821 if (def1->ns !=
NULL) {
3822 if (def1->ns[0] == 0) {
3831 if (xmlRelaxNGElementMatch(&ctxt, def2, &
node)) {
3832 if (def1->nameClass !=
NULL) {
3833 ret = xmlRelaxNGCompareNameClasses(def1->nameClass, def2);
3840 }
else if (def1->type == XML_RELAXNG_TEXT) {
3841 if (def2->type == XML_RELAXNG_TEXT)
3844 }
else if (def1->type == XML_RELAXNG_EXCEPT) {
3845 ret = xmlRelaxNGCompareNameClasses(def1->content, def2);
3855 if ((def2->type == XML_RELAXNG_ELEMENT) ||
3856 (def2->type == XML_RELAXNG_ATTRIBUTE)) {
3857 if (def2->name !=
NULL) {
3858 node.name = def2->name;
3860 node.name = invalidName;
3863 if (def2->ns !=
NULL) {
3864 if (def2->ns[0] == 0) {
3870 ns.href = invalidName;
3872 if (xmlRelaxNGElementMatch(&ctxt, def1, &
node)) {
3873 if (def2->nameClass !=
NULL) {
3874 ret = xmlRelaxNGCompareNameClasses(def2->nameClass, def1);
3901xmlRelaxNGCompareElemDefLists(xmlRelaxNGParserCtxtPtr ctxt
3903 xmlRelaxNGDefinePtr * def2)
3905 xmlRelaxNGDefinePtr *basedef2 = def2;
3907 if ((def1 ==
NULL) || (def2 ==
NULL))
3909 if ((*def1 ==
NULL) || (*def2 ==
NULL))
3911 while (*def1 !=
NULL) {
3912 while ((*def2) !=
NULL) {
3913 if (xmlRelaxNGCompareNameClasses(*def1, *def2) == 0)
3933xmlRelaxNGGenerateAttributes(xmlRelaxNGParserCtxtPtr ctxt,
3934 xmlRelaxNGDefinePtr def)
3942 if (ctxt->nbErrors != 0)
3948 if ((
cur->type == XML_RELAXNG_ELEMENT) ||
3949 (
cur->type == XML_RELAXNG_TEXT) ||
3950 (
cur->type == XML_RELAXNG_DATATYPE) ||
3951 (
cur->type == XML_RELAXNG_PARAM) ||
3952 (
cur->type == XML_RELAXNG_LIST) ||
3953 (
cur->type == XML_RELAXNG_VALUE) ||
3954 (
cur->type == XML_RELAXNG_EMPTY))
3956 if ((
cur->type == XML_RELAXNG_CHOICE) ||
3957 (
cur->type == XML_RELAXNG_INTERLEAVE) ||
3958 (
cur->type == XML_RELAXNG_GROUP) ||
3959 (
cur->type == XML_RELAXNG_ONEORMORE) ||
3960 (
cur->type == XML_RELAXNG_ZEROORMORE) ||
3961 (
cur->type == XML_RELAXNG_OPTIONAL) ||
3962 (
cur->type == XML_RELAXNG_PARENTREF) ||
3963 (
cur->type == XML_RELAXNG_EXTERNALREF) ||
3964 (
cur->type == XML_RELAXNG_REF) ||
3965 (
cur->type == XML_RELAXNG_DEF)) {
3970 while (tmp !=
NULL) {
4008static xmlRelaxNGDefinePtr *
4009xmlRelaxNGGetElements(xmlRelaxNGParserCtxtPtr ctxt,
4010 xmlRelaxNGDefinePtr def,
int eora)
4020 if (ctxt->nbErrors != 0)
4026 if (((eora == 0) && ((
cur->type == XML_RELAXNG_ELEMENT) ||
4027 (
cur->type == XML_RELAXNG_TEXT))) ||
4028 ((eora == 1) && (
cur->type == XML_RELAXNG_ATTRIBUTE)) ||
4029 ((eora == 2) && ((
cur->type == XML_RELAXNG_DATATYPE) ||
4030 (
cur->type == XML_RELAXNG_ELEMENT) ||
4031 (
cur->type == XML_RELAXNG_LIST) ||
4032 (
cur->type == XML_RELAXNG_TEXT) ||
4033 (
cur->type == XML_RELAXNG_VALUE)))) {
4036 ret = (xmlRelaxNGDefinePtr *)
4039 xmlRngPErrMemory(ctxt,
"getting element list\n");
4043 xmlRelaxNGDefinePtr *
temp;
4047 (
max + 1) *
sizeof(xmlRelaxNGDefinePtr));
4049 xmlRngPErrMemory(ctxt,
"getting element list\n");
4057 }
else if ((
cur->type == XML_RELAXNG_CHOICE) ||
4058 (
cur->type == XML_RELAXNG_INTERLEAVE) ||
4059 (
cur->type == XML_RELAXNG_GROUP) ||
4060 (
cur->type == XML_RELAXNG_ONEORMORE) ||
4061 (
cur->type == XML_RELAXNG_ZEROORMORE) ||
4062 (
cur->type == XML_RELAXNG_OPTIONAL) ||
4063 (
cur->type == XML_RELAXNG_PARENTREF) ||
4064 (
cur->type == XML_RELAXNG_REF) ||
4065 (
cur->type == XML_RELAXNG_DEF) ||
4066 (
cur->type == XML_RELAXNG_EXTERNALREF)) {
4075 while (tmp !=
NULL) {
4111xmlRelaxNGCheckChoiceDeterminism(xmlRelaxNGParserCtxtPtr ctxt,
4112 xmlRelaxNGDefinePtr def)
4114 xmlRelaxNGDefinePtr **
list;
4115 xmlRelaxNGDefinePtr
cur;
4116 int nbchild = 0,
i,
j,
ret;
4117 int is_nullable = 0;
4118 int is_indeterminist = 0;
4122 if ((def ==
NULL) || (def->type != XML_RELAXNG_CHOICE))
4125 if (def->dflags & IS_PROCESSED)
4132 if (ctxt->nbErrors != 0)
4135 is_nullable = xmlRelaxNGIsNullable(def);
4144 sizeof(xmlRelaxNGDefinePtr
4147 xmlRngPErrMemory(ctxt,
"building choice\n");
4154 if (is_nullable == 0) {
4161 list[
i] = xmlRelaxNGGetElements(ctxt,
cur, 0);
4164 }
else if (is_triable == 1) {
4165 xmlRelaxNGDefinePtr *tmp;
4169 while ((*tmp !=
NULL) && (is_triable == 1)) {
4170 if ((*tmp)->type == XML_RELAXNG_TEXT) {
4176 }
else if (((*tmp)->type == XML_RELAXNG_ELEMENT) &&
4177 ((*tmp)->name !=
NULL)) {
4178 if (((*tmp)->ns ==
NULL) || ((*tmp)->ns[0] == 0))
4184 (*tmp)->name, (*tmp)->ns,
4188 }
else if ((*tmp)->type == XML_RELAXNG_ELEMENT) {
4189 if (((*tmp)->ns ==
NULL) || ((*tmp)->ns[0] == 0))
4209 for (
i = 0;
i < nbchild;
i++) {
4212 for (
j = 0;
j <
i;
j++) {
4215 ret = xmlRelaxNGCompareElemDefLists(ctxt,
list[
i],
list[
j]);
4217 is_indeterminist = 1;
4221 for (
i = 0;
i < nbchild;
i++) {
4227 if (is_indeterminist) {
4228 def->dflags |= IS_INDETERMINIST;
4230 if (is_triable == 1) {
4231 def->dflags |= IS_TRIABLE;
4233 }
else if (triage !=
NULL) {
4236 def->dflags |= IS_PROCESSED;
4247xmlRelaxNGCheckGroupAttrs(xmlRelaxNGParserCtxtPtr ctxt,
4248 xmlRelaxNGDefinePtr def)
4250 xmlRelaxNGDefinePtr **
list;
4251 xmlRelaxNGDefinePtr
cur;
4252 int nbchild = 0,
i,
j,
ret;
4254 if ((def ==
NULL) ||
4255 ((def->type != XML_RELAXNG_GROUP) &&
4256 (def->type != XML_RELAXNG_ELEMENT)))
4259 if (def->dflags & IS_PROCESSED)
4266 if (ctxt->nbErrors != 0)
4281 sizeof(xmlRelaxNGDefinePtr
4284 xmlRngPErrMemory(ctxt,
"building group\n");
4290 list[
i] = xmlRelaxNGGetElements(ctxt,
cur, 1);
4296 list[
i] = xmlRelaxNGGetElements(ctxt,
cur, 1);
4301 for (
i = 0;
i < nbchild;
i++) {
4304 for (
j = 0;
j <
i;
j++) {
4307 ret = xmlRelaxNGCompareElemDefLists(ctxt,
list[
i],
list[
j]);
4310 "Attributes conflicts in group\n",
NULL,
NULL);
4314 for (
i = 0;
i < nbchild;
i++) {
4320 def->dflags |= IS_PROCESSED;
4339xmlRelaxNGComputeInterleaves(
void *payload,
void *
data,
4342 xmlRelaxNGDefinePtr def = (xmlRelaxNGDefinePtr) payload;
4343 xmlRelaxNGParserCtxtPtr ctxt = (xmlRelaxNGParserCtxtPtr)
data;
4344 xmlRelaxNGDefinePtr
cur, *tmp;
4346 xmlRelaxNGPartitionPtr partitions =
NULL;
4348 xmlRelaxNGInterleaveGroupPtr
group;
4353 int is_determinist = 1;
4359 if (ctxt->nbErrors != 0)
4362#ifdef DEBUG_INTERLEAVE
4364 "xmlRelaxNGComputeInterleaves(%s)\n",
name);
4372#ifdef DEBUG_INTERLEAVE
4375 groups = (xmlRelaxNGInterleaveGroupPtr *)
4376 xmlMalloc(nbchild *
sizeof(xmlRelaxNGInterleaveGroupPtr));
4381 groups[nbgroups] = (xmlRelaxNGInterleaveGroupPtr)
4382 xmlMalloc(
sizeof(xmlRelaxNGInterleaveGroup));
4385 if (
cur->type == XML_RELAXNG_TEXT)
4388 groups[nbgroups]->defs = xmlRelaxNGGetElements(ctxt,
cur, 2);
4389 groups[nbgroups]->attrs = xmlRelaxNGGetElements(ctxt,
cur, 1);
4393#ifdef DEBUG_INTERLEAVE
4400 partitions = (xmlRelaxNGPartitionPtr)
4402 if (partitions ==
NULL)
4404 memset(partitions, 0,
sizeof(xmlRelaxNGPartition));
4405 partitions->nbgroups = nbgroups;
4407 for (
i = 0;
i < nbgroups;
i++) {
4409 for (
j =
i + 1;
j < nbgroups;
j++) {
4413 ret = xmlRelaxNGCompareElemDefLists(ctxt,
group->defs,
4417 "Element or text conflicts in interleave\n",
4420 ret = xmlRelaxNGCompareElemDefLists(ctxt,
group->attrs,
4424 "Attributes conflicts in interleave\n",
NULL,
4429 if ((tmp !=
NULL) && (*tmp !=
NULL)) {
4430 while (*tmp !=
NULL) {
4431 if ((*tmp)->type == XML_RELAXNG_TEXT) {
4436 is_determinist = -1;
4437 }
else if (((*tmp)->type == XML_RELAXNG_ELEMENT) &&
4438 ((*tmp)->name !=
NULL)) {
4439 if (((*tmp)->ns ==
NULL) || ((*tmp)->ns[0] == 0))
4445 (*tmp)->name, (*tmp)->ns,
4448 is_determinist = -1;
4449 }
else if ((*tmp)->type == XML_RELAXNG_ELEMENT) {
4450 if (((*tmp)->ns ==
NULL) || ((*tmp)->ns[0] == 0))
4458 if ((*tmp)->nameClass !=
NULL)
4461 is_determinist = -1;
4463 is_determinist = -1;
4471 partitions->groups =
groups;
4476 def->data = partitions;
4478 def->dflags |= IS_MIXED;
4479 if (is_determinist == 1)
4480 partitions->flags = IS_DETERMINIST;
4481 if (is_determinist == 2)
4482 partitions->flags = IS_DETERMINIST | IS_NEEDCHECK;
4486 xmlRngPErrMemory(ctxt,
"in interleave computation\n");
4488 for (
i = 0;
i < nbgroups;
i++)
4496 xmlRelaxNGFreePartition(partitions);
4508static xmlRelaxNGDefinePtr
4509xmlRelaxNGParseInterleave(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node)
4511 xmlRelaxNGDefinePtr def =
NULL;
4515 def = xmlRelaxNGNewDefine(ctxt,
node);
4519 def->type = XML_RELAXNG_INTERLEAVE;
4521 if (ctxt->interleaves ==
NULL)
4523 if (ctxt->interleaves ==
NULL) {
4524 xmlRngPErrMemory(ctxt,
"create interleaves\n");
4528 snprintf(
name, 32,
"interleave%d", ctxt->nbInterleaves++);
4531 "Failed to add %s to hash table\n",
4538 "Element interleave is empty\n",
NULL,
NULL);
4541 if (IS_RELAXNG(
child,
"element")) {
4542 cur = xmlRelaxNGParseElement(ctxt,
child);
4544 cur = xmlRelaxNGParsePattern(ctxt,
child);
4571xmlRelaxNGParseInclude(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node)
4573 xmlRelaxNGIncludePtr incl;
4580 "Include node has no data\n",
NULL,
NULL);
4591 "Include document root is not a grammar\n",
NULL,
NULL);
4599 tmp = xmlRelaxNGParseGrammarContent(ctxt,
root->children);
4604 tmp = xmlRelaxNGParseGrammarContent(ctxt,
node->children);
4621xmlRelaxNGParseDefine(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node)
4625 xmlRelaxNGDefinePtr def;
4631 "define has no name\n",
NULL,
NULL);
4633 xmlRelaxNGNormExtSpace(
name);
4634 if (xmlValidateNCName(
name, 0)) {
4636 "define name '%s' is not an NCName\n",
name,
NULL);
4638 def = xmlRelaxNGNewDefine(ctxt,
node);
4643 def->type = XML_RELAXNG_DEF;
4647 "define has no children\n",
NULL,
NULL);
4649 olddefine = ctxt->define;
4650 ctxt->define =
name;
4652 xmlRelaxNGParsePatterns(ctxt,
node->children, 0);
4653 ctxt->define = olddefine;
4655 if (ctxt->grammar->defs ==
NULL)
4657 if (ctxt->grammar->defs ==
NULL) {
4659 "Could not create definition hash\n",
NULL,
NULL);
4664 xmlRelaxNGDefinePtr prev;
4669 "Internal error on define aggregation of %s\n",
4673 while (prev->nextHash !=
NULL)
4674 prev = prev->nextHash;
4675 prev->nextHash = def;
4692xmlRelaxNGParseImportRef(
void *payload,
void *
data,
const xmlChar *
name) {
4693 xmlRelaxNGParserCtxtPtr ctxt = (xmlRelaxNGParserCtxtPtr)
data;
4694 xmlRelaxNGDefinePtr def = (xmlRelaxNGDefinePtr) payload;
4697 def->dflags |= IS_EXTERNAL_REF;
4701 xmlRelaxNGDefinePtr prev;
4703 prev = (xmlRelaxNGDefinePtr)
4706 if (def->name !=
NULL) {
4708 "Error refs definitions '%s'\n",
4712 "Error refs definitions\n",
4716 def->nextHash = prev->nextHash;
4717 prev->nextHash = def;
4732xmlRelaxNGParseImportRefs(xmlRelaxNGParserCtxtPtr ctxt,
4733 xmlRelaxNGGrammarPtr grammar) {
4734 if ((ctxt ==
NULL) || (grammar ==
NULL) || (ctxt->grammar ==
NULL))
4736 if (grammar->refs ==
NULL)
4738 if (ctxt->grammar->refs ==
NULL)
4740 if (ctxt->grammar->refs ==
NULL) {
4742 "Could not create references hash\n",
NULL,
NULL);
4745 xmlHashScan(grammar->refs, xmlRelaxNGParseImportRef, ctxt);
4758static xmlRelaxNGDefinePtr
4759xmlRelaxNGProcessExternalRef(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node)
4761 xmlRelaxNGDocumentPtr docu;
4764 int newNs = 0, oldflags;
4765 xmlRelaxNGDefinePtr def;
4769 def = xmlRelaxNGNewDefine(ctxt,
node);
4772 def->type = XML_RELAXNG_EXTERNALREF;
4774 if (docu->content ==
NULL) {
4781 "xmlRelaxNGParse: %s is empty\n", ctxt->URL,
4810 oldflags = ctxt->flags;
4811 ctxt->flags |= XML_RELAXNG_IN_EXTERNALREF;
4812 docu->schema = xmlRelaxNGParseDocument(ctxt,
root);
4813 ctxt->flags = oldflags;
4814 if ((docu->schema !=
NULL) &&
4815 (docu->schema->topgrammar !=
NULL)) {
4816 docu->content = docu->schema->topgrammar->start;
4817 if (docu->schema->topgrammar->refs)
4818 xmlRelaxNGParseImportRefs(ctxt, docu->schema->topgrammar);
4828 def->content = docu->content;
4845static xmlRelaxNGDefinePtr
4846xmlRelaxNGParsePattern(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node)
4848 xmlRelaxNGDefinePtr def =
NULL;
4853 if (IS_RELAXNG(
node,
"element")) {
4854 def = xmlRelaxNGParseElement(ctxt,
node);
4855 }
else if (IS_RELAXNG(
node,
"attribute")) {
4856 def = xmlRelaxNGParseAttribute(ctxt,
node);
4857 }
else if (IS_RELAXNG(
node,
"empty")) {
4858 def = xmlRelaxNGNewDefine(ctxt,
node);
4861 def->type = XML_RELAXNG_EMPTY;
4864 "empty: had a child node\n",
NULL,
NULL);
4866 }
else if (IS_RELAXNG(
node,
"text")) {
4867 def = xmlRelaxNGNewDefine(ctxt,
node);
4870 def->type = XML_RELAXNG_TEXT;
4873 "text: had a child node\n",
NULL,
NULL);
4875 }
else if (IS_RELAXNG(
node,
"zeroOrMore")) {
4876 def = xmlRelaxNGNewDefine(ctxt,
node);
4879 def->type = XML_RELAXNG_ZEROORMORE;
4882 "Element %s is empty\n",
node->name,
NULL);
4885 xmlRelaxNGParsePatterns(ctxt,
node->children, 1);
4887 }
else if (IS_RELAXNG(
node,
"oneOrMore")) {
4888 def = xmlRelaxNGNewDefine(ctxt,
node);
4891 def->type = XML_RELAXNG_ONEORMORE;
4894 "Element %s is empty\n",
node->name,
NULL);
4897 xmlRelaxNGParsePatterns(ctxt,
node->children, 1);
4899 }
else if (IS_RELAXNG(
node,
"optional")) {
4900 def = xmlRelaxNGNewDefine(ctxt,
node);
4903 def->type = XML_RELAXNG_OPTIONAL;
4906 "Element %s is empty\n",
node->name,
NULL);
4909 xmlRelaxNGParsePatterns(ctxt,
node->children, 1);
4911 }
else if (IS_RELAXNG(
node,
"choice")) {
4912 def = xmlRelaxNGNewDefine(ctxt,
node);
4915 def->type = XML_RELAXNG_CHOICE;
4918 "Element %s is empty\n",
node->name,
NULL);
4921 xmlRelaxNGParsePatterns(ctxt,
node->children, 0);
4923 }
else if (IS_RELAXNG(
node,
"group")) {
4924 def = xmlRelaxNGNewDefine(ctxt,
node);
4927 def->type = XML_RELAXNG_GROUP;
4930 "Element %s is empty\n",
node->name,
NULL);
4933 xmlRelaxNGParsePatterns(ctxt,
node->children, 0);
4935 }
else if (IS_RELAXNG(
node,
"ref")) {
4936 def = xmlRelaxNGNewDefine(ctxt,
node);
4939 def->type = XML_RELAXNG_REF;
4941 if (def->name ==
NULL) {
4945 xmlRelaxNGNormExtSpace(def->name);
4946 if (xmlValidateNCName(def->name, 0)) {
4948 "ref name '%s' is not an NCName\n", def->name,
4956 if (ctxt->grammar->refs ==
NULL)
4958 if (ctxt->grammar->refs ==
NULL) {
4960 "Could not create references hash\n",
NULL,
NULL);
4967 xmlRelaxNGDefinePtr prev;
4969 prev = (xmlRelaxNGDefinePtr)
4972 if (def->name !=
NULL) {
4974 "Error refs definitions '%s'\n",
4978 "Error refs definitions\n",
4983 def->nextHash = prev->nextHash;
4984 prev->nextHash = def;
4988 }
else if (IS_RELAXNG(
node,
"data")) {
4989 def = xmlRelaxNGParseData(ctxt,
node);
4990 }
else if (IS_RELAXNG(
node,
"value")) {
4991 def = xmlRelaxNGParseValue(ctxt,
node);
4992 }
else if (IS_RELAXNG(
node,
"list")) {
4993 def = xmlRelaxNGNewDefine(ctxt,
node);
4996 def->type = XML_RELAXNG_LIST;
4999 "Element %s is empty\n",
node->name,
NULL);
5002 xmlRelaxNGParsePatterns(ctxt,
node->children, 0);
5004 }
else if (IS_RELAXNG(
node,
"interleave")) {
5005 def = xmlRelaxNGParseInterleave(ctxt,
node);
5006 }
else if (IS_RELAXNG(
node,
"externalRef")) {
5007 def = xmlRelaxNGProcessExternalRef(ctxt,
node);
5008 }
else if (IS_RELAXNG(
node,
"notAllowed")) {
5009 def = xmlRelaxNGNewDefine(ctxt,
node);
5012 def->type = XML_RELAXNG_NOT_ALLOWED;
5015 "xmlRelaxNGParse: notAllowed element is not empty\n",
5018 }
else if (IS_RELAXNG(
node,
"grammar")) {
5019 xmlRelaxNGGrammarPtr grammar, old;
5020 xmlRelaxNGGrammarPtr oldparent;
5024 "Found <grammar> pattern\n");
5027 oldparent = ctxt->parentgrammar;
5028 old = ctxt->grammar;
5029 ctxt->parentgrammar = old;
5030 grammar = xmlRelaxNGParseGrammar(ctxt,
node->children);
5032 ctxt->grammar = old;
5033 ctxt->parentgrammar = oldparent;
5035 if (grammar !=
NULL) {
5036 grammar->next = old->next;
5037 old->next = grammar;
5041 if (grammar !=
NULL)
5042 def = grammar->start;
5045 }
else if (IS_RELAXNG(
node,
"parentRef")) {
5046 if (ctxt->parentgrammar ==
NULL) {
5048 "Use of parentRef without a parent grammar\n",
NULL,
5052 def = xmlRelaxNGNewDefine(ctxt,
node);
5055 def->type = XML_RELAXNG_PARENTREF;
5057 if (def->name ==
NULL) {
5059 "parentRef has no name\n",
NULL,
NULL);
5061 xmlRelaxNGNormExtSpace(def->name);
5062 if (xmlValidateNCName(def->name, 0)) {
5064 "parentRef name '%s' is not an NCName\n",
5070 "parentRef is not empty\n",
NULL,
NULL);
5072 if (ctxt->parentgrammar->refs ==
NULL)
5074 if (ctxt->parentgrammar->refs ==
NULL) {
5076 "Could not create references hash\n",
NULL,
NULL);
5078 }
else if (def->name !=
NULL) {
5084 xmlRelaxNGDefinePtr prev;
5086 prev = (xmlRelaxNGDefinePtr)
5090 "Internal error parentRef definitions '%s'\n",
5094 def->nextHash = prev->nextHash;
5095 prev->nextHash = def;
5099 }
else if (IS_RELAXNG(
node,
"mixed")) {
5105 def = xmlRelaxNGParseInterleave(ctxt,
node);
5107 xmlRelaxNGDefinePtr tmp;
5109 if ((def->content !=
NULL) && (def->content->next !=
NULL)) {
5110 tmp = xmlRelaxNGNewDefine(ctxt,
node);
5112 tmp->type = XML_RELAXNG_GROUP;
5113 tmp->content = def->content;
5118 tmp = xmlRelaxNGNewDefine(ctxt,
node);
5121 tmp->type = XML_RELAXNG_TEXT;
5122 tmp->next = def->content;
5128 "Unexpected node %s is not a pattern\n",
node->name,
5144static xmlRelaxNGDefinePtr
5145xmlRelaxNGParseAttribute(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node)
5147 xmlRelaxNGDefinePtr
ret,
cur;
5151 ret = xmlRelaxNGNewDefine(ctxt,
node);
5154 ret->type = XML_RELAXNG_ATTRIBUTE;
5155 ret->parent = ctxt->def;
5159 "xmlRelaxNGParseattribute: attribute has no children\n",
5163 old_flags = ctxt->flags;
5164 ctxt->flags |= XML_RELAXNG_IN_ATTRIBUTE;
5170 cur = xmlRelaxNGParsePattern(ctxt,
child);
5172 switch (
cur->type) {
5173 case XML_RELAXNG_EMPTY:
5174 case XML_RELAXNG_NOT_ALLOWED:
5175 case XML_RELAXNG_TEXT:
5176 case XML_RELAXNG_ELEMENT:
5177 case XML_RELAXNG_DATATYPE:
5178 case XML_RELAXNG_VALUE:
5179 case XML_RELAXNG_LIST:
5180 case XML_RELAXNG_REF:
5181 case XML_RELAXNG_PARENTREF:
5182 case XML_RELAXNG_EXTERNALREF:
5183 case XML_RELAXNG_DEF:
5184 case XML_RELAXNG_ONEORMORE:
5185 case XML_RELAXNG_ZEROORMORE:
5186 case XML_RELAXNG_OPTIONAL:
5187 case XML_RELAXNG_CHOICE:
5188 case XML_RELAXNG_GROUP:
5189 case XML_RELAXNG_INTERLEAVE:
5190 case XML_RELAXNG_ATTRIBUTE:
5194 case XML_RELAXNG_START:
5195 case XML_RELAXNG_PARAM:
5196 case XML_RELAXNG_EXCEPT:
5198 "attribute has invalid content\n",
NULL,
5201 case XML_RELAXNG_NOOP:
5203 "RNG Internal error, noop found in attribute\n",
5212 "attribute has multiple children\n",
NULL,
NULL);
5214 ctxt->flags = old_flags;
5228static xmlRelaxNGDefinePtr
5229xmlRelaxNGParseExceptNameClass(xmlRelaxNGParserCtxtPtr ctxt,
5235 if (!IS_RELAXNG(
node,
"except")) {
5237 "Expecting an except node\n",
NULL,
NULL);
5242 "exceptNameClass allows only a single except node\n",
5251 ret = xmlRelaxNGNewDefine(ctxt,
node);
5254 ret->type = XML_RELAXNG_EXCEPT;
5257 cur = xmlRelaxNGNewDefine(ctxt,
child);
5261 cur->type = XML_RELAXNG_ATTRIBUTE;
5263 cur->type = XML_RELAXNG_ELEMENT;
5265 if (xmlRelaxNGParseNameClass(ctxt,
child,
cur) !=
NULL) {
5289static xmlRelaxNGDefinePtr
5290xmlRelaxNGParseNameClass(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node,
5291 xmlRelaxNGDefinePtr def)
5293 xmlRelaxNGDefinePtr
ret, tmp;
5297 if ((IS_RELAXNG(
node,
"name")) || (IS_RELAXNG(
node,
"anyName")) ||
5298 (IS_RELAXNG(
node,
"nsName"))) {
5299 if ((def->type != XML_RELAXNG_ELEMENT) &&
5300 (def->type != XML_RELAXNG_ATTRIBUTE)) {
5301 ret = xmlRelaxNGNewDefine(ctxt,
node);
5305 if (ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE)
5306 ret->type = XML_RELAXNG_ATTRIBUTE;
5308 ret->type = XML_RELAXNG_ELEMENT;
5311 if (IS_RELAXNG(
node,
"name")) {
5313 xmlRelaxNGNormExtSpace(
val);
5314 if (xmlValidateNCName(
val, 0)) {
5317 "Element %s name '%s' is not an NCName\n",
5321 "name '%s' is not an NCName\n",
5327 if ((ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE) &&
5331 "Attribute with namespace '%s' is not allowed\n",
5334 if ((ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE) &&
5338 "Attribute with QName 'xmlns' is not allowed\n",
5341 }
else if (IS_RELAXNG(
node,
"anyName")) {
5346 xmlRelaxNGParseExceptNameClass(ctxt,
node->children,
5348 XML_RELAXNG_ATTRIBUTE));
5350 }
else if (IS_RELAXNG(
node,
"nsName")) {
5355 "nsName has no ns attribute\n",
NULL,
NULL);
5357 if ((ctxt->flags & XML_RELAXNG_IN_ATTRIBUTE) &&
5360 (
ret->ns,
BAD_CAST "http://www.w3.org/2000/xmlns"))) {
5362 "Attribute with namespace '%s' is not allowed\n",
5367 xmlRelaxNGParseExceptNameClass(ctxt,
node->children,
5369 XML_RELAXNG_ATTRIBUTE));
5371 }
else if (IS_RELAXNG(
node,
"choice")) {
5375 if (def->type == XML_RELAXNG_CHOICE) {
5378 ret = xmlRelaxNGNewDefine(ctxt,
node);
5382 ret->type = XML_RELAXNG_CHOICE;
5387 "Element choice is empty\n",
NULL,
NULL);
5392 tmp = xmlRelaxNGParseNameClass(ctxt,
child,
ret);
5406 "expecting name, anyName, nsName or choice : got %s\n",
5412 if (def->nameClass ==
NULL) {
5413 def->nameClass =
ret;
5415 tmp = def->nameClass;
5416 while (tmp->next !=
NULL) {
5434static xmlRelaxNGDefinePtr
5435xmlRelaxNGParseElement(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node)
5441 ret = xmlRelaxNGNewDefine(ctxt,
node);
5444 ret->type = XML_RELAXNG_ELEMENT;
5445 ret->parent = ctxt->def;
5449 "xmlRelaxNGParseElement: element has no children\n",
5459 "xmlRelaxNGParseElement: element has no content\n",
5463 olddefine = ctxt->define;
5464 ctxt->define =
NULL;
5467 cur = xmlRelaxNGParsePattern(ctxt,
child);
5470 switch (
cur->type) {
5471 case XML_RELAXNG_EMPTY:
5472 case XML_RELAXNG_NOT_ALLOWED:
5473 case XML_RELAXNG_TEXT:
5474 case XML_RELAXNG_ELEMENT:
5475 case XML_RELAXNG_DATATYPE:
5476 case XML_RELAXNG_VALUE:
5477 case XML_RELAXNG_LIST:
5478 case XML_RELAXNG_REF:
5479 case XML_RELAXNG_PARENTREF:
5480 case XML_RELAXNG_EXTERNALREF:
5481 case XML_RELAXNG_DEF:
5482 case XML_RELAXNG_ZEROORMORE:
5483 case XML_RELAXNG_ONEORMORE:
5484 case XML_RELAXNG_OPTIONAL:
5485 case XML_RELAXNG_CHOICE:
5486 case XML_RELAXNG_GROUP:
5487 case XML_RELAXNG_INTERLEAVE:
5491 if ((
last->type == XML_RELAXNG_ELEMENT) &&
5493 ret->content = xmlRelaxNGNewDefine(ctxt,
node);
5495 ret->content->type = XML_RELAXNG_GROUP;
5505 case XML_RELAXNG_ATTRIBUTE:
5509 case XML_RELAXNG_START:
5511 "RNG Internal error, start found in element\n",
5514 case XML_RELAXNG_PARAM:
5516 "RNG Internal error, param found in element\n",