26#ifdef LIBXML_SCHEMATRON_ENABLED
37#define SCHEMATRON_PARSE_OPTIONS XML_PARSE_NOENT
39#define SCT_OLD_NS BAD_CAST "http://www.ascc.net/xml/schematron"
41#define XML_SCHEMATRON_NS BAD_CAST "http://purl.oclc.org/dsdl/schematron"
44static const xmlChar *xmlSchematronNs = XML_SCHEMATRON_NS;
45static const xmlChar *xmlOldSchematronNs = SCT_OLD_NS;
47#define IS_SCHEMATRON(node, elem) \
48 ((node != NULL) && (node->type == XML_ELEMENT_NODE ) && \
49 (node->ns != NULL) && \
50 (xmlStrEqual(node->name, (const xmlChar *) elem)) && \
51 ((xmlStrEqual(node->ns->href, xmlSchematronNs)) || \
52 (xmlStrEqual(node->ns->href, xmlOldSchematronNs))))
54#define NEXT_SCHEMATRON(node) \
55 while (node != NULL) { \
56 if ((node->type == XML_ELEMENT_NODE ) && (node->ns != NULL) && \
57 ((xmlStrEqual(node->ns->href, xmlSchematronNs)) || \
58 (xmlStrEqual(node->ns->href, xmlOldSchematronNs)))) \
69 xmlGenericError(xmlGenericErrorContext, \
70 "Unimplemented block at %s:%d\n", \
74 XML_SCHEMATRON_ASSERT=1,
75 XML_SCHEMATRON_REPORT=2
76} xmlSchematronTestType;
83typedef struct _xmlSchematronLet xmlSchematronLet;
84typedef xmlSchematronLet *xmlSchematronLetPtr;
85struct _xmlSchematronLet {
86 xmlSchematronLetPtr
next;
88 xmlXPathCompExprPtr comp;
96typedef struct _xmlSchematronTest xmlSchematronTest;
97typedef xmlSchematronTest *xmlSchematronTestPtr;
98struct _xmlSchematronTest {
99 xmlSchematronTestPtr
next;
100 xmlSchematronTestType
type;
103 xmlXPathCompExprPtr comp;
112typedef struct _xmlSchematronRule xmlSchematronRule;
113typedef xmlSchematronRule *xmlSchematronRulePtr;
114struct _xmlSchematronRule {
115 xmlSchematronRulePtr
next;
116 xmlSchematronRulePtr patnext;
119 xmlSchematronTestPtr
tests;
122 xmlSchematronLetPtr lets;
130typedef struct _xmlSchematronPattern xmlSchematronPattern;
131typedef xmlSchematronPattern *xmlSchematronPatternPtr;
132struct _xmlSchematronPattern {
133 xmlSchematronPatternPtr
next;
134 xmlSchematronRulePtr rules;
143struct _xmlSchematron {
157 xmlSchematronPatternPtr patterns;
158 xmlSchematronRulePtr rules;
169struct _xmlSchematronValidCtxt {
178 xmlXPathContextPtr xctxt;
182#ifdef LIBXML_OUTPUT_ENABLED
183 xmlOutputWriteCallback iowrite;
184 xmlOutputCloseCallback ioclose;
190 xmlSchematronValidityErrorFunc
error;
191 xmlSchematronValidityWarningFunc
warning;
195struct _xmlSchematronParserCtxt {
207 xmlXPathContextPtr xctxt;
220 xmlSchematronValidityErrorFunc
error;
221 xmlSchematronValidityWarningFunc
warning;
225#define XML_STRON_CTXT_PARSER 1
226#define XML_STRON_CTXT_VALIDATOR 2
242xmlSchematronPErrMemory(xmlSchematronParserCtxtPtr ctxt,
272 channel = ctxt->error;
273 data = ctxt->userData;
274 schannel = ctxt->serror;
278 (
const char *) str1, (
const char *) str2,
NULL, 0, 0,
290xmlSchematronVErrMemory(xmlSchematronValidCtxtPtr ctxt,
320static xmlSchematronTestPtr
321xmlSchematronAddTest(xmlSchematronParserCtxtPtr ctxt,
322 xmlSchematronTestType
type,
323 xmlSchematronRulePtr rule,
326 xmlSchematronTestPtr
ret;
327 xmlXPathCompExprPtr comp;
336 comp = xmlXPathCtxtCompile(ctxt->xctxt,
test);
338 xmlSchematronPErr(ctxt,
node,
340 "Failed to compile test expression %s",
345 ret = (xmlSchematronTestPtr)
xmlMalloc(
sizeof(xmlSchematronTest));
347 xmlSchematronPErrMemory(ctxt,
"allocating schema test",
node);
350 memset(
ret, 0,
sizeof(xmlSchematronTest));
357 if (rule->tests ==
NULL) {
360 xmlSchematronTestPtr prev = rule->tests;
362 while (prev->next !=
NULL)
376xmlSchematronFreeTests(xmlSchematronTestPtr
tests) {
377 xmlSchematronTestPtr
next;
384 xmlXPathFreeCompExpr(
tests->comp);
399xmlSchematronFreeLets(xmlSchematronLetPtr lets) {
400 xmlSchematronLetPtr
next;
402 while (lets !=
NULL) {
404 if (lets->name !=
NULL)
406 if (lets->comp !=
NULL)
407 xmlXPathFreeCompExpr(lets->comp);
425static xmlSchematronRulePtr
426xmlSchematronAddRule(xmlSchematronParserCtxtPtr ctxt, xmlSchematronPtr
schema,
430 xmlSchematronRulePtr
ret;
440 pattern = xmlPatterncompile(
context, ctxt->dict, XML_PATTERN_XPATH,
443 xmlSchematronPErr(ctxt,
node,
445 "Failed to compile context expression %s",
449 ret = (xmlSchematronRulePtr)
xmlMalloc(
sizeof(xmlSchematronRule));
451 xmlSchematronPErrMemory(ctxt,
"allocating schema rule",
node);
454 memset(
ret, 0,
sizeof(xmlSchematronRule));
464 xmlSchematronRulePtr prev =
schema->rules;
466 while (prev->next !=
NULL)
471 if (pat->rules ==
NULL) {
474 xmlSchematronRulePtr prev = pat->rules;
476 while (prev->patnext !=
NULL)
477 prev = prev->patnext;
490xmlSchematronFreeRules(xmlSchematronRulePtr rules) {
491 xmlSchematronRulePtr
next;
493 while (rules !=
NULL) {
496 xmlSchematronFreeTests(rules->tests);
497 if (rules->context !=
NULL)
500 xmlFreePattern(rules->pattern);
501 if (rules->report !=
NULL)
503 if (rules->lets !=
NULL)
504 xmlSchematronFreeLets(rules->lets);
521static xmlSchematronPatternPtr
522xmlSchematronAddPattern(xmlSchematronParserCtxtPtr ctxt,
525 xmlSchematronPatternPtr
ret;
530 ret = (xmlSchematronPatternPtr)
xmlMalloc(
sizeof(xmlSchematronPattern));
532 xmlSchematronPErrMemory(ctxt,
"allocating schema pattern",
node);
535 memset(
ret, 0,
sizeof(xmlSchematronPattern));
541 xmlSchematronPatternPtr prev =
schema->patterns;
543 while (prev->next !=
NULL)
557xmlSchematronFreePatterns(xmlSchematronPatternPtr patterns) {
558 xmlSchematronPatternPtr
next;
560 while (patterns !=
NULL) {
561 next = patterns->next;
562 if (patterns->name !=
NULL)
577static xmlSchematronPtr
578xmlSchematronNewSchematron(xmlSchematronParserCtxtPtr ctxt)
580 xmlSchematronPtr
ret;
582 ret = (xmlSchematronPtr)
xmlMalloc(
sizeof(xmlSchematron));
584 xmlSchematronPErrMemory(ctxt,
"allocating schema",
NULL);
588 ret->dict = ctxt->dict;
601xmlSchematronFree(xmlSchematronPtr
schema)
612 xmlSchematronFreeRules(
schema->rules);
613 xmlSchematronFreePatterns(
schema->patterns);
627xmlSchematronParserCtxtPtr
628xmlSchematronNewParserCtxt(
const char *URL)
630 xmlSchematronParserCtxtPtr
ret;
636 (xmlSchematronParserCtxtPtr)
637 xmlMalloc(
sizeof(xmlSchematronParserCtxt));
639 xmlSchematronPErrMemory(
NULL,
"allocating schema parser context",
643 memset(
ret, 0,
sizeof(xmlSchematronParserCtxt));
644 ret->type = XML_STRON_CTXT_PARSER;
648 ret->xctxt = xmlXPathNewContext(
NULL);
650 xmlSchematronPErrMemory(
NULL,
"allocating schema parser XPath context",
652 xmlSchematronFreeParserCtxt(
ret);
655 ret->xctxt->flags = XML_XPATH_CHECKNS;
669xmlSchematronParserCtxtPtr
670xmlSchematronNewMemParserCtxt(
const char *
buffer,
int size)
672 xmlSchematronParserCtxtPtr
ret;
678 (xmlSchematronParserCtxtPtr)
679 xmlMalloc(
sizeof(xmlSchematronParserCtxt));
681 xmlSchematronPErrMemory(
NULL,
"allocating schema parser context",
685 memset(
ret, 0,
sizeof(xmlSchematronParserCtxt));
689 ret->xctxt = xmlXPathNewContext(
NULL);
691 xmlSchematronPErrMemory(
NULL,
"allocating schema parser XPath context",
693 xmlSchematronFreeParserCtxt(
ret);
708xmlSchematronParserCtxtPtr
709xmlSchematronNewDocParserCtxt(
xmlDocPtr doc)
711 xmlSchematronParserCtxtPtr
ret;
717 (xmlSchematronParserCtxtPtr)
718 xmlMalloc(
sizeof(xmlSchematronParserCtxt));
720 xmlSchematronPErrMemory(
NULL,
"allocating schema parser context",
724 memset(
ret, 0,
sizeof(xmlSchematronParserCtxt));
729 ret->xctxt = xmlXPathNewContext(doc);
731 xmlSchematronPErrMemory(
NULL,
"allocating schema parser XPath context",
733 xmlSchematronFreeParserCtxt(
ret);
747xmlSchematronFreeParserCtxt(xmlSchematronParserCtxtPtr ctxt)
751 if (ctxt->doc !=
NULL && !ctxt->preserve)
753 if (ctxt->xctxt !=
NULL) {
754 xmlXPathFreeContext(ctxt->xctxt);
756 if (ctxt->namespaces !=
NULL)
757 xmlFree((
char **) ctxt->namespaces);
772xmlSchematronPushInclude(xmlSchematronParserCtxtPtr ctxt,
775 if (ctxt->includes ==
NULL) {
776 ctxt->maxIncludes = 10;
779 if (ctxt->includes ==
NULL) {
780 xmlSchematronPErrMemory(
NULL,
"allocating parser includes",
784 ctxt->nbIncludes = 0;
785 }
else if (ctxt->nbIncludes + 2 >= ctxt->maxIncludes) {
789 xmlRealloc(ctxt->includes, ctxt->maxIncludes * 4 *
792 xmlSchematronPErrMemory(
NULL,
"allocating parser includes",
796 ctxt->includes = tmp;
797 ctxt->maxIncludes *= 2;
799 ctxt->includes[2 * ctxt->nbIncludes] =
cur;
800 ctxt->includes[2 * ctxt->nbIncludes + 1] = (
xmlNodePtr) doc;
814xmlSchematronPopInclude(xmlSchematronParserCtxtPtr ctxt)
819 if (ctxt->nbIncludes <= 0)
822 doc = (
xmlDocPtr) ctxt->includes[2 * ctxt->nbIncludes + 1];
823 ret = ctxt->includes[2 * ctxt->nbIncludes];
828 return(xmlSchematronPopInclude(ctxt));
842xmlSchematronAddNamespace(xmlSchematronParserCtxtPtr ctxt,
845 if (ctxt->namespaces ==
NULL) {
846 ctxt->maxNamespaces = 10;
847 ctxt->namespaces = (
const xmlChar **)
849 if (ctxt->namespaces ==
NULL) {
850 xmlSchematronPErrMemory(
NULL,
"allocating parser namespaces",
854 ctxt->nbNamespaces = 0;
855 }
else if (ctxt->nbNamespaces + 2 >= ctxt->maxNamespaces) {
862 xmlSchematronPErrMemory(
NULL,
"allocating parser namespaces",
866 ctxt->namespaces = tmp;
867 ctxt->maxNamespaces *= 2;
869 ctxt->namespaces[2 * ctxt->nbNamespaces] =
871 ctxt->namespaces[2 * ctxt->nbNamespaces + 1] =
873 ctxt->nbNamespaces++;
874 ctxt->namespaces[2 * ctxt->nbNamespaces] =
NULL;
875 ctxt->namespaces[2 * ctxt->nbNamespaces + 1] =
NULL;
887xmlSchematronParseTestReportMsg(xmlSchematronParserCtxtPtr ctxt,
xmlNodePtr con)
890 xmlXPathCompExprPtr comp;
898 else if (IS_SCHEMATRON(
child,
"name")) {
900 }
else if (IS_SCHEMATRON(
child,
"value-of")) {
906 xmlSchematronPErr(ctxt,
child,
908 "value-of has no select attribute",
914 comp = xmlXPathCtxtCompile(ctxt->xctxt,
select);
916 xmlSchematronPErr(ctxt,
child,
918 "Failed to compile select expression %s",
921 xmlXPathFreeCompExpr(comp);
938xmlSchematronParseRule(xmlSchematronParserCtxtPtr ctxt,
939 xmlSchematronPatternPtr
pattern,
949 xmlSchematronRulePtr ruleptr;
950 xmlSchematronTestPtr testptr;
952 if ((ctxt ==
NULL) || (rule ==
NULL))
return;
956 xmlSchematronPErr(ctxt, rule,
958 "rule has no context attribute",
962 xmlSchematronPErr(ctxt, rule,
964 "rule has an empty context attribute",
969 ruleptr = xmlSchematronAddRule(ctxt, ctxt->schema,
pattern,
971 if (ruleptr ==
NULL) {
978 NEXT_SCHEMATRON(
cur);
980 if (IS_SCHEMATRON(
cur,
"let")) {
981 xmlXPathCompExprPtr var_comp;
982 xmlSchematronLetPtr let;
986 xmlSchematronPErr(ctxt,
cur,
988 "let has no name attribute",
991 }
else if (
name[0] == 0) {
992 xmlSchematronPErr(ctxt,
cur,
994 "let has an empty name attribute",
1001 xmlSchematronPErr(ctxt,
cur,
1003 "let has no value attribute",
1006 }
else if (
value[0] == 0) {
1007 xmlSchematronPErr(ctxt,
cur,
1009 "let has an empty value attribute",
1015 var_comp = xmlXPathCtxtCompile(ctxt->xctxt,
value);
1016 if (var_comp ==
NULL) {
1017 xmlSchematronPErr(ctxt,
cur,
1019 "Failed to compile let expression %s",
1024 let = (xmlSchematronLetPtr)
malloc(
sizeof(xmlSchematronLet));
1026 let->comp = var_comp;
1030 if (ruleptr->lets !=
NULL) {
1031 let->
next = ruleptr->lets;
1033 ruleptr->lets = let;
1036 }
else if (IS_SCHEMATRON(
cur,
"assert")) {
1040 xmlSchematronPErr(ctxt,
cur,
1042 "assert has no test attribute",
1044 }
else if (
test[0] == 0) {
1045 xmlSchematronPErr(ctxt,
cur,
1047 "assert has an empty test attribute",
1051 xmlSchematronParseTestReportMsg(ctxt,
cur);
1054 testptr = xmlSchematronAddTest(ctxt, XML_SCHEMATRON_ASSERT,
1056 if (testptr ==
NULL)
1059 }
else if (IS_SCHEMATRON(
cur,
"report")) {
1063 xmlSchematronPErr(ctxt,
cur,
1065 "assert has no test attribute",
1067 }
else if (
test[0] == 0) {
1068 xmlSchematronPErr(ctxt,
cur,
1070 "assert has an empty test attribute",
1074 xmlSchematronParseTestReportMsg(ctxt,
cur);
1077 testptr = xmlSchematronAddTest(ctxt, XML_SCHEMATRON_REPORT,
1079 if (testptr ==
NULL)
1083 xmlSchematronPErr(ctxt,
cur,
1085 "Expecting an assert or a report element instead of %s",
1089 NEXT_SCHEMATRON(
cur);
1091 if (nbChecks == 0) {
1092 xmlSchematronPErr(ctxt, rule,
1094 "rule has no assert nor report element",
NULL,
NULL);
1106xmlSchematronParsePattern(xmlSchematronParserCtxtPtr ctxt,
xmlNodePtr pat)
1109 xmlSchematronPatternPtr
pattern;
1113 if ((ctxt ==
NULL) || (pat ==
NULL))
return;
1119 pattern = xmlSchematronAddPattern(ctxt, ctxt->schema, pat,
id);
1126 NEXT_SCHEMATRON(
cur);
1128 if (IS_SCHEMATRON(
cur,
"rule")) {
1132 xmlSchematronPErr(ctxt,
cur,
1134 "Expecting a rule element instead of %s",
cur->name,
NULL);
1137 NEXT_SCHEMATRON(
cur);
1140 xmlSchematronPErr(ctxt, pat,
1142 "Pattern has no rule element",
NULL,
NULL);
1157xmlSchematronLoadInclude(xmlSchematronParserCtxtPtr ctxt,
xmlNodePtr cur)
1170 xmlSchematronPErr(ctxt,
cur,
1172 "Include has no href attribute",
NULL,
NULL);
1179 doc =
xmlReadFile((
const char *) URI,
NULL, SCHEMATRON_PARSE_OPTIONS);
1181 xmlSchematronPErr(ctxt,
cur,
1183 "could not load include '%s'.\n",
1189 xmlSchematronPErr(ctxt,
cur,
1191 "could not find root from include '%s'.\n",
1197 xmlSchematronPushInclude(ctxt, doc,
cur);
1224xmlSchematronParse(xmlSchematronParserCtxtPtr ctxt)
1239 if (ctxt->URL !=
NULL) {
1241 SCHEMATRON_PARSE_OPTIONS);
1243 xmlSchematronPErr(ctxt,
NULL,
1245 "xmlSchematronParse: could not load '%s'.\n",
1250 }
else if (ctxt->buffer !=
NULL) {
1252 SCHEMATRON_PARSE_OPTIONS);
1254 xmlSchematronPErr(ctxt,
NULL,
1256 "xmlSchematronParse: could not parse.\n",
1263 }
else if (ctxt->doc !=
NULL) {
1268 xmlSchematronPErr(ctxt,
NULL,
1270 "xmlSchematronParse: could not parse.\n",
1282 "The schema has no document element.\n",
NULL,
NULL);
1289 if (!IS_SCHEMATRON(
root,
"schema")) {
1290 xmlSchematronPErr(ctxt,
root,
1292 "The XML document '%s' is not a XML schematron document",
1296 ret = xmlSchematronNewSchematron(ctxt);
1305 NEXT_SCHEMATRON(
cur);
1306 if (IS_SCHEMATRON(
cur,
"title")) {
1313 NEXT_SCHEMATRON(
cur);
1315 while (IS_SCHEMATRON(
cur,
"ns")) {
1319 xmlSchematronPErr(ctxt,
cur,
1321 "ns element has no uri",
NULL,
NULL);
1323 if ((prefix ==
NULL) || (prefix[0] == 0)) {
1324 xmlSchematronPErr(ctxt,
cur,
1326 "ns element has no prefix",
NULL,
NULL);
1328 if ((prefix) && (
uri)) {
1329 xmlXPathRegisterNs(ctxt->xctxt, prefix,
uri);
1330 xmlSchematronAddNamespace(ctxt, prefix,
uri);
1338 NEXT_SCHEMATRON(
cur);
1341 if (IS_SCHEMATRON(
cur,
"pattern")) {
1342 xmlSchematronParsePattern(ctxt,
cur);
1345 xmlSchematronPErr(ctxt,
cur,
1347 "Expecting a pattern element instead of %s",
cur->name,
NULL);
1350 NEXT_SCHEMATRON(
cur);
1352 if (
ret->nbPattern == 0) {
1353 xmlSchematronPErr(ctxt,
root,
1355 "The schematron document '%s' has no pattern",
1371 if (ctxt->nberrors != 0) {
1372 xmlSchematronFree(
ret);
1375 ret->namespaces = ctxt->namespaces;
1376 ret->nbNamespaces = ctxt->nbNamespaces;
1377 ctxt->namespaces =
NULL;
1390xmlSchematronGetNode(xmlSchematronValidCtxtPtr ctxt,
1393 xmlXPathObjectPtr
ret;
1398 ctxt->xctxt->doc =
cur->doc;
1399 ctxt->xctxt->node =
cur;
1400 ret = xmlXPathEval(xpath, ctxt->xctxt);
1404 if ((
ret->type == XPATH_NODESET) &&
1405 (
ret->nodesetval !=
NULL) && (
ret->nodesetval->nodeNr > 0))
1406 node =
ret->nodesetval->nodeTab[0];
1408 xmlXPathFreeObject(
ret);
1440xmlSchematronFormatReport(xmlSchematronValidCtxtPtr ctxt,
1444 xmlXPathCompExprPtr comp;
1454 else if (IS_SCHEMATRON(
child,
"name")) {
1474 }
else if (IS_SCHEMATRON(
child,
"value-of")) {
1476 xmlXPathObjectPtr eval;
1479 comp = xmlXPathCtxtCompile(ctxt->xctxt,
select);
1480 eval = xmlXPathCompiledEval(comp, ctxt->xctxt);
1482 switch (eval->type) {
1483 case XPATH_NODESET: {
1487 if (eval->nodesetval) {
1488 for (indx = 0; indx < eval->nodesetval->nodeNr; indx++) {
1495 "Empty node set\n");
1499 case XPATH_BOOLEAN: {
1500 const char *
str = eval->boolval ?
"True" :
"False";
1504 case XPATH_NUMBER: {
1521 "Unsupported XPATH Type: %d\n", eval->type);
1523 xmlXPathFreeObject(eval);
1524 xmlXPathFreeCompExpr(comp);
1540 if ((
c ==
' ') || (
c ==
'\n') || (
c ==
'\r') || (
c ==
'\t')) {
1541 while ((
c ==
' ') || (
c ==
'\n') ||
1542 (
c ==
'\r') || (
c ==
'\t')) {
1570xmlSchematronReportSuccess(xmlSchematronValidCtxtPtr ctxt,
1575 if ((ctxt->flags & XML_SCHEMATRON_OUT_QUIET) &&
1576 ((ctxt->flags & XML_SCHEMATRON_OUT_XML) == 0) &&
1577 (
test->type == XML_SCHEMATRON_REPORT))
1579 if (ctxt->flags & XML_SCHEMATRON_OUT_XML) {
1587 if (((
test->type == XML_SCHEMATRON_REPORT) & (!
success)) ||
1588 ((
test->type == XML_SCHEMATRON_ASSERT) & (
success)))
1601 if (
test->type == XML_SCHEMATRON_ASSERT) {
1610 if (ctxt->flags & XML_SCHEMATRON_OUT_ERROR) {
1616 if (ctxt->serror !=
NULL)
1617 schannel = ctxt->serror;
1619 channel = ctxt->error;
1620 data = ctxt->userData;
1623 __xmlRaiseError(schannel, channel,
data,
1628 (
const char *)
path,
1629 (
const char *)
report, 0, 0,
1632 xmlSchematronReportOutput(ctxt,
cur, &
msg[0]);
1650xmlSchematronReportPattern(xmlSchematronValidCtxtPtr ctxt,
1651 xmlSchematronPatternPtr
pattern) {
1654 if ((ctxt->flags & XML_SCHEMATRON_OUT_QUIET) || (ctxt->flags & XML_SCHEMATRON_OUT_ERROR))
1656 if (ctxt->flags & XML_SCHEMATRON_OUT_XML) {
1664 xmlSchematronReportOutput(ctxt,
NULL, &
msg[0]);
1684xmlSchematronSetValidStructuredErrors(xmlSchematronValidCtxtPtr ctxt,
1689 ctxt->serror = serror;
1691 ctxt->warning =
NULL;
1692 ctxt->userData =
ctx;
1704xmlSchematronValidCtxtPtr
1705xmlSchematronNewValidCtxt(xmlSchematronPtr
schema,
int options)
1708 xmlSchematronValidCtxtPtr
ret;
1710 ret = (xmlSchematronValidCtxtPtr)
xmlMalloc(
sizeof(xmlSchematronValidCtxt));
1712 xmlSchematronVErrMemory(
NULL,
"allocating validation context",
1716 memset(
ret, 0,
sizeof(xmlSchematronValidCtxt));
1717 ret->type = XML_STRON_CTXT_VALIDATOR;
1719 ret->xctxt = xmlXPathNewContext(
NULL);
1722 xmlSchematronPErrMemory(
NULL,
"allocating schema parser XPath context",
1724 xmlSchematronFreeValidCtxt(
ret);
1727 for (
i = 0;
i <
schema->nbNamespaces;
i++) {
1731 xmlXPathRegisterNs(
ret->xctxt,
schema->namespaces[2 *
i + 1],
1744xmlSchematronFreeValidCtxt(xmlSchematronValidCtxtPtr ctxt)
1748 if (ctxt->xctxt !=
NULL)
1749 xmlXPathFreeContext(ctxt->xctxt);
1750 if (ctxt->dict !=
NULL)
1802xmlSchematronRunTest(xmlSchematronValidCtxtPtr ctxt,
1805 xmlXPathObjectPtr
ret;
1810 ctxt->xctxt->node =
cur;
1811 ret = xmlXPathCompiledEval(
test->comp, ctxt->xctxt);
1815 switch (
ret->type) {
1816 case XPATH_XSLT_TREE:
1818 if ((
ret->nodesetval ==
NULL) ||
1819 (
ret->nodesetval->nodeNr == 0))
1823 failed = !
ret->boolval;
1826 if ((xmlXPathIsNaN(
ret->floatval)) ||
1827 (
ret->floatval == 0.0))
1831 if ((
ret->stringval ==
NULL) ||
1832 (
ret->stringval[0] == 0))
1835 case XPATH_UNDEFINED:
1836#ifdef LIBXML_XPTR_LOCS_ENABLED
1839 case XPATH_LOCATIONSET:
1845 xmlXPathFreeObject(
ret);
1847 if ((failed) && (
test->type == XML_SCHEMATRON_ASSERT))
1849 else if ((!failed) && (
test->type == XML_SCHEMATRON_REPORT))
1869xmlSchematronRegisterVariables(xmlXPathContextPtr ctxt, xmlSchematronLetPtr let,
1872 xmlXPathObjectPtr let_eval;
1876 while (let !=
NULL) {
1877 let_eval = xmlXPathCompiledEval(let->comp, ctxt);
1878 if (let_eval ==
NULL) {
1880 "Evaluation of compiled expression failed\n");
1883 if(xmlXPathRegisterVariableNS(ctxt, let->name,
NULL, let_eval)) {
1885 "Registering a let variable failed\n");
1903xmlSchematronUnregisterVariables(xmlXPathContextPtr ctxt, xmlSchematronLetPtr let)
1905 while (let !=
NULL) {
1906 if (xmlXPathRegisterVariableNS(ctxt, let->name,
NULL,
NULL)) {
1908 "Unregistering a let variable failed\n");
1930 xmlSchematronPatternPtr
pattern;
1931 xmlSchematronRulePtr rule;
1932 xmlSchematronTestPtr
test;
1934 if ((ctxt ==
NULL) || (ctxt->schema ==
NULL) ||
1944 if ((ctxt->flags & XML_SCHEMATRON_OUT_QUIET) ||
1945 (ctxt->flags == 0)) {
1952 rule = ctxt->schema->rules;
1953 while (rule !=
NULL) {
1954 if (xmlPatternMatch(rule->pattern,
cur) == 1) {
1957 if (xmlSchematronRegisterVariables(ctxt->xctxt, rule->lets,
instance,
cur))
1961 xmlSchematronRunTest(ctxt,
test,
instance,
cur, (xmlSchematronPatternPtr)rule->pattern);
1965 if (xmlSchematronUnregisterVariables(ctxt->xctxt, rule->lets))
1972 cur = xmlSchematronNextNode(
cur);
1978 pattern = ctxt->schema->patterns;
1981 xmlSchematronReportPattern(ctxt,
pattern);
1992 while (rule !=
NULL) {
1993 if (xmlPatternMatch(rule->pattern,
cur) == 1) {
1995 xmlSchematronRegisterVariables(ctxt->xctxt, rule->lets,
2003 xmlSchematronUnregisterVariables(ctxt->xctxt, rule->lets);
2005 rule = rule->patnext;
2008 cur = xmlSchematronNextNode(
cur);
2013 return(ctxt->nberrors);
2022 xmlSchematronParserCtxtPtr pctxt;
2023 xmlSchematronValidCtxtPtr vctxt;
2026 pctxt = xmlSchematronNewParserCtxt(
"tst.sct");
2027 if (pctxt ==
NULL) {
2030 schema = xmlSchematronParse(pctxt);
2034 xmlSchematronFreeParserCtxt(pctxt);
2042 vctxt = xmlSchematronNewValidCtxt(
schema);
2043 if (vctxt ==
NULL) {
2047 xmlSchematronFreeValidCtxt(vctxt);
2050 xmlSchematronFree(
schema);
static struct loaded_include * includes
static HINSTANCE instance
static void report(const DATA_BLOB *pDataIn, const DATA_BLOB *pOptionalEntropy, CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct, DWORD dwFlags)
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
GLuint GLuint GLsizei GLenum type
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLsizei const GLvoid GLenum preserve
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
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static struct test_info tests[]
#define sprintf(buf, format,...)
static unsigned __int64 next
XMLPUBFUN const xmlChar *XMLCALL xmlDictLookup(xmlDictPtr dict, const xmlChar *name, int len)
XMLPUBFUN xmlDictPtr XMLCALL xmlDictCreate(void)
XMLPUBFUN void XMLCALL xmlDictFree(xmlDictPtr dict)
XMLPUBFUN int XMLCALL xmlDictReference(xmlDictPtr dict)
XMLPUBVAR xmlMallocFunc xmlMalloc
XMLPUBVAR xmlFreeFunc xmlFree
XMLPUBVAR void * xmlGenericErrorContext
XMLPUBVAR xmlReallocFunc xmlRealloc
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
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 void XMLCALL xmlCleanupParser(void)
XMLPUBFUN xmlChar *XMLCALL xmlNodeGetContent(const xmlNode *cur)
XMLPUBFUN xmlNodePtr XMLCALL xmlDocGetRootElement(const xmlDoc *doc)
XMLPUBFUN void XMLCALL xmlFreeDoc(xmlDocPtr cur)
XMLPUBFUN xmlChar *XMLCALL xmlGetNoNsProp(const xmlNode *node, const xmlChar *name)
XMLPUBFUN xmlChar *XMLCALL xmlNodeGetBase(const xmlDoc *doc, const xmlNode *cur)
XMLPUBFUN long XMLCALL xmlGetLineNo(const xmlNode *node)
struct _xmlNode * children
XMLPUBFUN xmlChar *XMLCALL xmlBuildURI(const xmlChar *URI, const xmlChar *base)
#define success(from, fromstr, to, tostr)
void(XMLCDECL * xmlGenericErrorFunc)(void *ctx, const char *msg,...) LIBXML_ATTR_FORMAT(2
void(XMLCDECL *) typedef void(XMLCALL * xmlStructuredErrorFunc)(void *userData, xmlErrorPtr error)
@ XML_SCHEMAP_FAILED_PARSE
@ XML_SCHEMAP_FAILED_LOAD
@ XML_SCHEMAP_NOTHING_TO_PARSE
@ XML_SCHEMAV_ATTRINVALID
XMLPUBFUN void XMLCALL xmlMemoryDump(void)
XMLPUBFUN xmlChar *XMLCALL xmlStrcat(xmlChar *cur, const xmlChar *add)
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
#define LIBXML_ATTR_FORMAT(fmt, args)