* xmlSchematronAddRule: * @ctxt: the schema parsing context * @schema: a schema structure * @node: the node hosting the rule * @context: the associated context string * @report: the associated report string * * Add a rule to a schematron * * Returns the new pointer or NULL in case of error */
| 461 | * Returns the new pointer or NULL in case of error |
| 462 | */ |
| 463 | static xmlSchematronRulePtr |
| 464 | xmlSchematronAddRule(xmlSchematronParserCtxtPtr ctxt, xmlSchematronPtr schema, |
| 465 | xmlSchematronPatternPtr pat, xmlNodePtr node, |
| 466 | xmlChar *context, xmlChar *report) |
| 467 | { |
| 468 | xmlSchematronRulePtr ret; |
| 469 | xmlPatternPtr pattern; |
| 470 | |
| 471 | if ((ctxt == NULL) || (schema == NULL) || (node == NULL) || |
| 472 | (context == NULL)) |
| 473 | return(NULL); |
| 474 | |
| 475 | /* |
| 476 | * Try first to compile the pattern |
| 477 | */ |
| 478 | pattern = xmlPatterncompile(context, ctxt->dict, XML_PATTERN_XPATH, |
| 479 | ctxt->namespaces); |
| 480 | if (pattern == NULL) { |
| 481 | xmlSchematronPErr(ctxt, node, |
| 482 | XML_SCHEMAP_NOROOT, |
| 483 | "Failed to compile context expression %s", |
| 484 | context, NULL); |
| 485 | } |
| 486 | |
| 487 | ret = (xmlSchematronRulePtr) xmlMalloc(sizeof(xmlSchematronRule)); |
| 488 | if (ret == NULL) { |
| 489 | xmlSchematronPErrMemory(ctxt); |
| 490 | return (NULL); |
| 491 | } |
| 492 | memset(ret, 0, sizeof(xmlSchematronRule)); |
| 493 | ret->node = node; |
| 494 | ret->context = context; |
| 495 | ret->pattern = pattern; |
| 496 | ret->report = report; |
| 497 | ret->next = NULL; |
| 498 | ret->lets = NULL; |
| 499 | if (schema->rules == NULL) { |
| 500 | schema->rules = ret; |
| 501 | } else { |
| 502 | xmlSchematronRulePtr prev = schema->rules; |
| 503 | |
| 504 | while (prev->next != NULL) |
| 505 | prev = prev->next; |
| 506 | prev->next = ret; |
| 507 | } |
| 508 | ret->patnext = NULL; |
| 509 | if (pat->rules == NULL) { |
| 510 | pat->rules = ret; |
| 511 | } else { |
| 512 | xmlSchematronRulePtr prev = pat->rules; |
| 513 | |
| 514 | while (prev->patnext != NULL) |
| 515 | prev = prev->patnext; |
| 516 | prev->patnext = ret; |
| 517 | } |
| 518 | return (ret); |
| 519 | } |
| 520 |
no test coverage detected