[XML-SIG] how to use XSV in python to validate an xml file against an xsd schema file

Henry S. Thompson ht@cogsci.ed.ac.uk
22 Mar 2003 11:34:27 +0000


"Nico Grubert" <nicogrubert@web.de> writes:

> hello,
> 
> i played around with XSV. I have installed it on win2000 and run the XSV file from the command line passing an xml file and and xsd schema file.
> 
> how can i use XSV in python ?
> 
> I tried:
> 
> """
> # validateTestXML.py
> 
> from XSV.driver import runitAndShow
> 
> xmlfile     = "myxmlfile.xml"
> schemafile  = "myxsdfile.xsd"
> 
> res = runitAndShow( xmlfile, schemafile )
> print res
> 
> """
> 
> but python does not print out anything. how can I print, if the
> validation brought errors or not ?
> 
> has anybody ever used it directly in python ?

As its name suggests, runitAndShow does the output itself, but it goes
to stderr, so you may have just never seen it.

Also note the second argument is a list, so you need to say

>>> runitAndShow(xmlfile,[schemafile])

For your purposes, you want to do

"""
# validateTestXML.py

from XSV.driver import runit
import sys

xmlfile     = "myxmlfile.xml"
schemafile  = "myxsdfile.xsd"

res = runit( xmlfile, [schemafile] )

res.printme(sys.stdout)

"""

-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
                      Half-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/
 [mail really from me _always_ has this .sig -- mail without it is forged spam]