Re: [xml] Will xmllint use schematron?

  I read quickly. I didn't understand it.

It's not a very good site, IMHO. However, schematron itself is quite a
neat idea.

It seems it would require XSLT and EXSLT so it would not be implementable
at the libxml2 level since XSLT and EXSLT are provided in libraries separate
from libxml2.

I believe that only XPath is required, so it would be possible, but I
agree with Daniel that it would be better implemented as a seperate tool
on top of libxml/libxslt.

The implementation is fairly trivial, and there are existing
implementations in XSLT:

I've used some of the sample metastylesheets with xsltproc, and have had
no problems. If you really want a programatic interface, here's a simple
start point...

/* Simple Schematron commandline util
   Based on skeleton1-5.xsl, from

   S. Little

#include <iostream.h>
#include "libxslt/transform.h"
#include "libxslt/xsltutils.h"

const char * skeleton_xslfile="/path/to/skeleton1-5.xsl";

int main(int argc, char** argv)
  if(argc != 3){
    cout << "Usage:" << endl;
    cout << "\t" << argv[0] << " <schematron-schema-file> <xml-file>" <<
    return 1;

  // generate schematron XSLT document
  xsltStylesheetPtr skeletonXsl = xsltParseStylesheetFile((const xmlChar
  xmlDocPtr schematronDoc = xmlParseFile(argv[1]);
  xmlDocPtr schematronXml = xsltApplyStylesheet(skeletonXsl,
schematronDoc, NULL);

  // apply schematron XSLT document to input XML, to produce output
  xsltStylesheetPtr schematronXsl = xsltParseStylesheetDoc(schematronXml);
  xmlDocPtr input = xmlParseFile(argv[2]);
  xmlDocPtr output = xsltApplyStylesheet(schematronXsl,input, NULL);

  // Any analysis of the output can be done here.
  // For now, just dump to stdout

You could make a metastylesheet makes it trivial to analyse the output for

A perl implementation on a similar principle exists:

Alternatively, you can parse the schematron schemafile yourself,
implement each tag, check the XPaths etc, and thus make a libxml only
version. Arguably that's a waste of time though, when there's a Free XSLT

Hope that helps.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]