* xmlShellRNGValidate: * @ctxt: the shell context * @schemas: the path to the Relax-NG schemas * @node: a node * @node2: unused * * Implements the XML shell function "relaxng" * validating the instance against a Relax-NG schemas * * Returns 0 */
| 2345 | * Returns 0 |
| 2346 | */ |
| 2347 | static int |
| 2348 | xmlShellRNGValidate(xmlShellCtxtPtr sctxt, char *schemas, |
| 2349 | xmlNodePtr node ATTRIBUTE_UNUSED, |
| 2350 | xmlNodePtr node2 ATTRIBUTE_UNUSED) |
| 2351 | { |
| 2352 | xmlRelaxNGPtr relaxngschemas; |
| 2353 | xmlRelaxNGParserCtxtPtr ctxt; |
| 2354 | xmlRelaxNGValidCtxtPtr vctxt; |
| 2355 | int ret; |
| 2356 | |
| 2357 | ctxt = xmlRelaxNGNewParserCtxt(schemas); |
| 2358 | xmlRelaxNGSetParserErrors(ctxt, xmlShellPrintf, xmlShellPrintf, sctxt); |
| 2359 | relaxngschemas = xmlRelaxNGParse(ctxt); |
| 2360 | xmlRelaxNGFreeParserCtxt(ctxt); |
| 2361 | if (relaxngschemas == NULL) { |
| 2362 | fprintf(sctxt->output, |
| 2363 | "Relax-NG schema %s failed to compile\n", schemas); |
| 2364 | return(-1); |
| 2365 | } |
| 2366 | vctxt = xmlRelaxNGNewValidCtxt(relaxngschemas); |
| 2367 | xmlRelaxNGSetValidErrors(vctxt, xmlShellPrintf, xmlShellPrintf, sctxt); |
| 2368 | ret = xmlRelaxNGValidateDoc(vctxt, sctxt->doc); |
| 2369 | if (ret == 0) { |
| 2370 | fprintf(sctxt->output, "%s validates\n", sctxt->filename); |
| 2371 | } else if (ret > 0) { |
| 2372 | fprintf(sctxt->output, "%s fails to validate\n", sctxt->filename); |
| 2373 | } else { |
| 2374 | fprintf(sctxt->output, "%s validation generated an internal error\n", |
| 2375 | sctxt->filename); |
| 2376 | } |
| 2377 | xmlRelaxNGFreeValidCtxt(vctxt); |
| 2378 | if (relaxngschemas != NULL) |
| 2379 | xmlRelaxNGFree(relaxngschemas); |
| 2380 | return(0); |
| 2381 | } |
| 2382 | #endif |
| 2383 | |
| 2384 | #ifdef LIBXML_OUTPUT_ENABLED |
no test coverage detected