* xmlShellValidate: * @ctxt: the shell context * @dtd: the DTD URI (optional) * @node: unused * @node2: unused * * Implements the XML shell function "validate" * Validate the document, if a DTD path is provided, then the validation * is done against the given DTD. * * Returns 0 or -1 in case of error */
| 2625 | * Returns 0 or -1 in case of error |
| 2626 | */ |
| 2627 | int |
| 2628 | xmlShellValidate(xmlShellCtxtPtr ctxt, char *dtd, |
| 2629 | xmlNodePtr node ATTRIBUTE_UNUSED, |
| 2630 | xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 2631 | { |
| 2632 | xmlValidCtxt vctxt; |
| 2633 | int res = -1; |
| 2634 | |
| 2635 | if ((ctxt == NULL) || (ctxt->doc == NULL)) return(-1); |
| 2636 | memset(&vctxt, 0, sizeof(vctxt)); |
| 2637 | vctxt.error = xmlShellPrintf; |
| 2638 | vctxt.warning = xmlShellPrintf; |
| 2639 | vctxt.userData = ctxt; |
| 2640 | |
| 2641 | if ((dtd == NULL) || (dtd[0] == 0)) { |
| 2642 | res = xmlValidateDocument(&vctxt, ctxt->doc); |
| 2643 | } else { |
| 2644 | xmlDtdPtr subset; |
| 2645 | |
| 2646 | subset = xmlParseDTD(NULL, (xmlChar *) dtd); |
| 2647 | if (subset != NULL) { |
| 2648 | res = xmlValidateDtd(&vctxt, ctxt->doc, subset); |
| 2649 | |
| 2650 | xmlFreeDtd(subset); |
| 2651 | } |
| 2652 | } |
| 2653 | return (res); |
| 2654 | } |
| 2655 | #endif /* LIBXML_VALID_ENABLED */ |
| 2656 | |
| 2657 | /** |
no test coverage detected