#!/export/home/ht/bin/python1.6 """ $Id: xmlschema-check,v 1.16 2000/06/20 15:47:56 ht Exp $ """ import sys import cgi import os import string import traceback import time import tempfile import urlparse Page = """ XML Schema Checking Service (ALPHA TEST) XML Output version

W3C XML LTG

XML Schema Validator, XML Output version

NOTICE: This is an ALPHA TEST of a service for a work-in-progress specification.


Use this form for checking a schema which is accessible via the Web, and/or schema-validating an instance with a schema of your own.


Default output is now text/xml with an XSLT stylesheet. Select fallbacks for browsers which don't support http://www.w3.org/1999/XSL/Transform stylesheets:
text/xml + official XSLT (suits IE5.5; IE5 + MSXML3)
text/xml + early MS XSL support (suits vanilla IE5)
text/html (styled server-side: suits Netscape, older IE)
xml, but labelled text/plain (works for any browser, but hard to read)


Use this form only if you are behind a firewall or have a schema to check which is not accessible via the Web.


Default output is now text/xml with an XSLT stylesheet. Select fallbacks for browsers which don't support http://www.w3.org/1999/XSL/Transform stylesheets:
text/xml + official XSLT (suits IE5.5; IE5 + MSXML3)
text/xml + early MS XSL support (suits vanilla IE5)
text/html (styled server-side: suits Netscape, older IE)
xml, but labelled text/plain (works for any browser, but hard to read)


Address(es)
of document to schema-validate. If you enter more than one URL, the 2nd etc. will be used to schema-validate the first
Keep Going
continue schema-validation after finding errors
Contribute
We need schemas to provide a regression testing pool: if you're willing for a copy of your input to be logged and copied offline, please give us permission to do so.

Stuff

report problems (and sucesses!) to xmlschema-dev (archive)
Schema validator by Henry S. Thompson and Richard Tobin.
Web interface by Dan Connolly
script $Revision: 1.16 $ of $Date: 2000/06/20 15:47:56 $
""" # ' sys.path.append("/export/home/ht/lib/xmlschema") import applyschema from PyXML import error def serveRequest(): tempfile.tempdir="/export/home/ht/xsvlog" logFile=None fields = cgi.FieldStorage() if not (fields.has_key('docAddrs') or fields.has_key('docFile')): print "Content-Type: text/html" print print Page else: timeString=time.asctime(time.gmtime(time.time())) ss=None stemplate='../style/%s' style = fields['style'].value if style=='text': mime='text/plain' elif style=='offline': mime='text/html' else: mime='text/xml' if style=='msxsl': ss=stemplate%'xsv.msxsl' else: ss=stemplate%'xsv.xsl' if fields.has_key('docFile'): data = fields['docFile'].file.read() # print "writing %d bytes of uploaded data ..." \ # %(len(data), ) uploadTmp = tempfile.mktemp("uploaded") #@@hmm... when to delete these? # print "... to %s" % (uploadTmp,) fp = open(uploadTmp, "w") fp.write(data) fp.close() target = 'file:' + uploadTmp args = [target,] schemas = [] #@@hmm... allow both upload and schemas? else: addrs = fields['docAddrs'].value if "'" in addrs: print """Content-Type: text/plain sorry, I can't handle addresses with ' in them""" return args=string.split(addrs) for fn in args: if not urlparse.urlparse(fn)[0]: print """Content-Type: text/plain sorry, I can't handle relative addresses: %s"""%fn return target=args[0] schemas=args[1:] if fields.has_key('keepGoing'): keep='on' else: keep='off' if fields.has_key('logOK'): logFile=tempfile.mktemp() log = open(logFile,"a+") log.write("\n"% (timeString, args,keep,applyschema.vs)) log.close() print "Content-Type: %s"%mime print sys.stdout.flush() if style=='offline': outFile=tempfile.mktemp("xsvout") outf=open(outFile,"w+") sys.stderr.flush() savestderr=os.dup(2) # save stderr os.dup2(outf.fileno(),2) # capture all output else: os.dup2(1, 2) # send stderr to stdout sys.stdout.flush() try: applyschema.runitAndShow(target,schemas,keep=='on',ss) except error: # IO Error in PyXML pass except: if style=='offline': os.dup2(savestderr,2) # put it back print 'XSV Crash
'
          print "Schema validator crashed:"
          print '-'*60
          traceback.print_exc(file=sys.stdout)
          print '-'*60
          print """The maintainers of XSV will be notified, you don't need to
send mail about this unless you have extra information to provide.
If there are Schema errors reported before the crash, try correcting
them and re-running the validation."""
          if style=='offline':
            print '
' if not logFile: logFile=tempfile.mktemp() log = open(logFile,"a+") log.write(""% (time.asctime(time.gmtime(time.time())), args,keep,applyschema.vs)) log.write("\n") log.write("\n") log.close() return if style=='offline': sys.stderr.flush() os.dup2(savestderr,2) # put it back outf.close() os.system("/export/home/ht/bin/doxt %s /usr/local/Jigsaw/Jigsaw/WWW/style/xsv.xsl"%outFile) if __name__ == '__main__': #sys.stderr = open("/tmp/cgi-write/xmlschema-log", "w+") #sys.stderr.write(str(os.environ)) if os.environ.has_key('SCRIPT_NAME'): try: serveRequest() except: print "Content-Type: text/plain" print traceback.print_exc(file=sys.stdout)