Sample code required to validate a xml file against XSD

H

hrishy

Hi

Does anybody have a python xample program to validate a xml file against a XSD.

regards
Hrisy
 
F

Frank Millman

Hi

Does anybody have a python xample program to validate a xml file against a XSD.

regards
Hrisy

I have used minixsv successfully in a test environment -

http://www.familieleuthe.de/MiniXsv.html

Here is some sample code -

#---------------------------------
from minixsv import pyxsval as xsv
try:
etw = xsv.parseAndValidateXmlInput(
'bpmn1.xml',
'bpmn.xsd',
xmlIfClass=xsv.XMLIF_ELEMENTTREE)
et = etw.getTree()
root = et.getroot()
except xsv.XsvalError,errstr:
print errstr
#---------------------------------

It supports minidom, 4DOM, and ElementTree.

It is written in pure python. It is not very fast - around 0.5 sec for
a small xml file - but I have not compared it with any others, so I
don't know what is typical.

I believe that lxml also handles xsd files, but I have not tried it,
so I can't give any details.

HTH

Frank Millman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top