RE: [xml] On validating a DOM with a schema, in Python
- From: "Meunier, Jean-Luc" <Jean-Luc Meunier xrce xerox com>
- To: "Kasimier Buchcik" <K Buchcik 4commerce de>
- Cc: ML-libxml2 <xml gnome org>
- Subject: RE: [xml] On validating a DOM with a schema, in Python
- Date: Wed, 26 Oct 2005 10:28:13 +0200
Ok, thanks Kasimier for this good pointer to the test suite file "xstc/xstc.py".
So here are the steps (note that in xstc.py the error cases are properly handled)
JL
# inspired from the test suite file "xstc/xstc.py"
# thanks to Kasimier Buchcik
#
import libxml2
ctxt = libxml2.schemaNewParserCtxt("my-schema.xsd")
schema = ctxt.schemaParse()
del ctxt
validationCtxt = schema.schemaNewValidCtxt()
doc = libxml2.parseFile("test.xml")
#instance_Err = validationCtxt.schemaValidateFile(filePath, 0)
instance_Err = validationCtxt.schemaValidateDoc(doc)
del validationCtxt
del schema
doc.freeDoc()
if instance_Err != 0:
print "VALIDATION FAILED"
else:
print "VALIDATED"
-----Original Message-----
From: xml-bounces gnome org [mailto:xml-bounces gnome org] On Behalf Of Kasimier Buchcik
Sent: Tuesday, October 25, 2005 5:44 PM
To: Meunier, Jean-Luc
Cc: ML-libxml2
Subject: Re: [xml] On validating a DOM with a schema, in Python
Hi,
On Tue, 2005-10-25 at 17:14 +0200, Meunier, Jean-Luc wrote:
Hi,
In Python, I need to validate a DOM tree using a W3C XML schema, but I cannot figure out how to do it.
It seems that the C-function xmlSchemaValidateDoc does the job but I'm lost in the Python binding.
( My (naïve) trials were in the style:
schemadoc = libxml2.parseFile("my-schema.wxs")
schema = libxml2.Schema(schemadoc)
ctxt = libxml2.SchemaValidCtxt(schema)
#ctxt.schemaParse() ??
doc = libxml2.parseFile("test.xml")
res = doc.schemaValidateDoc(ctxt)
)
Is there anyone around that can show me the way? (I insist, that it is about validating a DOM already in
memory)
Thanks,
JL
I'm heading home, so just a short one: maybe the test suite
file "xstc/xstc.py" can be of some help; it uses schemaValidateDoc()
as well as schemaValidateFile() for stream-based validation.
Regards,
Kasimier
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]