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",
5519 case XML_RELAXNG_EXCEPT:
5521 "RNG Internal error, except found in element\n",
5524 case XML_RELAXNG_NOOP:
5526 "RNG Internal error, noop found in element\n",
5533 ctxt->define = olddefine;
5547static xmlRelaxNGDefinePtr
5548xmlRelaxNGParsePatterns(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr nodes,
5554 while (nodes !=
NULL) {
5555 if (IS_RELAXNG(nodes,
"element")) {
5556 cur = xmlRelaxNGParseElement(ctxt, nodes);
5562 if ((
group == 1) && (def->type == XML_RELAXNG_ELEMENT) &&
5564 def = xmlRelaxNGNewDefine(ctxt, nodes);
5567 def->type = XML_RELAXNG_GROUP;
5568 def->content =
last;
5575 cur = xmlRelaxNGParsePattern(ctxt, nodes);
5585 nodes = nodes->
next;
5600xmlRelaxNGParseStart(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr nodes)
5603 xmlRelaxNGDefinePtr def =
NULL,
last;
5605 if (nodes ==
NULL) {
5610 if (IS_RELAXNG(nodes,
"empty")) {
5611 def = xmlRelaxNGNewDefine(ctxt, nodes);
5614 def->type = XML_RELAXNG_EMPTY;
5617 "element empty is not empty\n",
NULL,
NULL);
5619 }
else if (IS_RELAXNG(nodes,
"notAllowed")) {
5620 def = xmlRelaxNGNewDefine(ctxt, nodes);
5623 def->type = XML_RELAXNG_NOT_ALLOWED;
5626 "element notAllowed is not empty\n",
NULL,
NULL);
5629 def = xmlRelaxNGParsePatterns(ctxt, nodes, 1);
5631 if (ctxt->grammar->start !=
NULL) {
5632 last = ctxt->grammar->start;
5637 ctxt->grammar->start = def;
5639 nodes = nodes->
next;
5640 if (nodes !=
NULL) {
5642 "start more than one children\n",
NULL,
NULL);
5658xmlRelaxNGParseGrammarContent(xmlRelaxNGParserCtxtPtr ctxt,
5663 if (nodes ==
NULL) {
5665 "grammar has no children\n",
NULL,
NULL);
5668 while (nodes !=
NULL) {
5669 if (IS_RELAXNG(nodes,
"start")) {
5672 "start has no children\n",
NULL,
NULL);
5674 tmp = xmlRelaxNGParseStart(ctxt, nodes->
children);
5678 }
else if (IS_RELAXNG(nodes,
"define")) {
5679 tmp = xmlRelaxNGParseDefine(ctxt, nodes);
5682 }
else if (IS_RELAXNG(nodes,
"include")) {
5683 tmp = xmlRelaxNGParseInclude(ctxt, nodes);
5688 "grammar has unexpected child %s\n", nodes->
name,
5692 nodes = nodes->
next;
5707xmlRelaxNGCheckReference(
void *payload,
void *
data,
const xmlChar *
name)
5709 xmlRelaxNGDefinePtr
ref = (xmlRelaxNGDefinePtr) payload;
5710 xmlRelaxNGParserCtxtPtr ctxt = (xmlRelaxNGParserCtxtPtr)
data;
5711 xmlRelaxNGGrammarPtr grammar;
5712 xmlRelaxNGDefinePtr def,
cur;
5717 if (
ref->dflags & IS_EXTERNAL_REF)
5720 grammar = ctxt->grammar;
5721 if (grammar ==
NULL) {
5723 "Internal error: no grammar in CheckReference %s\n",
5729 "Internal error: reference has content in CheckReference %s\n",
5733 if (grammar->defs !=
NULL) {
5743 "Reference %s has no matching definition\n",
name,
5748 "Reference %s has no matching definition\n",
name,
5763xmlRelaxNGCheckCombine(
void *payload,
void *
data,
const xmlChar *
name)
5765 xmlRelaxNGDefinePtr
define = (xmlRelaxNGDefinePtr) payload;
5766 xmlRelaxNGParserCtxtPtr ctxt = (xmlRelaxNGParserCtxtPtr)
data;
5768 int choiceOrInterleave = -1;
5770 xmlRelaxNGDefinePtr
cur,
last, tmp, tmp2;
5777 if (combine !=
NULL) {
5779 if (choiceOrInterleave == -1)
5780 choiceOrInterleave = 1;
5781 else if (choiceOrInterleave == 0) {
5783 "Defines for %s use both 'choice' and 'interleave'\n",
5787 if (choiceOrInterleave == -1)
5788 choiceOrInterleave = 0;
5789 else if (choiceOrInterleave == 1) {
5791 "Defines for %s use both 'choice' and 'interleave'\n",
5796 "Defines for %s use unknown combine value '%s''\n",
5805 "Some defines for %s needs the combine attribute\n",
5814 "xmlRelaxNGCheckCombine(): merging %s defines: %d\n",
5815 name, choiceOrInterleave);
5817 if (choiceOrInterleave == -1)
5818 choiceOrInterleave = 0;
5819 cur = xmlRelaxNGNewDefine(ctxt,
define->node);
5822 if (choiceOrInterleave == 0)
5823 cur->type = XML_RELAXNG_INTERLEAVE;
5825 cur->type = XML_RELAXNG_CHOICE;
5828 while (tmp !=
NULL) {
5829 if (tmp->content !=
NULL) {
5830 if (tmp->content->next !=
NULL) {
5834 tmp2 = xmlRelaxNGNewDefine(ctxt, tmp->content->node);
5837 tmp2->type = XML_RELAXNG_GROUP;
5838 tmp2->content = tmp->content;
5840 tmp2 = tmp->content;
5843 cur->content = tmp2;
5850 tmp = tmp->nextHash;
5853 if (choiceOrInterleave == 0) {
5854 if (ctxt->interleaves ==
NULL)
5856 if (ctxt->interleaves ==
NULL) {
5858 "Failed to create interleaves hash table\n",
NULL,
5863 snprintf(tmpname, 32,
"interleave%d", ctxt->nbInterleaves++);
5867 "Failed to add %s to hash table\n",
5883xmlRelaxNGCombineStart(xmlRelaxNGParserCtxtPtr ctxt,
5884 xmlRelaxNGGrammarPtr grammar)
5886 xmlRelaxNGDefinePtr starts;
5888 int choiceOrInterleave = -1;
5890 xmlRelaxNGDefinePtr
cur;
5892 starts = grammar->start;
5893 if ((starts ==
NULL) || (starts->next ==
NULL))
5901 "Internal error: start element not found\n",
NULL,
5907 if (combine !=
NULL) {
5909 if (choiceOrInterleave == -1)
5910 choiceOrInterleave = 1;
5911 else if (choiceOrInterleave == 0) {
5913 "<start> use both 'choice' and 'interleave'\n",
5917 if (choiceOrInterleave == -1)
5918 choiceOrInterleave = 0;
5919 else if (choiceOrInterleave == 1) {
5921 "<start> use both 'choice' and 'interleave'\n",
5926 "<start> uses unknown combine value '%s''\n",
5935 "Some <start> element miss the combine attribute\n",
5944 "xmlRelaxNGCombineStart(): merging <start>: %d\n",
5945 choiceOrInterleave);
5947 if (choiceOrInterleave == -1)
5948 choiceOrInterleave = 0;
5949 cur = xmlRelaxNGNewDefine(ctxt, starts->node);
5952 if (choiceOrInterleave == 0)
5953 cur->type = XML_RELAXNG_INTERLEAVE;
5955 cur->type = XML_RELAXNG_CHOICE;
5956 cur->content = grammar->start;
5957 grammar->start =
cur;
5958 if (choiceOrInterleave == 0) {
5959 if (ctxt->interleaves ==
NULL)
5961 if (ctxt->interleaves ==
NULL) {
5963 "Failed to create interleaves hash table\n",
NULL,
5968 snprintf(tmpname, 32,
"interleave%d", ctxt->nbInterleaves++);
5972 "Failed to add %s to hash table\n",
5990xmlRelaxNGCheckCycles(xmlRelaxNGParserCtxtPtr ctxt,
5991 xmlRelaxNGDefinePtr
cur,
int depth)
5996 if ((
cur->type == XML_RELAXNG_REF) ||
5997 (
cur->type == XML_RELAXNG_PARENTREF)) {
5998 if (
cur->depth == -1) {
6000 ret = xmlRelaxNGCheckCycles(ctxt,
cur->content,
depth);
6004 "Detected a cycle in %s references\n",
6008 }
else if (
cur->type == XML_RELAXNG_ELEMENT) {
6009 ret = xmlRelaxNGCheckCycles(ctxt,
cur->content,
depth + 1);
6011 ret = xmlRelaxNGCheckCycles(ctxt,
cur->content,
depth);
6029static xmlRelaxNGDefinePtr
6031 xmlRelaxNGDefinePtr
cur,
6032 xmlRelaxNGDefinePtr
parent, xmlRelaxNGDefinePtr prev)
6035 prev->next =
cur->next;
6045 cur->type = XML_RELAXNG_NOOP;
6060xmlRelaxNGSimplify(xmlRelaxNGParserCtxtPtr ctxt,
6061 xmlRelaxNGDefinePtr
cur, xmlRelaxNGDefinePtr
parent)
6063 xmlRelaxNGDefinePtr prev =
NULL;
6066 if ((
cur->type == XML_RELAXNG_REF) ||
6067 (
cur->type == XML_RELAXNG_PARENTREF)) {
6068 if (
cur->depth != -3) {
6070 xmlRelaxNGSimplify(ctxt,
cur->content,
cur);
6072 }
else if (
cur->type == XML_RELAXNG_NOT_ALLOWED) {
6075 ((
parent->type == XML_RELAXNG_ATTRIBUTE) ||
6076 (
parent->type == XML_RELAXNG_LIST) ||
6077 (
parent->type == XML_RELAXNG_GROUP) ||
6078 (
parent->type == XML_RELAXNG_INTERLEAVE) ||
6079 (
parent->type == XML_RELAXNG_ONEORMORE) ||
6080 (
parent->type == XML_RELAXNG_ZEROORMORE))) {
6081 parent->type = XML_RELAXNG_NOT_ALLOWED;
6085 prev = xmlRelaxNGTryUnlink(ctxt,
cur,
parent, prev);
6088 }
else if (
cur->type == XML_RELAXNG_EMPTY) {
6091 ((
parent->type == XML_RELAXNG_ONEORMORE) ||
6092 (
parent->type == XML_RELAXNG_ZEROORMORE))) {
6093 parent->type = XML_RELAXNG_EMPTY;
6097 ((
parent->type == XML_RELAXNG_GROUP) ||
6098 (
parent->type == XML_RELAXNG_INTERLEAVE))) {
6099 prev = xmlRelaxNGTryUnlink(ctxt,
cur,
parent, prev);
6105 xmlRelaxNGSimplify(ctxt,
cur->content,
cur);
6106 if ((
cur->type != XML_RELAXNG_VALUE) && (
cur->attrs !=
NULL))
6107 xmlRelaxNGSimplify(ctxt,
cur->attrs,
cur);
6109 xmlRelaxNGSimplify(ctxt,
cur->nameClass,
cur);
6114 if (
cur->type == XML_RELAXNG_ELEMENT) {
6116 xmlRelaxNGDefinePtr tmp, pre;
6118 while (
cur->content !=
NULL) {
6120 xmlRelaxNGGenerateAttributes(ctxt,
cur->content);
6121 if (attronly == 1) {
6126 cur->content = tmp->next;
6127 tmp->next =
cur->attrs;
6137 while ((pre !=
NULL) && (pre->next !=
NULL)) {
6139 attronly = xmlRelaxNGGenerateAttributes(ctxt, tmp);
6140 if (attronly == 1) {
6144 pre->next = tmp->next;
6145 tmp->next =
cur->attrs;
6155 if ((
cur->type == XML_RELAXNG_GROUP) ||
6156 (
cur->type == XML_RELAXNG_INTERLEAVE)) {
6158 cur->type = XML_RELAXNG_EMPTY;
6159 else if (
cur->content->next ==
NULL) {
6161 cur->type = XML_RELAXNG_NOOP;
6162 }
else if (prev ==
NULL) {
6164 cur->content->next =
cur->next;
6167 cur->content->next =
cur->next;
6168 prev->next =
cur->content;
6176 if ((
cur->type == XML_RELAXNG_EXCEPT) &&
6178 (
cur->content->type == XML_RELAXNG_NOT_ALLOWED)) {
6179 prev = xmlRelaxNGTryUnlink(ctxt,
cur,
parent, prev);
6180 }
else if (
cur->type == XML_RELAXNG_NOT_ALLOWED) {
6182 ((
parent->type == XML_RELAXNG_ATTRIBUTE) ||
6183 (
parent->type == XML_RELAXNG_LIST) ||
6184 (
parent->type == XML_RELAXNG_GROUP) ||
6185 (
parent->type == XML_RELAXNG_INTERLEAVE) ||
6186 (
parent->type == XML_RELAXNG_ONEORMORE) ||
6187 (
parent->type == XML_RELAXNG_ZEROORMORE))) {
6188 parent->type = XML_RELAXNG_NOT_ALLOWED;
6192 (
parent->type == XML_RELAXNG_CHOICE)) {
6193 prev = xmlRelaxNGTryUnlink(ctxt,
cur,
parent, prev);
6196 }
else if (
cur->type == XML_RELAXNG_EMPTY) {
6198 ((
parent->type == XML_RELAXNG_ONEORMORE) ||
6199 (
parent->type == XML_RELAXNG_ZEROORMORE))) {
6200 parent->type = XML_RELAXNG_EMPTY;
6204 ((
parent->type == XML_RELAXNG_GROUP) ||
6205 (
parent->type == XML_RELAXNG_INTERLEAVE) ||
6206 (
parent->type == XML_RELAXNG_CHOICE))) {
6207 prev = xmlRelaxNGTryUnlink(ctxt,
cur,
parent, prev);
6227static xmlRelaxNGContentType
6228xmlRelaxNGGroupContentType(xmlRelaxNGContentType ct1,
6229 xmlRelaxNGContentType ct2)
6231 if ((ct1 == XML_RELAXNG_CONTENT_ERROR) ||
6232 (ct2 == XML_RELAXNG_CONTENT_ERROR))
6233 return (XML_RELAXNG_CONTENT_ERROR);
6234 if (ct1 == XML_RELAXNG_CONTENT_EMPTY)
6236 if (ct2 == XML_RELAXNG_CONTENT_EMPTY)
6238 if ((ct1 == XML_RELAXNG_CONTENT_COMPLEX) &&
6239 (ct2 == XML_RELAXNG_CONTENT_COMPLEX))
6240 return (XML_RELAXNG_CONTENT_COMPLEX);
6241 return (XML_RELAXNG_CONTENT_ERROR);
6253static xmlRelaxNGContentType
6254xmlRelaxNGMaxContentType(xmlRelaxNGContentType ct1,
6255 xmlRelaxNGContentType ct2)
6257 if ((ct1 == XML_RELAXNG_CONTENT_ERROR) ||
6258 (ct2 == XML_RELAXNG_CONTENT_ERROR))
6259 return (XML_RELAXNG_CONTENT_ERROR);
6260 if ((ct1 == XML_RELAXNG_CONTENT_SIMPLE) ||
6261 (ct2 == XML_RELAXNG_CONTENT_SIMPLE))
6262 return (XML_RELAXNG_CONTENT_SIMPLE);
6263 if ((ct1 == XML_RELAXNG_CONTENT_COMPLEX) ||
6264 (ct2 == XML_RELAXNG_CONTENT_COMPLEX))
6265 return (XML_RELAXNG_CONTENT_COMPLEX);
6266 return (XML_RELAXNG_CONTENT_EMPTY);
6280static xmlRelaxNGContentType
6281xmlRelaxNGCheckRules(xmlRelaxNGParserCtxtPtr ctxt,
6282 xmlRelaxNGDefinePtr
cur,
int flags,
6283 xmlRelaxNGType ptype)
6286 xmlRelaxNGContentType
ret, tmp,
val = XML_RELAXNG_CONTENT_EMPTY;
6289 ret = XML_RELAXNG_CONTENT_EMPTY;
6290 if ((
cur->type == XML_RELAXNG_REF) ||
6291 (
cur->type == XML_RELAXNG_PARENTREF)) {
6298 if (
flags & XML_RELAXNG_IN_LIST) {
6300 "Found forbidden pattern list//ref\n",
NULL,
6304 if (
flags & XML_RELAXNG_IN_DATAEXCEPT) {
6306 "Found forbidden pattern data/except//ref\n",
6310 if (
cur->type == XML_RELAXNG_PARENTREF)
6312 "Internal found no define for parent refs\n",
6316 "Internal found no define for ref %s\n",
6319 if (
cur->depth > -4) {
6321 ret = xmlRelaxNGCheckRules(ctxt,
cur->content,
6324 }
else if (
cur->depth == -4) {
6325 ret = XML_RELAXNG_CONTENT_COMPLEX;
6327 ret = (xmlRelaxNGContentType) (
cur->depth + 15);
6329 }
else if (
cur->type == XML_RELAXNG_ELEMENT) {
6333 xmlRelaxNGCheckGroupAttrs(ctxt,
cur);
6334 if (
flags & XML_RELAXNG_IN_DATAEXCEPT) {
6336 "Found forbidden pattern data/except//element(ref)\n",
6339 if (
flags & XML_RELAXNG_IN_LIST) {
6341 "Found forbidden pattern list//element(ref)\n",
6344 if (
flags & XML_RELAXNG_IN_ATTRIBUTE) {
6346 "Found forbidden pattern attribute//element(ref)\n",
6349 if (
flags & XML_RELAXNG_IN_ATTRIBUTE) {
6351 "Found forbidden pattern attribute//element(ref)\n",
6360 xmlRelaxNGCheckRules(ctxt,
cur->attrs, nflags,
cur->type);
6361 if (
ret != XML_RELAXNG_CONTENT_EMPTY) {
6363 "Element %s attributes have a content type error\n",
6367 xmlRelaxNGCheckRules(ctxt,
cur->content, nflags,
6369 if (
ret == XML_RELAXNG_CONTENT_ERROR) {
6371 "Element %s has a content type error\n",
6374 ret = XML_RELAXNG_CONTENT_COMPLEX;
6376 }
else if (
cur->type == XML_RELAXNG_ATTRIBUTE) {
6377 if (
flags & XML_RELAXNG_IN_ATTRIBUTE) {
6379 "Found forbidden pattern attribute//attribute\n",
6382 if (
flags & XML_RELAXNG_IN_LIST) {
6384 "Found forbidden pattern list//attribute\n",
6387 if (
flags & XML_RELAXNG_IN_OOMGROUP) {
6389 "Found forbidden pattern oneOrMore//group//attribute\n",
6392 if (
flags & XML_RELAXNG_IN_OOMINTERLEAVE) {
6394 "Found forbidden pattern oneOrMore//interleave//attribute\n",
6397 if (
flags & XML_RELAXNG_IN_DATAEXCEPT) {
6399 "Found forbidden pattern data/except//attribute\n",
6402 if (
flags & XML_RELAXNG_IN_START) {
6404 "Found forbidden pattern start//attribute\n",
6407 if ((!(
flags & XML_RELAXNG_IN_ONEORMORE))
6414 "Found anyName attribute without oneOrMore ancestor\n",
6418 "Found nsName attribute without oneOrMore ancestor\n",
6422 nflags =
flags | XML_RELAXNG_IN_ATTRIBUTE;
6423 xmlRelaxNGCheckRules(ctxt,
cur->content, nflags,
cur->type);
6424 ret = XML_RELAXNG_CONTENT_EMPTY;
6425 }
else if ((
cur->type == XML_RELAXNG_ONEORMORE) ||
6426 (
cur->type == XML_RELAXNG_ZEROORMORE)) {
6427 if (
flags & XML_RELAXNG_IN_DATAEXCEPT) {
6429 "Found forbidden pattern data/except//oneOrMore\n",
6432 if (
flags & XML_RELAXNG_IN_START) {
6434 "Found forbidden pattern start//oneOrMore\n",
6437 nflags =
flags | XML_RELAXNG_IN_ONEORMORE;
6439 xmlRelaxNGCheckRules(ctxt,
cur->content, nflags,
6441 ret = xmlRelaxNGGroupContentType(
ret,
ret);
6442 }
else if (
cur->type == XML_RELAXNG_LIST) {
6443 if (
flags & XML_RELAXNG_IN_LIST) {
6445 "Found forbidden pattern list//list\n",
NULL,
6448 if (
flags & XML_RELAXNG_IN_DATAEXCEPT) {
6450 "Found forbidden pattern data/except//list\n",
6453 if (
flags & XML_RELAXNG_IN_START) {
6455 "Found forbidden pattern start//list\n",
NULL,
6458 nflags =
flags | XML_RELAXNG_IN_LIST;
6460 xmlRelaxNGCheckRules(ctxt,
cur->content, nflags,
6462 }
else if (
cur->type == XML_RELAXNG_GROUP) {
6463 if (
flags & XML_RELAXNG_IN_DATAEXCEPT) {
6465 "Found forbidden pattern data/except//group\n",
6468 if (
flags & XML_RELAXNG_IN_START) {
6470 "Found forbidden pattern start//group\n",
NULL,
6473 if (
flags & XML_RELAXNG_IN_ONEORMORE)
6474 nflags =
flags | XML_RELAXNG_IN_OOMGROUP;
6478 xmlRelaxNGCheckRules(ctxt,
cur->content, nflags,
6483 xmlRelaxNGCheckGroupAttrs(ctxt,
cur);
6484 }
else if (
cur->type == XML_RELAXNG_INTERLEAVE) {
6485 if (
flags & XML_RELAXNG_IN_LIST) {
6487 "Found forbidden pattern list//interleave\n",
6490 if (
flags & XML_RELAXNG_IN_DATAEXCEPT) {
6492 "Found forbidden pattern data/except//interleave\n",
6495 if (
flags & XML_RELAXNG_IN_START) {
6497 "Found forbidden pattern start//interleave\n",
6500 if (
flags & XML_RELAXNG_IN_ONEORMORE)
6501 nflags =
flags | XML_RELAXNG_IN_OOMINTERLEAVE;
6505 xmlRelaxNGCheckRules(ctxt,
cur->content, nflags,
6507 }
else if (
cur->type == XML_RELAXNG_EXCEPT) {
6509 (
cur->parent->type == XML_RELAXNG_DATATYPE))
6510 nflags =
flags | XML_RELAXNG_IN_DATAEXCEPT;
6514 xmlRelaxNGCheckRules(ctxt,
cur->content, nflags,
6516 }
else if (
cur->type == XML_RELAXNG_DATATYPE) {
6517 if (
flags & XML_RELAXNG_IN_START) {
6519 "Found forbidden pattern start//data\n",
NULL,
6522 xmlRelaxNGCheckRules(ctxt,
cur->content,
flags,
cur->type);
6523 ret = XML_RELAXNG_CONTENT_SIMPLE;
6524 }
else if (
cur->type == XML_RELAXNG_VALUE) {
6525 if (
flags & XML_RELAXNG_IN_START) {
6527 "Found forbidden pattern start//value\n",
NULL,
6530 xmlRelaxNGCheckRules(ctxt,
cur->content,
flags,
cur->type);
6531 ret = XML_RELAXNG_CONTENT_SIMPLE;
6532 }
else if (
cur->type == XML_RELAXNG_TEXT) {
6533 if (
flags & XML_RELAXNG_IN_LIST) {
6535 "Found forbidden pattern list//text\n",
NULL,
6538 if (
flags & XML_RELAXNG_IN_DATAEXCEPT) {
6540 "Found forbidden pattern data/except//text\n",
6543 if (
flags & XML_RELAXNG_IN_START) {
6545 "Found forbidden pattern start//text\n",
NULL,
6548 ret = XML_RELAXNG_CONTENT_COMPLEX;
6549 }
else if (
cur->type == XML_RELAXNG_EMPTY) {
6550 if (
flags & XML_RELAXNG_IN_DATAEXCEPT) {
6552 "Found forbidden pattern data/except//empty\n",
6555 if (
flags & XML_RELAXNG_IN_START) {
6557 "Found forbidden pattern start//empty\n",
NULL,
6560 ret = XML_RELAXNG_CONTENT_EMPTY;
6561 }
else if (
cur->type == XML_RELAXNG_CHOICE) {
6562 xmlRelaxNGCheckChoiceDeterminism(ctxt,
cur);
6564 xmlRelaxNGCheckRules(ctxt,
cur->content,
flags,
cur->type);
6567 xmlRelaxNGCheckRules(ctxt,
cur->content,
flags,
cur->type);
6570 if (ptype == XML_RELAXNG_GROUP) {
6571 val = xmlRelaxNGGroupContentType(
val,
ret);
6572 }
else if (ptype == XML_RELAXNG_INTERLEAVE) {
6577 tmp = xmlRelaxNGGroupContentType(
val,
ret);
6578 if (tmp != XML_RELAXNG_CONTENT_ERROR)
6579 tmp = xmlRelaxNGMaxContentType(
val,
ret);
6580 }
else if (ptype == XML_RELAXNG_CHOICE) {
6581 val = xmlRelaxNGMaxContentType(
val,
ret);
6582 }
else if (ptype == XML_RELAXNG_LIST) {
6583 val = XML_RELAXNG_CONTENT_SIMPLE;
6584 }
else if (ptype == XML_RELAXNG_EXCEPT) {
6585 if (
ret == XML_RELAXNG_CONTENT_ERROR)
6586 val = XML_RELAXNG_CONTENT_ERROR;
6588 val = XML_RELAXNG_CONTENT_SIMPLE;
6590 val = xmlRelaxNGGroupContentType(
val,
ret);
6607static xmlRelaxNGGrammarPtr
6608xmlRelaxNGParseGrammar(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr nodes)
6610 xmlRelaxNGGrammarPtr
ret, tmp, old;
6616 ret = xmlRelaxNGNewGrammar(ctxt);
6623 ret->parent = ctxt->grammar;
6624 if (ctxt->grammar !=
NULL) {
6625 tmp = ctxt->grammar->children;
6627 ctxt->grammar->children =
ret;
6629 while (tmp->next !=
NULL)
6635 old = ctxt->grammar;
6636 ctxt->grammar =
ret;
6637 xmlRelaxNGParseGrammarContent(ctxt, nodes);
6638 ctxt->grammar =
ret;
6639 if (ctxt->grammar ==
NULL) {
6641 "Failed to parse <grammar> content\n",
NULL,
NULL);
6642 }
else if (ctxt->grammar->start ==
NULL) {
6644 "Element <grammar> has no <start>\n",
NULL,
NULL);
6650 xmlRelaxNGCombineStart(ctxt,
ret);
6665 ctxt->grammar = old;
6681xmlRelaxNGParseDocument(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node)
6685 xmlRelaxNGGrammarPtr old;
6690 schema = xmlRelaxNGNewRelaxNG(ctxt);
6694 olddefine = ctxt->define;
6695 ctxt->define =
NULL;
6696 if (IS_RELAXNG(
node,
"grammar")) {
6697 schema->topgrammar = xmlRelaxNGParseGrammar(ctxt,
node->children);
6703 xmlRelaxNGGrammarPtr tmp,
ret;
6705 schema->topgrammar =
ret = xmlRelaxNGNewGrammar(ctxt);
6713 ret->parent = ctxt->grammar;
6714 if (ctxt->grammar !=
NULL) {
6715 tmp = ctxt->grammar->children;
6717 ctxt->grammar->children =
ret;
6719 while (tmp->next !=
NULL)
6724 old = ctxt->grammar;
6725 ctxt->grammar =
ret;
6726 xmlRelaxNGParseStart(ctxt,
node);
6728 ctxt->grammar = old;
6730 ctxt->define = olddefine;
6732 xmlRelaxNGCheckCycles(ctxt,
schema->topgrammar->start, 0);
6733 if ((ctxt->flags & XML_RELAXNG_IN_EXTERNALREF) == 0) {
6734 xmlRelaxNGSimplify(ctxt,
schema->topgrammar->start,
NULL);
6735 while ((
schema->topgrammar->start !=
NULL) &&
6736 (
schema->topgrammar->start->type == XML_RELAXNG_NOOP) &&
6738 schema->topgrammar->start =
6739 schema->topgrammar->start->content;
6740 xmlRelaxNGCheckRules(ctxt,
schema->topgrammar->start,
6741 XML_RELAXNG_IN_START, XML_RELAXNG_NOOP);
6747 "xmlRelaxNGParseDocument() failed\n");
6768xmlRelaxNGParserCtxtPtr
6769xmlRelaxNGNewParserCtxt(
const char *URL)
6771 xmlRelaxNGParserCtxtPtr
ret;
6777 (xmlRelaxNGParserCtxtPtr)
xmlMalloc(
sizeof(xmlRelaxNGParserCtxt));
6779 xmlRngPErrMemory(
NULL,
"building parser\n");
6782 memset(
ret, 0,
sizeof(xmlRelaxNGParserCtxt));
6799xmlRelaxNGParserCtxtPtr
6800xmlRelaxNGNewMemParserCtxt(
const char *
buffer,
int size)
6802 xmlRelaxNGParserCtxtPtr
ret;
6808 (xmlRelaxNGParserCtxtPtr)
xmlMalloc(
sizeof(xmlRelaxNGParserCtxt));
6810 xmlRngPErrMemory(
NULL,
"building parser\n");
6813 memset(
ret, 0,
sizeof(xmlRelaxNGParserCtxt));
6831xmlRelaxNGParserCtxtPtr
6832xmlRelaxNGNewDocParserCtxt(
xmlDocPtr doc)
6834 xmlRelaxNGParserCtxtPtr
ret;
6839 copy = xmlCopyDoc(doc, 1);
6844 (xmlRelaxNGParserCtxtPtr)
xmlMalloc(
sizeof(xmlRelaxNGParserCtxt));
6846 xmlRngPErrMemory(
NULL,
"building parser\n");
6850 memset(
ret, 0,
sizeof(xmlRelaxNGParserCtxt));
6864xmlRelaxNGFreeParserCtxt(xmlRelaxNGParserCtxtPtr ctxt)
6868 if (ctxt->URL !=
NULL)
6870 if (ctxt->doc !=
NULL)
6871 xmlRelaxNGFreeDocument(ctxt->doc);
6872 if (ctxt->interleaves !=
NULL)
6874 if (ctxt->documents !=
NULL)
6875 xmlRelaxNGFreeDocumentList(ctxt->documents);
6876 if (ctxt->includes !=
NULL)
6877 xmlRelaxNGFreeIncludeList(ctxt->includes);
6878 if (ctxt->docTab !=
NULL)
6880 if (ctxt->incTab !=
NULL)
6882 if (ctxt->defTab !=
NULL) {
6885 for (
i = 0;
i < ctxt->defNr;
i++)
6886 xmlRelaxNGFreeDefine(ctxt->defTab[
i]);
6889 if ((ctxt->document !=
NULL) && (ctxt->freedoc))
6954xmlRelaxNGCleanupAttributes(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr node)
6971 "Attribute %s is not allowed on %s\n",
6978 "Attribute %s is not allowed on %s\n",
6985 "Attribute %s is not allowed on %s\n",
6992 "Attribute %s is not allowed on %s\n",
7005 "Attribute %s contains invalid URI %s\n",
7010 "Attribute %s URI %s is not absolute\n",
7015 "Attribute %s URI %s has a fragment ID\n",
7025 "Unknown attribute %s on %s\n",
cur->name,
7042xmlRelaxNGCleanupTree(xmlRelaxNGParserCtxtPtr ctxt,
xmlNodePtr root)
7049 if (
delete !=
NULL) {
7066 "element %s doesn't allow foreign elements\n",
7072 xmlRelaxNGCleanupAttributes(ctxt,
cur);
7075 xmlRelaxNGDocumentPtr docu;
7082 while ((tmp !=
NULL) &&
7093 "xmlRelaxNGParse: externalRef has no href attribute\n",
7103 "Incorrect URI for externalRef %s\n",
7114 "Fragment forbidden in URI for externalRef %s\n",
7129 "Failed to compute URL for externalRef %s\n",
7144 docu = xmlRelaxNGLoadExternalRef(ctxt, URL,
ns);
7147 "Failed to load externalRef %s\n", URL,
7161 xmlRelaxNGIncludePtr incl;
7167 "xmlRelaxNGParse: include has no href attribute\n",
7176 "Failed to compute URL for include %s\n",
7192 while ((tmp !=
NULL) &&
7200 incl = xmlRelaxNGLoadInclude(ctxt, URL,
cur,
ns);
7205 "Failed to load include %s\n", URL,
7235 xmlAddPrevSibling(
cur->children,
node);
7243 "Failed to create a name %s element\n",
7301 xmlRngPErr(ctxt,
cur,
7303 "xmlRelaxNGParse: no namespace for prefix %s\n",
7320 if (ctxt->flags & XML_RELAXNG_IN_NSEXCEPT) {
7321 xmlRngPErr(ctxt,
cur,
7323 "Found nsName/except//nsName forbidden construct\n",
7329 int oldflags = ctxt->flags;
7337 ctxt->flags |= XML_RELAXNG_IN_ANYEXCEPT;
7338 xmlRelaxNGCleanupTree(ctxt,
cur);
7339 ctxt->flags = oldflags;
7341 }
else if ((
cur->parent !=
NULL) &&
7344 ctxt->flags |= XML_RELAXNG_IN_NSEXCEPT;
7345 xmlRelaxNGCleanupTree(ctxt,
cur);
7346 ctxt->flags = oldflags;
7353 if (ctxt->flags & XML_RELAXNG_IN_ANYEXCEPT) {
7354 xmlRngPErr(ctxt,
cur,
7356 "Found anyName/except//anyName forbidden construct\n",
7358 }
else if (ctxt->flags & XML_RELAXNG_IN_NSEXCEPT) {
7359 xmlRngPErr(ctxt,
cur,
7361 "Found nsName/except//anyName forbidden construct\n",
7404 parDef = parDef->
next;
7467 if (
delete !=
NULL) {
7485xmlRelaxNGCleanupDoc(xmlRelaxNGParserCtxtPtr ctxt,
xmlDocPtr doc)
7498 xmlRelaxNGCleanupTree(ctxt,
root);
7513xmlRelaxNGParse(xmlRelaxNGParserCtxtPtr ctxt)
7519 xmlRelaxNGInitTypes();
7527 if (ctxt->URL !=
NULL) {
7531 "xmlRelaxNGParse: could not load %s\n", ctxt->URL,
7535 }
else if (ctxt->buffer !=
NULL) {
7539 "xmlRelaxNGParse: could not parse schemas\n",
NULL,
7545 }
else if (ctxt->document !=
NULL) {
7546 doc = ctxt->document;
7549 "xmlRelaxNGParse: nothing to parse\n",
NULL,
NULL);
7552 ctxt->document = doc;
7557 doc = xmlRelaxNGCleanupDoc(ctxt, doc);
7560 ctxt->document =
NULL;
7574 ctxt->document =
NULL;
7577 ret = xmlRelaxNGParseDocument(ctxt,
root);
7580 ctxt->document =
NULL;
7590 if (ctxt->interleaves !=
NULL) {
7591 xmlHashScan(ctxt->interleaves, xmlRelaxNGComputeInterleaves, ctxt);
7597 if (ctxt->nbErrors > 0) {
7598 xmlRelaxNGFree(
ret);
7599 ctxt->document =
NULL;
7607 if ((
ret->topgrammar !=
NULL) && (
ret->topgrammar->start !=
NULL)) {
7608 if (
ret->topgrammar->start->type != XML_RELAXNG_START) {
7609 xmlRelaxNGDefinePtr def;
7611 def = xmlRelaxNGNewDefine(ctxt,
NULL);
7613 def->type = XML_RELAXNG_START;
7614 def->content =
ret->topgrammar->start;
7615 ret->topgrammar->start = def;
7618 xmlRelaxNGTryCompile(ctxt,
ret->topgrammar->start);
7625 ctxt->document =
NULL;
7626 ret->documents = ctxt->documents;
7627 ctxt->documents =
NULL;
7629 ret->includes = ctxt->includes;
7630 ctxt->includes =
NULL;
7631 ret->defNr = ctxt->defNr;
7632 ret->defTab = ctxt->defTab;
7633 ctxt->defTab =
NULL;
7634 if (ctxt->idref == 1)
7650xmlRelaxNGSetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
7651 xmlRelaxNGValidityErrorFunc
err,
7652 xmlRelaxNGValidityWarningFunc
warn,
void *
ctx)
7657 ctxt->warning =
warn;
7658 ctxt->serror =
NULL;
7659 ctxt->userData =
ctx;
7674xmlRelaxNGGetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
7675 xmlRelaxNGValidityErrorFunc *
err,
7676 xmlRelaxNGValidityWarningFunc *
warn,
void **
ctx)
7683 *
warn = ctxt->warning;
7685 *
ctx = ctxt->userData;
7698xmlRelaxNGSetParserStructuredErrors(xmlRelaxNGParserCtxtPtr ctxt,
7704 ctxt->serror = serror;
7706 ctxt->warning =
NULL;
7707 ctxt->userData =
ctx;
7710#ifdef LIBXML_OUTPUT_ENABLED
7717static void xmlRelaxNGDumpDefine(
FILE * output,
7718 xmlRelaxNGDefinePtr
define);
7728xmlRelaxNGDumpDefines(
FILE * output, xmlRelaxNGDefinePtr
defines)
7731 xmlRelaxNGDumpDefine(output,
defines);
7744xmlRelaxNGDumpDefine(
FILE * output, xmlRelaxNGDefinePtr
define)
7749 case XML_RELAXNG_EMPTY:
7750 fprintf(output,
"<empty/>\n");
7752 case XML_RELAXNG_NOT_ALLOWED:
7753 fprintf(output,
"<notAllowed/>\n");
7755 case XML_RELAXNG_TEXT:
7758 case XML_RELAXNG_ELEMENT:
7759 fprintf(output,
"<element>\n");
7766 xmlRelaxNGDumpDefines(output,
define->attrs);
7767 xmlRelaxNGDumpDefines(output,
define->content);
7768 fprintf(output,
"</element>\n");
7770 case XML_RELAXNG_LIST:
7772 xmlRelaxNGDumpDefines(output,
define->content);
7775 case XML_RELAXNG_ONEORMORE:
7776 fprintf(output,
"<oneOrMore>\n");
7777 xmlRelaxNGDumpDefines(output,
define->content);
7778 fprintf(output,
"</oneOrMore>\n");
7780 case XML_RELAXNG_ZEROORMORE:
7781 fprintf(output,
"<zeroOrMore>\n");
7782 xmlRelaxNGDumpDefines(output,
define->content);
7783 fprintf(output,
"</zeroOrMore>\n");
7785 case XML_RELAXNG_CHOICE:
7786 fprintf(output,
"<choice>\n");
7787 xmlRelaxNGDumpDefines(output,
define->content);
7788 fprintf(output,
"</choice>\n");
7790 case XML_RELAXNG_GROUP:
7792 xmlRelaxNGDumpDefines(output,
define->content);
7793 fprintf(output,
"</group>\n");
7795 case XML_RELAXNG_INTERLEAVE:
7796 fprintf(output,
"<interleave>\n");
7797 xmlRelaxNGDumpDefines(output,
define->content);
7798 fprintf(output,
"</interleave>\n");
7800 case XML_RELAXNG_OPTIONAL:
7801 fprintf(output,
"<optional>\n");
7802 xmlRelaxNGDumpDefines(output,
define->content);
7803 fprintf(output,
"</optional>\n");
7805 case XML_RELAXNG_ATTRIBUTE:
7806 fprintf(output,
"<attribute>\n");
7807 xmlRelaxNGDumpDefines(output,
define->content);
7808 fprintf(output,
"</attribute>\n");
7810 case XML_RELAXNG_DEF:
7815 xmlRelaxNGDumpDefines(output,
define->content);
7816 fprintf(output,
"</define>\n");
7818 case XML_RELAXNG_REF:
7823 xmlRelaxNGDumpDefines(output,
define->content);
7826 case XML_RELAXNG_PARENTREF:
7827 fprintf(output,
"<parentRef");
7831 xmlRelaxNGDumpDefines(output,
define->content);
7832 fprintf(output,
"</parentRef>\n");
7834 case XML_RELAXNG_EXTERNALREF:
7835 fprintf(output,
"<externalRef>");
7836 xmlRelaxNGDumpDefines(output,
define->content);
7837 fprintf(output,
"</externalRef>\n");
7839 case XML_RELAXNG_DATATYPE:
7840 case XML_RELAXNG_VALUE:
7842 case XML_RELAXNG_START:
7843 case XML_RELAXNG_EXCEPT:
7844 case XML_RELAXNG_PARAM:
7846 case XML_RELAXNG_NOOP:
7847 xmlRelaxNGDumpDefines(output,
define->content);
7861xmlRelaxNGDumpGrammar(
FILE * output, xmlRelaxNGGrammarPtr grammar,
int top)
7863 if (grammar ==
NULL)
7868 fprintf(output,
" xmlns=\"http://relaxng.org/ns/structure/1.0\"");
7869 switch (grammar->combine) {
7870 case XML_RELAXNG_COMBINE_UNDEFINED:
7872 case XML_RELAXNG_COMBINE_CHOICE:
7873 fprintf(output,
" combine=\"choice\"");
7875 case XML_RELAXNG_COMBINE_INTERLEAVE:
7876 fprintf(output,
" combine=\"interleave\"");
7879 fprintf(output,
" <!-- invalid combine value -->");
7882 if (grammar->start ==
NULL) {
7883 fprintf(output,
" <!-- grammar had no start -->");
7886 xmlRelaxNGDumpDefine(output, grammar->start);
7887 fprintf(output,
"</start>\n");
7890 fprintf(output,
"</grammar>\n");
7901xmlRelaxNGDump(
FILE * output, xmlRelaxNGPtr
schema)
7906 fprintf(output,
"RelaxNG empty or failed to compile\n");
7911 fprintf(output,
"no document\n");
7918 fprintf(output,
"RelaxNG has no top grammar\n");
7921 xmlRelaxNGDumpGrammar(output,
schema->topgrammar, 1);
7932xmlRelaxNGDumpTree(
FILE * output, xmlRelaxNGPtr
schema)
7937 fprintf(output,
"RelaxNG empty or failed to compile\n");
7941 fprintf(output,
"no document\n");
7943 xmlDocDump(output,
schema->doc);
7953static int xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt,
7954 xmlRelaxNGDefinePtr
define);
7968 void *transdata,
void *inputdata)
7970 xmlRelaxNGValidCtxtPtr ctxt = (xmlRelaxNGValidCtxtPtr) inputdata;
7971 xmlRelaxNGDefinePtr
define = (xmlRelaxNGDefinePtr) transdata;
7976 "Compiled callback for: '%s'\n",
token);
7983 if (
token[0] ==
'#')
7986 if ((ctxt !=
NULL) && (ctxt->errNo == XML_RELAXNG_OK))
7987 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
7992 if ((ctxt !=
NULL) && (ctxt->errNo == XML_RELAXNG_OK))
7993 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
7995 }
else if (
define->type != XML_RELAXNG_ELEMENT) {
7997 if (ctxt->errNo == XML_RELAXNG_OK)
7998 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
8001 ret = xmlRelaxNGValidateDefinition(ctxt,
define);
8017xmlRelaxNGValidateCompiledContent(xmlRelaxNGValidCtxtPtr ctxt,
8020 xmlRegExecCtxtPtr exec;
8025 if ((ctxt ==
NULL) || (regexp ==
NULL))
8027 oldperr = ctxt->perr;
8028 exec = xmlRegNewExecCtxt(regexp,
8029 xmlRelaxNGValidateCompiledCallback, ctxt);
8033 ctxt->state->seq =
cur;
8034 switch (
cur->type) {
8039 ret = xmlRegExecPushString(exec,
BAD_CAST "#text", ctxt);
8041 VALID_ERR2(XML_RELAXNG_ERR_TEXTWRONG,
8047 ret = xmlRegExecPushString2(exec,
cur->name,
8048 cur->ns->href, ctxt);
8050 ret = xmlRegExecPushString(exec,
cur->name, ctxt);
8053 VALID_ERR2(XML_RELAXNG_ERR_ELEMWRONG,
cur->name);
8069 ctxt->state->seq =
NULL;
8070 }
else if (
ret == 0) {
8074 VALID_ERR2(XML_RELAXNG_ERR_NOELEM,
BAD_CAST "");
8076 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
8077 xmlRelaxNGDumpValidError(ctxt);
8081 xmlRegFreeExecCtxt(exec);
8086 if ((
ret == 0) && (ctxt->perr != 0)) {
8089 ctxt->perr = oldperr;
8098static int xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt,
8100static int xmlRelaxNGValidateElementEnd(xmlRelaxNGValidCtxtPtr ctxt,
8102static void xmlRelaxNGLogBestError(xmlRelaxNGValidCtxtPtr ctxt);
8114xmlRelaxNGElemPush(xmlRelaxNGValidCtxtPtr ctxt, xmlRegExecCtxtPtr exec)
8116 if (ctxt->elemTab ==
NULL) {
8118 ctxt->elemTab = (xmlRegExecCtxtPtr *)
xmlMalloc(ctxt->elemMax *
8120 (xmlRegExecCtxtPtr));
8121 if (ctxt->elemTab ==
NULL) {
8122 xmlRngVErrMemory(ctxt,
"validating\n");
8126 if (ctxt->elemNr >= ctxt->elemMax) {
8128 ctxt->elemTab = (xmlRegExecCtxtPtr *)
xmlRealloc(ctxt->elemTab,
8131 (xmlRegExecCtxtPtr));
8132 if (ctxt->elemTab ==
NULL) {
8133 xmlRngVErrMemory(ctxt,
"validating\n");
8137 ctxt->elemTab[ctxt->elemNr++] = exec;
8150static xmlRegExecCtxtPtr
8151xmlRelaxNGElemPop(xmlRelaxNGValidCtxtPtr ctxt)
8153 xmlRegExecCtxtPtr
ret;
8155 if (ctxt->elemNr <= 0)
8158 ret = ctxt->elemTab[ctxt->elemNr];
8159 ctxt->elemTab[ctxt->elemNr] =
NULL;
8160 if (ctxt->elemNr > 0)
8161 ctxt->elem = ctxt->elemTab[ctxt->elemNr - 1];
8178xmlRelaxNGValidateProgressiveCallback(xmlRegExecCtxtPtr exec
8181 void *transdata,
void *inputdata)
8183 xmlRelaxNGValidCtxtPtr ctxt = (xmlRelaxNGValidCtxtPtr) inputdata;
8184 xmlRelaxNGDefinePtr
define = (xmlRelaxNGDefinePtr) transdata;
8185 xmlRelaxNGValidStatePtr
state, oldstate;
8187 int ret = 0, oldflags;
8189#ifdef DEBUG_PROGRESSIVE
8191 "Progressive callback for: '%s'\n",
token);
8200 if (
token[0] ==
'#')
8203 if ((ctxt !=
NULL) && (ctxt->errNo == XML_RELAXNG_OK))
8204 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
8210 if ((ctxt !=
NULL) && (ctxt->errNo == XML_RELAXNG_OK))
8211 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
8214 }
else if (
define->type != XML_RELAXNG_ELEMENT) {
8216 if (ctxt->errNo == XML_RELAXNG_OK)
8217 ctxt->errNo = XML_RELAXNG_ERR_INTERNAL;
8222 VALID_ERR(XML_RELAXNG_ERR_NOTELEM);
8223 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
8224 xmlRelaxNGDumpValidError(ctxt);
8232#ifdef DEBUG_PROGRESSIVE
8234 "Element '%s' validation is not streamable\n",
8241 exec = xmlRegNewExecCtxt(
define->contModel,
8242 xmlRelaxNGValidateProgressiveCallback, ctxt);
8247 xmlRelaxNGElemPush(ctxt, exec);
8252 state = xmlRelaxNGNewValidState(ctxt,
node);
8257 oldstate = ctxt->state;
8258 ctxt->state =
state;
8260 ret = xmlRelaxNGValidateAttributeList(ctxt,
define->attrs);
8263 VALID_ERR2(XML_RELAXNG_ERR_ATTRVALID,
node->name);
8266 if (ctxt->state !=
NULL) {
8267 ctxt->state->seq =
NULL;
8268 ret = xmlRelaxNGValidateElementEnd(ctxt, 1);
8272 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
8273 }
else if (ctxt->states !=
NULL) {
8276 oldflags = ctxt->flags;
8278 for (
i = 0;
i < ctxt->states->nbState;
i++) {
8279 state = ctxt->states->tabState[
i];
8280 ctxt->state =
state;
8281 ctxt->state->seq =
NULL;
8283 if (xmlRelaxNGValidateElementEnd(ctxt, 0) == 0) {
8292 ctxt->flags |= FLAGS_IGNORABLE;
8293 xmlRelaxNGLogBestError(ctxt);
8295 for (
i = 0;
i < ctxt->states->nbState;
i++) {
8296 xmlRelaxNGFreeValidState(ctxt, ctxt->states->tabState[
i]);
8298 xmlRelaxNGFreeStates(ctxt, ctxt->states);
8299 ctxt->states =
NULL;
8300 if ((
ret == 0) && (tmp == -1))
8302 ctxt->flags = oldflags;
8304 if (ctxt->pstate == -1) {
8305 if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
8306 xmlRelaxNGDumpValidError(ctxt);
8309 ctxt->state = oldstate;
8324xmlRelaxNGValidatePushElement(xmlRelaxNGValidCtxtPtr ctxt,
8333#ifdef DEBUG_PROGRESSIVE
8336 if (ctxt->elem == 0) {
8338 xmlRelaxNGGrammarPtr grammar;
8339 xmlRegExecCtxtPtr exec;
8340 xmlRelaxNGDefinePtr
define;
8344 VALID_ERR(XML_RELAXNG_ERR_NOGRAMMAR);
8347 grammar =
schema->topgrammar;
8348 if ((grammar ==
NULL) || (grammar->start ==
NULL)) {
8349 VALID_ERR(XML_RELAXNG_ERR_NOGRAMMAR);
8357 exec = xmlRegNewExecCtxt(
define->contModel,
8358 xmlRelaxNGValidateProgressiveCallback,
8363 xmlRelaxNGElemPush(ctxt, exec);
8369 xmlRegExecPushString2(ctxt->elem,
elem->name,
elem->ns->href,
8372 ret = xmlRegExecPushString(ctxt->elem,
elem->name, ctxt);
8375 VALID_ERR2(XML_RELAXNG_ERR_ELEMWRONG,
elem->name);
8377 if (ctxt->pstate == 0)
8379 else if (ctxt->pstate < 0)
8384#ifdef DEBUG_PROGRESSIVE
8403xmlRelaxNGValidatePushCData(xmlRelaxNGValidCtxtPtr ctxt,
8411#ifdef DEBUG_PROGRESSIVE
8415 while (*
data != 0) {
8423 ret = xmlRegExecPushString(ctxt->elem,
BAD_CAST "#text", ctxt);
8425 VALID_ERR2(XML_RELAXNG_ERR_TEXTWRONG,
BAD_CAST " TODO ");
8426#ifdef DEBUG_PROGRESSIVE
8446xmlRelaxNGValidatePopElement(xmlRelaxNGValidCtxtPtr ctxt,
8451 xmlRegExecCtxtPtr exec;
8455#ifdef DEBUG_PROGRESSIVE
8461 exec = xmlRelaxNGElemPop(ctxt);
8467 VALID_ERR2(XML_RELAXNG_ERR_NOELEM,
BAD_CAST "");
8469 }
else if (
ret < 0) {
8474 xmlRegFreeExecCtxt(exec);
8475#ifdef DEBUG_PROGRESSIVE
8495xmlRelaxNGValidateFullElement(xmlRelaxNGValidCtxtPtr ctxt,
8500 xmlRelaxNGValidStatePtr
state;
8504#ifdef DEBUG_PROGRESSIVE
8507 state = xmlRelaxNGNewValidState(ctxt,
elem->parent);
8512 ctxt->state =
state;
8513 ctxt->errNo = XML_RELAXNG_OK;
8514 ret = xmlRelaxNGValidateDefinition(ctxt, ctxt->pdef);
8515 if ((
ret != 0) || (ctxt->errNo != XML_RELAXNG_OK))
8519 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
8521#ifdef DEBUG_PROGRESSIVE
8534static int xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
8535 xmlRelaxNGDefinePtr
define);
8560 ((ctxt->flags & FLAGS_MIXED_CONTENT) ||
8578xmlRelaxNGNormalize(xmlRelaxNGValidCtxtPtr ctxt,
const xmlChar *
str)
8593 xmlRngVErrMemory(ctxt,
"validating\n");
8625xmlRelaxNGValidateDatatype(xmlRelaxNGValidCtxtPtr ctxt,
8630 xmlRelaxNGTypeLibraryPtr lib;
8632 xmlRelaxNGDefinePtr
cur;
8637 lib = (xmlRelaxNGTypeLibraryPtr)
define->data;
8638 if (lib->check !=
NULL) {
8640 (
define->attrs->type == XML_RELAXNG_PARAM)) {
8649 VALID_ERR2(XML_RELAXNG_ERR_TYPE,
define->
name);
8651 lib->freef(lib->data,
result);
8653 }
else if (
ret == 1) {
8655 }
else if (
ret == 2) {
8656 VALID_ERR2P(XML_RELAXNG_ERR_DUPID,
value);
8662 while ((
ret == 0) && (
cur !=
NULL) && (
cur->type == XML_RELAXNG_PARAM)) {
8663 if (lib->facet !=
NULL) {
8672 const xmlChar *oldvalue, *oldendvalue;
8674 oldvalue = ctxt->state->value;
8675 oldendvalue = ctxt->state->endvalue;
8677 ctxt->state->endvalue =
NULL;
8678 ret = xmlRelaxNGValidateValue(ctxt,
define->content);
8679 ctxt->state->value = (
xmlChar *) oldvalue;
8680 ctxt->state->endvalue = (
xmlChar *) oldendvalue;
8683 lib->freef(lib->data,
result);
8696xmlRelaxNGNextValue(xmlRelaxNGValidCtxtPtr ctxt)
8700 cur = ctxt->state->value;
8701 if ((
cur ==
NULL) || (ctxt->state->endvalue ==
NULL)) {
8702 ctxt->state->value =
NULL;
8703 ctxt->state->endvalue =
NULL;
8708 while ((
cur != ctxt->state->endvalue) && (*
cur == 0))
8710 if (
cur == ctxt->state->endvalue)
8711 ctxt->state->value =
NULL;
8727xmlRelaxNGValidateValueList(xmlRelaxNGValidCtxtPtr ctxt,
8733 ret = xmlRelaxNGValidateValue(ctxt,
defines);
8751xmlRelaxNGValidateValue(xmlRelaxNGValidCtxtPtr ctxt,
8752 xmlRelaxNGDefinePtr
define)
8754 int ret = 0, oldflags;
8757 value = ctxt->state->value;
8759 case XML_RELAXNG_EMPTY:{
8770 case XML_RELAXNG_TEXT:
8772 case XML_RELAXNG_VALUE:{
8775 xmlRelaxNGTypeLibraryPtr lib;
8777 lib = (xmlRelaxNGTypeLibraryPtr)
define->data;
8782 value, ctxt->state->node);
8786 VALID_ERR2(XML_RELAXNG_ERR_TYPECMP,
8789 }
else if (
ret == 1) {
8802 nvalue = xmlRelaxNGNormalize(ctxt,
value);
8804 if ((nval ==
NULL) || (nvalue ==
NULL) ||
8814 xmlRelaxNGNextValue(ctxt);
8817 case XML_RELAXNG_DATATYPE:{
8821 xmlRelaxNGNextValue(ctxt);
8825 case XML_RELAXNG_CHOICE:{
8829 oldflags = ctxt->flags;
8830 ctxt->flags |= FLAGS_IGNORABLE;
8832 oldvalue = ctxt->state->
value;
8834 ret = xmlRelaxNGValidateValue(ctxt,
list);
8838 ctxt->state->value = oldvalue;
8841 ctxt->flags = oldflags;
8843 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
8844 xmlRelaxNGDumpValidError(ctxt);
8846 if (ctxt->errNr > 0)
8847 xmlRelaxNGPopErrors(ctxt, 0);
8851 case XML_RELAXNG_LIST:{
8859 oldvalue = ctxt->state->value;
8860 oldend = ctxt->state->endvalue;
8867 VALID_ERR(XML_RELAXNG_ERR_NOSTATE);
8885 "list value: '%s' found %d items\n",
8886 oldvalue, nb_values);
8889 ctxt->state->endvalue =
cur;
8891 while ((*
cur == 0) && (
cur != ctxt->state->endvalue))
8894 ctxt->state->value =
cur;
8897 if (ctxt->state->value == ctxt->state->endvalue)
8898 ctxt->state->value =
NULL;
8899 ret = xmlRelaxNGValidateValue(ctxt,
list);
8903 "Failed to validate value: '%s' with %d rule\n",
8904 ctxt->state->value, nb_values);
8914 if ((
ret == 0) && (ctxt->state->value !=
NULL) &&
8915 (ctxt->state->value != ctxt->state->endvalue)) {
8916 VALID_ERR2(XML_RELAXNG_ERR_LISTEXTRA,
8917 ctxt->state->value);
8921 ctxt->state->value = oldvalue;
8922 ctxt->state->endvalue = oldend;
8925 case XML_RELAXNG_ONEORMORE:
8926 ret = xmlRelaxNGValidateValueList(ctxt,
define->content);
8931 case XML_RELAXNG_ZEROORMORE:{
8934 if ((ctxt->state->value ==
NULL) ||
8935 (*ctxt->state->value == 0)) {
8939 oldflags = ctxt->flags;
8940 ctxt->flags |= FLAGS_IGNORABLE;
8941 cur = ctxt->state->value;
8943 while ((
cur !=
NULL) && (
cur != ctxt->state->endvalue) &&
8947 xmlRelaxNGValidateValueList(ctxt,
define->content);
8949 ctxt->state->value =
temp;
8953 cur = ctxt->state->value;
8955 ctxt->flags = oldflags;
8956 if (ctxt->errNr > 0)
8957 xmlRelaxNGPopErrors(ctxt, 0);
8960 case XML_RELAXNG_OPTIONAL:{
8963 if ((ctxt->state->value ==
NULL) ||
8964 (*ctxt->state->value == 0)) {
8968 oldflags = ctxt->flags;
8969 ctxt->flags |= FLAGS_IGNORABLE;
8970 temp = ctxt->state->value;
8971 ret = xmlRelaxNGValidateValue(ctxt,
define->content);
8972 ctxt->flags = oldflags;
8974 ctxt->state->value =
temp;
8975 if (ctxt->errNr > 0)
8976 xmlRelaxNGPopErrors(ctxt, 0);
8980 if (ctxt->errNr > 0)
8981 xmlRelaxNGPopErrors(ctxt, 0);
8984 case XML_RELAXNG_EXCEPT:{
8985 xmlRelaxNGDefinePtr
list;
8989 ret = xmlRelaxNGValidateValue(ctxt,
list);
8999 case XML_RELAXNG_DEF:
9000 case XML_RELAXNG_GROUP:{
9001 xmlRelaxNGDefinePtr
list;
9005 ret = xmlRelaxNGValidateValue(ctxt,
list);
9015 case XML_RELAXNG_REF:
9016 case XML_RELAXNG_PARENTREF:
9018 VALID_ERR(XML_RELAXNG_ERR_NODEFINE);
9021 ret = xmlRelaxNGValidateValue(ctxt,
define->content);
9040xmlRelaxNGValidateValueContent(xmlRelaxNGValidCtxtPtr ctxt,
9046 ret = xmlRelaxNGValidateValue(ctxt,
defines);
9065xmlRelaxNGAttributeMatch(xmlRelaxNGValidCtxtPtr ctxt,
9075 if (
define->ns[0] == 0) {
9079 if ((prop->
ns ==
NULL) ||
9087 if (
define->type == XML_RELAXNG_EXCEPT) {
9088 xmlRelaxNGDefinePtr
list;
9092 ret = xmlRelaxNGAttributeMatch(ctxt,
list, prop);
9099 }
else if (
define->type == XML_RELAXNG_CHOICE) {
9100 xmlRelaxNGDefinePtr
list;
9104 ret = xmlRelaxNGAttributeMatch(ctxt,
list, prop);
9127xmlRelaxNGValidateAttribute(xmlRelaxNGValidCtxtPtr ctxt,
9128 xmlRelaxNGDefinePtr
define)
9135 if (ctxt->state->nbAttrLeft <= 0)
9138 for (
i = 0;
i < ctxt->state->nbAttrs;
i++) {
9139 tmp = ctxt->state->attrs[
i];
9142 (tmp->ns ==
NULL)) ||
9143 ((tmp->ns !=
NULL) &&
9152 oldvalue = ctxt->state->value;
9153 oldseq = ctxt->state->seq;
9155 ctxt->state->value =
value;
9156 ctxt->state->endvalue =
NULL;
9157 ret = xmlRelaxNGValidateValueContent(ctxt,
define->content);
9158 if (ctxt->state->value !=
NULL)
9159 value = ctxt->state->value;
9162 ctxt->state->value = oldvalue;
9163 ctxt->state->seq = oldseq;
9168 ctxt->state->attrs[
i] =
NULL;
9169 ctxt->state->nbAttrLeft--;
9176 "xmlRelaxNGValidateAttribute(%s): %d\n",
9180 for (
i = 0;
i < ctxt->state->nbAttrs;
i++) {
9181 tmp = ctxt->state->attrs[
i];
9182 if ((tmp !=
NULL) &&
9183 (xmlRelaxNGAttributeMatch(ctxt,
define, tmp) == 1)) {
9190 oldvalue = ctxt->state->value;
9191 oldseq = ctxt->state->seq;
9193 ctxt->state->value =
value;
9194 ret = xmlRelaxNGValidateValueContent(ctxt,
define->content);
9195 if (ctxt->state->value !=
NULL)
9196 value = ctxt->state->value;
9199 ctxt->state->value = oldvalue;
9200 ctxt->state->seq = oldseq;
9205 ctxt->state->attrs[
i] =
NULL;
9206 ctxt->state->nbAttrLeft--;
9214 "xmlRelaxNGValidateAttribute(nsName ns = %s): %d\n",
9218 "xmlRelaxNGValidateAttribute(anyName): %d\n",
9237xmlRelaxNGValidateAttributeList(xmlRelaxNGValidCtxtPtr ctxt,
9242 xmlRelaxNGDefinePtr
cur;
9246 if (
cur->type == XML_RELAXNG_ATTRIBUTE) {
9247 if (xmlRelaxNGValidateAttribute(ctxt,
cur) != 0)
9257 if (
cur->type != XML_RELAXNG_ATTRIBUTE) {
9258 if ((ctxt->state !=
NULL) || (ctxt->states !=
NULL)) {
9259 res = xmlRelaxNGValidateDefinition(ctxt,
cur);
9263 VALID_ERR(XML_RELAXNG_ERR_NOSTATE);
9287 xmlRelaxNGDefinePtr
cur;
9296 (
cur->type == XML_RELAXNG_ELEMENT)) {
9302 ((
cur->type == XML_RELAXNG_DATATYPE) ||
9303 (
cur->type == XML_RELAXNG_LIST) ||
9304 (
cur->type == XML_RELAXNG_TEXT) ||
9305 (
cur->type == XML_RELAXNG_VALUE))) {
9323xmlRelaxNGValidateInterleave(xmlRelaxNGValidCtxtPtr ctxt,
9324 xmlRelaxNGDefinePtr
define)
9326 int ret = 0,
i, nbgroups;
9327 int errNr = ctxt->errNr;
9330 xmlRelaxNGValidStatePtr oldstate;
9331 xmlRelaxNGPartitionPtr partitions;
9332 xmlRelaxNGInterleaveGroupPtr
group =
NULL;
9337 partitions = (xmlRelaxNGPartitionPtr)
define->data;
9338 nbgroups = partitions->nbgroups;
9340 VALID_ERR(XML_RELAXNG_ERR_INTERNODATA);
9346 oldflags = ctxt->flags;
9347 if (
define->dflags & IS_MIXED) {
9348 ctxt->flags |= FLAGS_MIXED_CONTENT;
9349 if (nbgroups == 2) {
9353 if (ctxt->state !=
NULL)
9354 ctxt->state->seq = xmlRelaxNGSkipIgnored(ctxt,
9356 if (partitions->groups[0]->rule->type == XML_RELAXNG_TEXT)
9357 ret = xmlRelaxNGValidateDefinition(ctxt,
9358 partitions->groups[1]->
9361 ret = xmlRelaxNGValidateDefinition(ctxt,
9362 partitions->groups[0]->
9365 if (ctxt->state !=
NULL)
9366 ctxt->state->seq = xmlRelaxNGSkipIgnored(ctxt,
9370 ctxt->flags = oldflags;
9381 xmlRngVErrMemory(ctxt,
"validating\n");
9386 if (lasts ==
NULL) {
9387 xmlRngVErrMemory(ctxt,
"validating\n");
9396 cur = ctxt->state->seq;
9397 cur = xmlRelaxNGSkipIgnored(ctxt,
cur);
9400 ctxt->state->seq =
cur;
9401 if ((partitions->triage !=
NULL) &&
9402 (partitions->flags & IS_DETERMINIST)) {
9431 if (partitions->flags & IS_NEEDCHECK) {
9432 group = partitions->groups[
i];
9433 if (!xmlRelaxNGNodeMatchesList(
cur,
group->defs))
9438 for (
i = 0;
i < nbgroups;
i++) {
9439 group = partitions->groups[
i];
9442 if (xmlRelaxNGNodeMatchesList(
cur,
group->defs))
9449 if (
i >= nbgroups) {
9452 if (lasts[
i] !=
NULL) {
9453 lasts[
i]->next =
cur;
9460 lastchg =
cur->next;
9463 cur = xmlRelaxNGSkipIgnored(ctxt,
cur->next);
9466 VALID_ERR(XML_RELAXNG_ERR_INTERSEQ);
9471 oldstate = ctxt->state;
9472 for (
i = 0;
i < nbgroups;
i++) {
9473 ctxt->state = xmlRelaxNGCopyValidState(ctxt, oldstate);
9474 if (ctxt->state ==
NULL) {
9478 group = partitions->groups[
i];
9479 if (lasts[
i] !=
NULL) {
9480 last = lasts[
i]->next;
9481 lasts[
i]->next =
NULL;
9483 ctxt->state->seq =
list[
i];
9484 ret = xmlRelaxNGValidateDefinition(ctxt,
group->rule);
9487 if (ctxt->state !=
NULL) {
9488 cur = ctxt->state->seq;
9489 cur = xmlRelaxNGSkipIgnored(ctxt,
cur);
9490 xmlRelaxNGFreeValidState(ctxt, oldstate);
9491 oldstate = ctxt->state;
9501 && (
define->parent->type != XML_RELAXNG_DEF
9503 (
const xmlChar *)
"open-name-class"))) {
9504 VALID_ERR2(XML_RELAXNG_ERR_INTEREXTRA,
cur->name);
9506 ctxt->state = oldstate;
9509 }
else if (ctxt->states !=
NULL) {
9519 for (
j = 0;
j < ctxt->states->nbState;
j++) {
9520 cur = ctxt->states->tabState[
j]->seq;
9521 cur = xmlRelaxNGSkipIgnored(ctxt,
cur);
9524 lowattr = ctxt->states->tabState[
j]->nbAttrLeft;
9528 if (ctxt->states->tabState[
j]->nbAttrLeft <= lowattr) {
9530 lowattr = ctxt->states->tabState[
j]->nbAttrLeft;
9535 }
else if (found == 0) {
9536 if (lowattr == -1) {
9537 lowattr = ctxt->states->tabState[
j]->nbAttrLeft;
9540 if (ctxt->states->tabState[
j]->nbAttrLeft <= lowattr) {
9542 lowattr = ctxt->states->tabState[
j]->nbAttrLeft;
9550 if (ctxt->states->nbState > 0) {
9551 xmlRelaxNGFreeValidState(ctxt, oldstate);
9553 oldstate = ctxt->states->tabState[best];
9554 ctxt->states->tabState[best] =
NULL;
9557 ctxt->states->tabState[ctxt->states->nbState - 1];
9558 ctxt->states->tabState[ctxt->states->nbState - 1] =
NULL;
9559 ctxt->states->nbState--;
9562 for (
j = 0;
j < ctxt->states->nbState ;
j++) {
9563 xmlRelaxNGFreeValidState(ctxt, ctxt->states->tabState[
j]);
9565 xmlRelaxNGFreeStates(ctxt, ctxt->states);
9566 ctxt->states =
NULL;
9569 VALID_ERR2(XML_RELAXNG_ERR_INTEREXTRA,
9572 VALID_ERR2(XML_RELAXNG_ERR_INTEREXTRA,
cur->name);
9575 ctxt->state = oldstate;
9582 if (lasts[
i] !=
NULL) {
9583 lasts[
i]->next =
last;
9586 if (ctxt->state !=
NULL)
9587 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
9588 ctxt->state = oldstate;
9589 ctxt->state->seq = lastelem;
9591 VALID_ERR(XML_RELAXNG_ERR_INTERSEQ);
9597 ctxt->flags = oldflags;
9609 if (ctxt->errNr > errNr)
9610 xmlRelaxNGPopErrors(ctxt, errNr);
9628xmlRelaxNGValidateDefinitionList(xmlRelaxNGValidCtxtPtr ctxt,
9635 VALID_ERR2(XML_RELAXNG_ERR_INTERNAL,
9640 if ((ctxt->state !=
NULL) || (ctxt->states !=
NULL)) {
9641 res = xmlRelaxNGValidateDefinition(ctxt,
defines);
9645 VALID_ERR(XML_RELAXNG_ERR_NOSTATE);
9667xmlRelaxNGElementMatch(xmlRelaxNGValidCtxtPtr ctxt,
9670 int ret = 0, oldflags = 0;
9680 VALID_ERR2(XML_RELAXNG_ERR_ELEMNONS,
elem->name);
9683 VALID_ERR3(XML_RELAXNG_ERR_ELEMWRONGNS,
9689 VALID_ERR2(XML_RELAXNG_ERR_ELEMEXTRANS,
elem->name);
9692 VALID_ERR2(XML_RELAXNG_ERR_ELEMEXTRANS,
define->
name);
9700 if (
define->type == XML_RELAXNG_EXCEPT) {
9701 xmlRelaxNGDefinePtr
list;
9704 oldflags = ctxt->flags;
9705 ctxt->flags |= FLAGS_IGNORABLE;
9713 ctxt->flags = oldflags;
9718 ctxt->flags = oldflags;
9725 ctxt->flags = oldflags;
9727 }
else if (
define->type == XML_RELAXNG_CHOICE) {
9728 xmlRelaxNGDefinePtr
list;
9731 oldflags = ctxt->flags;
9732 ctxt->flags |= FLAGS_IGNORABLE;
9740 ctxt->flags = oldflags;
9745 ctxt->flags = oldflags;
9752 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9753 xmlRelaxNGDumpValidError(ctxt);
9755 if (ctxt->errNr > 0)
9756 xmlRelaxNGPopErrors(ctxt, 0);
9761 ctxt->flags = oldflags;
9781xmlRelaxNGBestState(xmlRelaxNGValidCtxtPtr ctxt)
9783 xmlRelaxNGValidStatePtr
state;
9786 int value = 1000000;
9788 if ((ctxt ==
NULL) || (ctxt->states ==
NULL) ||
9789 (ctxt->states->nbState <= 0))
9792 for (
i = 0;
i < ctxt->states->nbState;
i++) {
9793 state = ctxt->states->tabState[
i];
9797 if ((best == -1) || (
value > 100000)) {
9802 tmp =
state->nbAttrLeft;
9803 if ((best == -1) || (
value > tmp)) {
9820xmlRelaxNGLogBestError(xmlRelaxNGValidCtxtPtr ctxt)
9824 if ((ctxt ==
NULL) || (ctxt->states ==
NULL) ||
9825 (ctxt->states->nbState <= 0))
9828 best = xmlRelaxNGBestState(ctxt);
9829 if ((best >= 0) && (best < ctxt->states->nbState)) {
9830 ctxt->state = ctxt->states->tabState[best];
9832 xmlRelaxNGValidateElementEnd(ctxt, 1);
9848xmlRelaxNGValidateElementEnd(xmlRelaxNGValidCtxtPtr ctxt,
int dolog)
9851 xmlRelaxNGValidStatePtr
state;
9853 state = ctxt->state;
9855 state->seq = xmlRelaxNGSkipIgnored(ctxt,
state->seq);
9858 VALID_ERR3(XML_RELAXNG_ERR_EXTRACONTENT,
9864 for (
i = 0;
i <
state->nbAttrs;
i++) {
9867 VALID_ERR3(XML_RELAXNG_ERR_INVALIDATTR,
9886xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt,
9887 xmlRelaxNGDefinePtr
define)
9890 int ret = 0,
i, tmp, oldflags, errNr;
9891 xmlRelaxNGValidStatePtr oldstate =
NULL,
state;
9894 VALID_ERR(XML_RELAXNG_ERR_NODEFINE);
9898 if (ctxt->state !=
NULL) {
9899 node = ctxt->state->seq;
9904 for (
i = 0;
i < ctxt->depth;
i++)
9907 "Start validating %s ", xmlRelaxNGDefName(
define));
9917 case XML_RELAXNG_EMPTY:
9920 case XML_RELAXNG_NOT_ALLOWED:
9923 case XML_RELAXNG_TEXT:
9930 ctxt->state->seq =
node;
9932 case XML_RELAXNG_ELEMENT:
9933 errNr = ctxt->errNr;
9934 node = xmlRelaxNGSkipIgnored(ctxt,
node);
9936 VALID_ERR2(XML_RELAXNG_ERR_NOELEM,
define->
name);
9938 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9939 xmlRelaxNGDumpValidError(ctxt);
9943 VALID_ERR(XML_RELAXNG_ERR_NOTELEM);
9945 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9946 xmlRelaxNGDumpValidError(ctxt);
9954 ctxt->state->seq = xmlRelaxNGSkipIgnored(ctxt,
node->
next);
9955 if (ctxt->errNr > errNr)
9956 xmlRelaxNGPopErrors(ctxt, errNr);
9957 if (ctxt->errNr != 0) {
9958 while ((ctxt->err !=
NULL) &&
9959 (((ctxt->err->err == XML_RELAXNG_ERR_ELEMNAME)
9963 XML_RELAXNG_ERR_ELEMEXTRANS)
9965 || (ctxt->err->err == XML_RELAXNG_ERR_NOELEM)
9966 || (ctxt->err->err ==
9967 XML_RELAXNG_ERR_NOTELEM)))
9968 xmlRelaxNGValidErrorPop(ctxt);
9976 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
9977 xmlRelaxNGDumpValidError(ctxt);
9981 if (ctxt->errNr != 0) {
9982 if (ctxt->errNr > errNr)
9983 xmlRelaxNGPopErrors(ctxt, errNr);
9984 while ((ctxt->err !=
NULL) &&
9985 (((ctxt->err->err == XML_RELAXNG_ERR_ELEMNAME) &&
9987 ((ctxt->err->err == XML_RELAXNG_ERR_ELEMEXTRANS) &&
9989 (ctxt->err->err == XML_RELAXNG_ERR_NOELEM) ||
9990 (ctxt->err->err == XML_RELAXNG_ERR_NOTELEM)))
9991 xmlRelaxNGValidErrorPop(ctxt);
9993 errNr = ctxt->errNr;
9995 oldflags = ctxt->flags;
9996 if (ctxt->flags & FLAGS_MIXED_CONTENT) {
9997 ctxt->flags -= FLAGS_MIXED_CONTENT;
9999 state = xmlRelaxNGNewValidState(ctxt,
node);
10002 if ((ctxt->flags & FLAGS_IGNORABLE) == 0)
10003 xmlRelaxNGDumpValidError(ctxt);
10007 oldstate = ctxt->state;
10008 ctxt->state =
state;
10010 tmp = xmlRelaxNGValidateAttributeList(ctxt,
define->attrs);
10013 VALID_ERR2(XML_RELAXNG_ERR_ATTRVALID,
node->name);
10017 xmlRelaxNGValidStatePtr nstate, tmpstate = ctxt->state;
10018 xmlRelaxNGStatesPtr tmpstates = ctxt->states;
10021 nstate = xmlRelaxNGNewValidState(ctxt,
node);
10022 ctxt->state = nstate;
10023 ctxt->states =
NULL;
10025 tmp = xmlRelaxNGValidateCompiledContent(ctxt,
10028 nseq = ctxt->state->seq;
10029 ctxt->state = tmpstate;
10030 ctxt->states = tmpstates;
10031 xmlRelaxNGFreeValidState(ctxt, nstate);
10033#ifdef DEBUG_COMPILE
10035 "Validating content of '%s' : %d\n",
10041 if (ctxt->states !=
NULL) {
10044 for (
i = 0;
i < ctxt->states->nbState;
i++) {
10045 state = ctxt->states->tabState[
i];
10046 ctxt->state =
state;
10047 ctxt->state->seq = nseq;
10049 if (xmlRelaxNGValidateElementEnd(ctxt, 0) == 0) {
10058 ctxt->flags |= FLAGS_IGNORABLE;
10059 xmlRelaxNGLogBestError(ctxt);
10061 for (
i = 0;
i < ctxt->states->nbState;
i++) {
10062 xmlRelaxNGFreeValidState(ctxt,
10066 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10067 ctxt->flags = oldflags;
10068 ctxt->states =
NULL;
10069 if ((
ret == 0) && (tmp == -1))
10072 state = ctxt->state;
10073 if (ctxt->state !=
NULL)
10074 ctxt->state->seq = nseq;
10076 ret = xmlRelaxNGValidateElementEnd(ctxt, 1);
10077 xmlRelaxNGFreeValidState(ctxt,
state);
10081 tmp = xmlRelaxNGValidateDefinitionList(ctxt,
10086 if (ctxt->state ==
NULL) {
10087 ctxt->state = oldstate;
10088 VALID_ERR2(XML_RELAXNG_ERR_CONTENTVALID,
10090 ctxt->state =
NULL;
10092 VALID_ERR2(XML_RELAXNG_ERR_CONTENTVALID,
10098 if (ctxt->states !=
NULL) {
10101 for (
i = 0;
i < ctxt->states->nbState;
i++) {
10102 state = ctxt->states->tabState[
i];
10103 ctxt->state =
state;
10105 if (xmlRelaxNGValidateElementEnd(ctxt, 0) == 0) {
10114 ctxt->flags |= FLAGS_IGNORABLE;
10115 xmlRelaxNGLogBestError(ctxt);
10117 for (
i = 0;
i < ctxt->states->nbState;
i++) {
10118 xmlRelaxNGFreeValidState(ctxt,
10119 ctxt->states->tabState[
i]);
10120 ctxt->states->tabState[
i] =
NULL;
10122 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10123 ctxt->flags = oldflags;
10124 ctxt->states =
NULL;
10125 if ((
ret == 0) && (tmp == -1))
10128 state = ctxt->state;
10130 ret = xmlRelaxNGValidateElementEnd(ctxt, 1);
10131 xmlRelaxNGFreeValidState(ctxt,
state);
10137 ctxt->flags = oldflags;
10138 ctxt->state = oldstate;
10139 if (oldstate !=
NULL)
10140 oldstate->seq = xmlRelaxNGSkipIgnored(ctxt,
node->
next);
10142 if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
10143 xmlRelaxNGDumpValidError(ctxt);
10151 if (ctxt->errNr > errNr)
10152 xmlRelaxNGPopErrors(ctxt, errNr);
10157 "xmlRelaxNGValidateDefinition(): validated %s : %d",
10159 if (oldstate ==
NULL)
10161 else if (oldstate->seq ==
NULL)
10165 oldstate->seq->name);
10168 oldstate->seq->name, oldstate->seq->type);
10171 case XML_RELAXNG_OPTIONAL:{
10172 errNr = ctxt->errNr;
10173 oldflags = ctxt->flags;
10174 ctxt->flags |= FLAGS_IGNORABLE;
10175 oldstate = xmlRelaxNGCopyValidState(ctxt, ctxt->state);
10177 xmlRelaxNGValidateDefinitionList(ctxt,
10180 if (ctxt->state !=
NULL)
10181 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10182 ctxt->state = oldstate;
10183 ctxt->flags = oldflags;
10185 if (ctxt->errNr > errNr)
10186 xmlRelaxNGPopErrors(ctxt, errNr);
10189 if (ctxt->states !=
NULL) {
10190 xmlRelaxNGAddStates(ctxt, ctxt->states, oldstate);
10192 ctxt->states = xmlRelaxNGNewStates(ctxt, 1);
10193 if (ctxt->states ==
NULL) {
10194 xmlRelaxNGFreeValidState(ctxt, oldstate);
10195 ctxt->flags = oldflags;
10197 if (ctxt->errNr > errNr)
10198 xmlRelaxNGPopErrors(ctxt, errNr);
10201 xmlRelaxNGAddStates(ctxt, ctxt->states, oldstate);
10202 xmlRelaxNGAddStates(ctxt, ctxt->states, ctxt->state);
10203 ctxt->state =
NULL;
10205 ctxt->flags = oldflags;
10207 if (ctxt->errNr > errNr)
10208 xmlRelaxNGPopErrors(ctxt, errNr);
10211 case XML_RELAXNG_ONEORMORE:
10212 errNr = ctxt->errNr;
10213 ret = xmlRelaxNGValidateDefinitionList(ctxt,
define->content);
10217 if (ctxt->errNr > errNr)
10218 xmlRelaxNGPopErrors(ctxt, errNr);
10220 case XML_RELAXNG_ZEROORMORE:{
10225 errNr = ctxt->errNr;
10226 res = xmlRelaxNGNewStates(ctxt, 1);
10234 if (ctxt->state !=
NULL) {
10235 xmlRelaxNGAddStates(ctxt,
res,
10236 xmlRelaxNGCopyValidState(ctxt,
10240 for (
j = 0;
j < ctxt->states->nbState;
j++) {
10241 xmlRelaxNGAddStates(ctxt,
res,
10242 xmlRelaxNGCopyValidState(ctxt,
10243 ctxt->states->tabState[
j]));
10246 oldflags = ctxt->flags;
10247 ctxt->flags |= FLAGS_IGNORABLE;
10252 if (ctxt->states !=
NULL) {
10253 states = ctxt->states;
10254 for (
i = 0;
i < states->nbState;
i++) {
10255 ctxt->state = states->tabState[
i];
10256 ctxt->states =
NULL;
10257 ret = xmlRelaxNGValidateDefinitionList(ctxt,
10261 if (ctxt->state !=
NULL) {
10262 tmp = xmlRelaxNGAddStates(ctxt,
res,
10264 ctxt->state =
NULL;
10267 }
else if (ctxt->states !=
NULL) {
10268 for (
j = 0;
j < ctxt->states->nbState;
10271 xmlRelaxNGAddStates(ctxt,
res,
10272 ctxt->states->tabState[
j]);
10276 xmlRelaxNGFreeStates(ctxt,
10278 ctxt->states =
NULL;
10281 if (ctxt->state !=
NULL) {
10282 xmlRelaxNGFreeValidState(ctxt,
10284 ctxt->state =
NULL;
10289 ret = xmlRelaxNGValidateDefinitionList(ctxt,
10293 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10294 ctxt->state =
NULL;
10297 if (ctxt->state !=
NULL) {
10298 tmp = xmlRelaxNGAddStates(ctxt,
res,
10300 ctxt->state =
NULL;
10303 }
else if (ctxt->states !=
NULL) {
10304 for (
j = 0;
j < ctxt->states->nbState;
j++) {
10305 tmp = xmlRelaxNGAddStates(ctxt,
res,
10306 ctxt->states->tabState[
j]);
10310 if (states ==
NULL) {
10311 states = ctxt->states;
10313 xmlRelaxNGFreeStates(ctxt,
10316 ctxt->states =
NULL;
10325 if (
res->nbState -
base == 1) {
10326 ctxt->state = xmlRelaxNGCopyValidState(ctxt,
10331 if (states ==
NULL) {
10332 xmlRelaxNGNewStates(ctxt,
10334 states = ctxt->states;
10335 if (states ==
NULL) {
10340 states->nbState = 0;
10342 xmlRelaxNGAddStates(ctxt, states,
10343 xmlRelaxNGCopyValidState
10344 (ctxt,
res->tabState[
i]));
10345 ctxt->states = states;
10349 if (states !=
NULL) {
10350 xmlRelaxNGFreeStates(ctxt, states);
10352 ctxt->states =
res;
10353 ctxt->flags = oldflags;
10358 if (ctxt->errNr > errNr)
10359 xmlRelaxNGPopErrors(ctxt, errNr);
10364 case XML_RELAXNG_CHOICE:{
10366 xmlRelaxNGStatesPtr states =
NULL;
10368 node = xmlRelaxNGSkipIgnored(ctxt,
node);
10370 errNr = ctxt->errNr;
10407 VALID_ERR2(XML_RELAXNG_ERR_ELEMWRONG,
node->name);
10410 ret = xmlRelaxNGValidateDefinition(ctxt,
list);
10417 oldflags = ctxt->flags;
10418 ctxt->flags |= FLAGS_IGNORABLE;
10421 oldstate = xmlRelaxNGCopyValidState(ctxt, ctxt->state);
10422 ret = xmlRelaxNGValidateDefinition(ctxt,
list);
10424 if (states ==
NULL) {
10425 states = xmlRelaxNGNewStates(ctxt, 1);
10427 if (ctxt->state !=
NULL) {
10428 xmlRelaxNGAddStates(ctxt, states, ctxt->state);
10429 }
else if (ctxt->states !=
NULL) {
10430 for (
i = 0;
i < ctxt->states->nbState;
i++) {
10431 xmlRelaxNGAddStates(ctxt, states,
10435 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10436 ctxt->states =
NULL;
10439 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10441 ctxt->state = oldstate;
10444 if (states !=
NULL) {
10445 xmlRelaxNGFreeValidState(ctxt, oldstate);
10446 ctxt->states = states;
10447 ctxt->state =
NULL;
10450 ctxt->states =
NULL;
10452 ctxt->flags = oldflags;
10454 if ((ctxt->flags & FLAGS_IGNORABLE) == 0) {
10455 xmlRelaxNGDumpValidError(ctxt);
10458 if (ctxt->errNr > errNr)
10459 xmlRelaxNGPopErrors(ctxt, errNr);
10463 case XML_RELAXNG_DEF:
10464 case XML_RELAXNG_GROUP:
10465 ret = xmlRelaxNGValidateDefinitionList(ctxt,
define->content);
10467 case XML_RELAXNG_INTERLEAVE:
10468 ret = xmlRelaxNGValidateInterleave(ctxt,
define);
10470 case XML_RELAXNG_ATTRIBUTE:
10471 ret = xmlRelaxNGValidateAttribute(ctxt,
define);
10473 case XML_RELAXNG_START:
10474 case XML_RELAXNG_NOOP:
10475 case XML_RELAXNG_REF:
10476 case XML_RELAXNG_EXTERNALREF:
10477 case XML_RELAXNG_PARENTREF:
10478 ret = xmlRelaxNGValidateDefinition(ctxt,
define->content);
10480 case XML_RELAXNG_DATATYPE:{
10487 VALID_ERR2(XML_RELAXNG_ERR_DATAELEM,
10488 node->parent->name);
10506 xmlRngVErrMemory(ctxt,
"validating\n");
10514 VALID_ERR2(XML_RELAXNG_ERR_DATATYPE,
define->
name);
10515 }
else if (
ret == 0) {
10516 ctxt->state->seq =
NULL;
10522 case XML_RELAXNG_VALUE:{
10530 VALID_ERR2(XML_RELAXNG_ERR_VALELEM,
10531 node->parent->name);
10549 xmlRngVErrMemory(ctxt,
"validating\n");
10554 oldvalue = ctxt->state->value;
10555 ctxt->state->value =
content;
10556 ret = xmlRelaxNGValidateValue(ctxt,
define);
10557 ctxt->state->value = oldvalue;
10559 VALID_ERR2(XML_RELAXNG_ERR_VALUE,
define->
name);
10560 }
else if (
ret == 0) {
10561 ctxt->state->seq =
NULL;
10567 case XML_RELAXNG_LIST:{
10570 xmlChar *oldvalue, *oldendvalue;
10581 VALID_ERR2(XML_RELAXNG_ERR_LISTELEM,
10582 node->parent->name);
10600 xmlRngVErrMemory(ctxt,
"validating\n");
10606 oldvalue = ctxt->state->value;
10607 oldendvalue = ctxt->state->endvalue;
10608 ctxt->state->value =
content;
10610 ret = xmlRelaxNGValidateValue(ctxt,
define);
10611 ctxt->state->value = oldvalue;
10612 ctxt->state->endvalue = oldendvalue;
10614 VALID_ERR(XML_RELAXNG_ERR_LIST);
10622 case XML_RELAXNG_EXCEPT:
10623 case XML_RELAXNG_PARAM:
10629 for (
i = 0;
i < ctxt->depth;
i++)
10632 "Validating %s ", xmlRelaxNGDefName(
define));
10653xmlRelaxNGValidateDefinition(xmlRelaxNGValidCtxtPtr ctxt,
10654 xmlRelaxNGDefinePtr
define)
10656 xmlRelaxNGStatesPtr states,
res;
10657 int i,
j,
k,
ret, oldflags;
10662 if ((ctxt->state !=
NULL) && (ctxt->states !=
NULL)) {
10663 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10664 ctxt->state =
NULL;
10667 if ((ctxt->states ==
NULL) || (ctxt->states->nbState == 1)) {
10668 if (ctxt->states !=
NULL) {
10669 ctxt->state = ctxt->states->tabState[0];
10670 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10671 ctxt->states =
NULL;
10673 ret = xmlRelaxNGValidateState(ctxt,
define);
10674 if ((ctxt->state !=
NULL) && (ctxt->states !=
NULL)) {
10675 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10676 ctxt->state =
NULL;
10678 if ((ctxt->states !=
NULL) && (ctxt->states->nbState == 1)) {
10679 ctxt->state = ctxt->states->tabState[0];
10680 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10681 ctxt->states =
NULL;
10686 states = ctxt->states;
10687 ctxt->states =
NULL;
10690 oldflags = ctxt->flags;
10691 ctxt->flags |= FLAGS_IGNORABLE;
10692 for (
i = 0;
i < states->nbState;
i++) {
10693 ctxt->state = states->tabState[
i];
10694 ctxt->states =
NULL;
10695 ret = xmlRelaxNGValidateState(ctxt,
define);
10699 if ((ctxt->state !=
NULL) && (ctxt->states !=
NULL)) {
10700 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10701 ctxt->state =
NULL;
10704 if (ctxt->states ==
NULL) {
10707 xmlRelaxNGAddStates(ctxt,
res, ctxt->state);
10708 ctxt->state =
NULL;
10711 states->tabState[
j++] = ctxt->state;
10712 ctxt->state =
NULL;
10717 res = ctxt->states;
10718 ctxt->states =
NULL;
10719 for (
k = 0;
k <
j;
k++)
10720 xmlRelaxNGAddStates(ctxt,
res,
10721 states->tabState[
k]);
10724 for (
k = 0;
k < ctxt->states->nbState;
k++)
10725 xmlRelaxNGAddStates(ctxt,
res,
10726 ctxt->states->tabState[
k]);
10727 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10728 ctxt->states =
NULL;
10732 if (ctxt->state !=
NULL) {
10733 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10734 ctxt->state =
NULL;
10735 }
else if (ctxt->states !=
NULL) {
10736 for (
k = 0;
k < ctxt->states->nbState;
k++)
10737 xmlRelaxNGFreeValidState(ctxt,
10738 ctxt->states->tabState[
k]);
10739 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10740 ctxt->states =
NULL;
10744 ctxt->flags = oldflags;
10746 xmlRelaxNGFreeStates(ctxt, states);
10747 ctxt->states =
res;
10749 }
else if (
j > 1) {
10750 states->nbState =
j;
10751 ctxt->states = states;
10753 }
else if (
j == 1) {
10754 ctxt->state = states->tabState[0];
10755 xmlRelaxNGFreeStates(ctxt, states);
10759 xmlRelaxNGFreeStates(ctxt, states);
10760 if (ctxt->states !=
NULL) {
10761 xmlRelaxNGFreeStates(ctxt, ctxt->states);
10762 ctxt->states =
NULL;
10765 if ((ctxt->state !=
NULL) && (ctxt->states !=
NULL)) {
10766 TODO xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10767 ctxt->state =
NULL;
10782xmlRelaxNGValidateDocument(xmlRelaxNGValidCtxtPtr ctxt,
xmlDocPtr doc)
10786 xmlRelaxNGGrammarPtr grammar;
10787 xmlRelaxNGValidStatePtr
state;
10790 if ((ctxt ==
NULL) || (ctxt->schema ==
NULL) || (doc ==
NULL))
10793 ctxt->errNo = XML_RELAXNG_OK;
10795 grammar =
schema->topgrammar;
10796 if (grammar ==
NULL) {
10797 VALID_ERR(XML_RELAXNG_ERR_NOGRAMMAR);
10800 state = xmlRelaxNGNewValidState(ctxt,
NULL);
10801 ctxt->state =
state;
10802 ret = xmlRelaxNGValidateDefinition(ctxt, grammar->start);
10804 state = ctxt->state;
10806 node = xmlRelaxNGSkipIgnored(ctxt,
node);
10809 VALID_ERR(XML_RELAXNG_ERR_EXTRADATA);
10813 }
else if (ctxt->states !=
NULL) {
10817 for (
i = 0;
i < ctxt->states->nbState;
i++) {
10818 state = ctxt->states->tabState[
i];
10820 node = xmlRelaxNGSkipIgnored(ctxt,
node);
10823 xmlRelaxNGFreeValidState(ctxt,
state);
10827 VALID_ERR(XML_RELAXNG_ERR_EXTRADATA);
10832 if (ctxt->state !=
NULL) {
10833 xmlRelaxNGFreeValidState(ctxt, ctxt->state);
10834 ctxt->state =
NULL;
10837 xmlRelaxNGDumpValidError(ctxt);
10839 else if (ctxt->errNr != 0) {
10840 ctxt->error(ctxt->userData,
10841 "%d Extra error messages left on stack !\n",
10843 xmlRelaxNGDumpValidError(ctxt);
10846#ifdef LIBXML_VALID_ENABLED
10847 if (ctxt->idref == 1) {
10852 vctxt.error = ctxt->error;
10853 vctxt.warning = ctxt->warning;
10854 vctxt.userData = ctxt->userData;
10856 if (xmlValidateDocumentFinal(&vctxt, doc) != 1)
10860 if ((
ret == 0) && (ctxt->errNo != XML_RELAXNG_OK))
10934xmlRelaxNGValidCtxtPtr
10935xmlRelaxNGNewValidCtxt(xmlRelaxNGPtr
schema)
10937 xmlRelaxNGValidCtxtPtr
ret;
10939 ret = (xmlRelaxNGValidCtxtPtr)
xmlMalloc(
sizeof(xmlRelaxNGValidCtxt));
10941 xmlRngVErrMemory(
NULL,
"building context\n");
10944 memset(
ret, 0,
sizeof(xmlRelaxNGValidCtxt));
10957 ret->errNo = XML_RELAXNG_OK;
10968xmlRelaxNGFreeValidCtxt(xmlRelaxNGValidCtxtPtr ctxt)
10974 if (ctxt->states !=
NULL)
10975 xmlRelaxNGFreeStates(
NULL, ctxt->states);
10976 if (ctxt->freeState !=
NULL) {
10977 for (
k = 0;
k < ctxt->freeState->nbState;
k++) {
10978 xmlRelaxNGFreeValidState(
NULL, ctxt->freeState->tabState[
k]);
10980 xmlRelaxNGFreeStates(
NULL, ctxt->freeState);
10982 if (ctxt->freeStates !=
NULL) {
10983 for (
k = 0;
k < ctxt->freeStatesNr;
k++) {
10984 xmlRelaxNGFreeStates(
NULL, ctxt->freeStates[
k]);
10988 if (ctxt->errTab !=
NULL)
10990 if (ctxt->elemTab !=
NULL) {
10991 xmlRegExecCtxtPtr exec;
10993 exec = xmlRelaxNGElemPop(ctxt);
10994 while (exec !=
NULL) {
10995 xmlRegFreeExecCtxt(exec);
10996 exec = xmlRelaxNGElemPop(ctxt);
11013xmlRelaxNGSetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
11014 xmlRelaxNGValidityErrorFunc
err,
11015 xmlRelaxNGValidityWarningFunc
warn,
void *
ctx)
11020 ctxt->warning =
warn;
11021 ctxt->userData =
ctx;
11022 ctxt->serror =
NULL;
11034xmlRelaxNGSetValidStructuredErrors(xmlRelaxNGValidCtxtPtr ctxt,
11039 ctxt->serror = serror;
11040 ctxt->error =
NULL;
11041 ctxt->warning =
NULL;
11042 ctxt->userData =
ctx;
11057xmlRelaxNGGetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
11058 xmlRelaxNGValidityErrorFunc *
err,
11059 xmlRelaxNGValidityWarningFunc *
warn,
void **
ctx)
11064 *
err = ctxt->error;
11066 *
warn = ctxt->warning;
11068 *
ctx = ctxt->userData;
11083xmlRelaxNGValidateDoc(xmlRelaxNGValidCtxtPtr ctxt,
xmlDocPtr doc)
11087 if ((ctxt ==
NULL) || (doc ==
NULL))
11092 ret = xmlRelaxNGValidateDocument(ctxt, doc);
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
static struct loaded_include * includes
static SIZE_T const char const D3D_SHADER_MACRO * defines
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
#define check(expected, result)
__kernel_ptrdiff_t ptrdiff_t
GLint GLint GLsizei GLsizei GLsizei depth
GLuint GLuint GLsizei GLenum type
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLuint GLuint GLuint GLuint arg1
GLdouble GLdouble GLdouble GLdouble top
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
XMLPUBFUN xmlChar *XMLCALL xmlEscapeFormatString(xmlChar **msg)
#define memcpy(s1, s2, n)
static unsigned __int64 next
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
XMLPUBVAR xmlMallocFunc xmlMalloc
XMLPUBVAR xmlFreeFunc xmlFree
XMLPUBVAR void * xmlGenericErrorContext
XMLPUBVAR xmlReallocFunc xmlRealloc
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
XMLPUBFUN int XMLCALL xmlHashAddEntry2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2, void *userdata)
XMLPUBFUN void XMLCALL xmlHashFree(xmlHashTablePtr table, xmlHashDeallocator f)
xmlHashTable * xmlHashTablePtr
XMLPUBFUN void *XMLCALL xmlHashLookup(xmlHashTablePtr table, const xmlChar *name)
XMLPUBFUN xmlHashTablePtr XMLCALL xmlHashCreate(int size)
XMLPUBFUN int XMLCALL xmlHashAddEntry(xmlHashTablePtr table, const xmlChar *name, void *userdata)
XMLPUBFUN void *XMLCALL xmlHashLookup2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2)
XMLPUBFUN void XMLCALL xmlHashScan(xmlHashTablePtr table, xmlHashScanner f, void *data)
XMLPUBFUN xmlDocPtr XMLCALL xmlReadMemory(const char *buffer, int size, const char *URL, const char *encoding, int options)
XMLPUBFUN xmlDocPtr XMLCALL xmlReadFile(const char *URL, const char *encoding, int options)
XMLPUBFUN xmlNodePtr XMLCALL xmlAddChild(xmlNodePtr parent, xmlNodePtr cur)
XMLPUBFUN xmlChar *XMLCALL xmlNodeGetContent(const xmlNode *cur)
XMLPUBFUN xmlNodePtr XMLCALL xmlDocGetRootElement(const xmlDoc *doc)
XMLPUBFUN void XMLCALL xmlFreeDoc(xmlDocPtr cur)
XMLPUBFUN xmlAttrPtr XMLCALL xmlHasProp(const xmlNode *node, const xmlChar *name)
XMLPUBFUN xmlChar *XMLCALL xmlGetProp(const xmlNode *node, const xmlChar *name)
XMLPUBFUN xmlNsPtr XMLCALL xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace)
XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns, const xmlChar *name, const xmlChar *content)
XMLPUBFUN xmlNodePtr XMLCALL xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem)
XMLPUBFUN void XMLCALL xmlUnlinkNode(xmlNodePtr cur)
XMLPUBFUN xmlChar *XMLCALL xmlNodeGetBase(const xmlDoc *doc, const xmlNode *cur)
XMLPUBFUN void XMLCALL xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content)
XMLPUBFUN int XMLCALL xmlIsBlankNode(const xmlNode *node)
XMLPUBFUN xmlNodePtr XMLCALL xmlNewDocText(const xmlDoc *doc, const xmlChar *content)
XMLPUBFUN void XMLCALL xmlFreeNode(xmlNodePtr cur)
XMLPUBFUN xmlChar *XMLCALL xmlSplitQName2(const xmlChar *name, xmlChar **prefix)
XMLPUBFUN xmlChar *XMLCALL xmlNodeListGetString(xmlDocPtr doc, const xmlNode *list, int inLine)
struct _xmlNode * children
struct _xmlNode * children
XMLPUBFUN xmlURIPtr XMLCALL xmlParseURI(const char *str)
XMLPUBFUN xmlChar *XMLCALL xmlURIEscapeStr(const xmlChar *str, const xmlChar *list)
XMLPUBFUN void XMLCALL xmlFreeURI(xmlURIPtr uri)
XMLPUBFUN xmlChar *XMLCALL xmlBuildURI(const xmlChar *URI, const xmlChar *base)
typedeftypedef void(XMLCDECL *) typedef void(XMLCDECL *) struct _xmlValidCtx xmlValidCtxt)
#define success(from, fromstr, to, tostr)
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
void(XMLCDECL * xmlGenericErrorFunc)(void *ctx, const char *msg,...) LIBXML_ATTR_FORMAT(2
void(XMLCDECL *) typedef void(XMLCALL * xmlStructuredErrorFunc)(void *userData, xmlErrorPtr error)
@ XML_RNGP_UNKNOWN_TYPE_LIB
@ XML_RNGP_ELEM_TEXT_CONFLICT
@ XML_RNGP_EXCEPT_NO_CONTENT
@ XML_RNGP_PARAM_FORBIDDEN
@ XML_RNGP_GROUP_ATTR_CONFLICT
@ XML_RNGP_PAT_ONEMORE_INTERLEAVE_ATTR
@ XML_RNGP_PAT_START_DATA
@ XML_RNGP_PAT_START_GROUP
@ XML_RNGP_PAT_DATA_EXCEPT_ONEMORE
@ XML_RNGP_EMPTY_CONSTRUCT
@ XML_RNGP_PARENTREF_CREATE_FAILED
@ XML_RNGP_ELEM_CONTENT_ERROR
@ XML_RNGP_DEFINE_NAME_MISSING
@ XML_RNGP_TEXT_HAS_CHILD
@ XML_RNGP_FORBIDDEN_ATTRIBUTE
@ XML_RNGP_PARENTREF_NO_PARENT
@ XML_RNGP_PAT_DATA_EXCEPT_ATTR
@ XML_RNGP_EXTERNALREF_RECURSE
@ XML_RNGP_PAT_ONEMORE_GROUP_ATTR
@ XML_RNGP_EXCEPT_MISSING
@ XML_RNGP_START_CHOICE_AND_INTERLEAVE
@ XML_RNGP_URI_NOT_ABSOLUTE
@ XML_RNGP_GRAMMAR_NO_START
@ XML_RNGP_ELEMENT_CONTENT
@ XML_RNGP_NOTALLOWED_NOT_EMPTY
@ XML_RNGP_DEF_CHOICE_AND_INTERLEAVE
@ XML_RNGP_INCLUDE_RECURSE
@ XML_RNGP_EXTERNAL_REF_FAILURE
@ XML_RNGP_PAT_START_ATTR
@ XML_RNGP_ANYNAME_ATTR_ANCESTOR
@ XML_RNGP_ERROR_TYPE_LIB
@ XML_RNGP_ELEMENT_NO_CONTENT
@ XML_RNGP_PAT_START_EMPTY
@ XML_RNGP_PAT_DATA_EXCEPT_INTERLEAVE
@ XML_RNGP_PAT_START_VALUE
@ XML_RNGP_ELEM_CONTENT_EMPTY
@ XML_RNGP_EMPTY_NOT_EMPTY
@ XML_RNGP_PAT_DATA_EXCEPT_TEXT
@ XML_RNGP_ATTRIBUTE_NOOP
@ XML_RNGP_EXCEPT_MULTIPLE
@ XML_RNGP_DEFINE_MISSING
@ XML_RNGP_UNKNOWN_CONSTRUCT
@ XML_RNGP_PAT_DATA_EXCEPT_GROUP
@ XML_RNGP_REF_CREATE_FAILED
@ XML_RNGP_INCLUDE_FAILURE
@ XML_RNGP_PAT_NSNAME_EXCEPT_ANYNAME
@ XML_RNGP_REF_NAME_INVALID
@ XML_RNGP_EXTERNALREF_EMTPY
@ XML_RNGP_PAT_START_LIST
@ XML_RNGP_PAT_ANYNAME_EXCEPT_ANYNAME
@ XML_RNGP_PARENTREF_NAME_INVALID
@ XML_RNGP_ATTRIBUTE_CHILDREN
@ XML_RNGP_TYPE_NOT_FOUND
@ XML_RNGP_UNKNOWN_ATTRIBUTE
@ XML_RNGP_GRAMMAR_CONTENT
@ XML_RNGP_PREFIX_UNDEFINED
@ XML_RNGP_PAT_LIST_INTERLEAVE
@ XML_RNGP_PAT_DATA_EXCEPT_LIST
@ XML_RNGP_DEFINE_CREATE_FAILED
@ XML_RNGP_PARENTREF_NOT_EMPTY
@ XML_RNGP_ATTRIBUTE_EMPTY
@ XML_RNGP_PAT_DATA_EXCEPT_REF
@ XML_RNGP_PAT_NSNAME_EXCEPT_NSNAME
@ XML_RNGP_INTERLEAVE_NO_CONTENT
@ XML_RNGP_FOREIGN_ELEMENT
@ XML_RNGP_VALUE_NO_CONTENT
@ XML_RNGP_PAT_START_TEXT
@ XML_RNGP_CREATE_FAILURE
@ XML_RNGP_CHOICE_CONTENT
@ XML_RNGP_INTERLEAVE_ADD
@ XML_RNGP_PAT_DATA_EXCEPT_EMPTY
@ XML_RNGP_ATTRIBUTE_CONTENT
@ XML_RNGP_INTERLEAVE_CREATE_FAILED
@ XML_RNGP_INVALID_DEFINE_NAME
@ XML_RNGP_UNKNOWN_COMBINE
@ XML_RNGP_GRAMMAR_MISSING
@ XML_RNGP_PAT_DATA_EXCEPT_ELEM
@ XML_RNGP_PAT_START_ONEMORE
@ XML_RNGP_PARAM_NAME_MISSING
@ XML_RNGP_NSNAME_ATTR_ANCESTOR
@ XML_RNGP_PARENTREF_NO_NAME
XMLPUBFUN xmlChar *XMLCALL xmlStrcat(xmlChar *cur, const xmlChar *add)
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
XMLPUBFUN xmlChar *XMLCALL xmlCharStrdup(const char *cur)
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
#define LIBXML_ATTR_FORMAT(fmt, args)