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

[xml] Fwd: [lxml-dev] lxml RelaxNG validation on hand-built documents



Hi,

any idea what might trigger this?

The main API calls we use are:

	ctx = xmlRelaxNGNewParserCtxt(filename)
	schema = xmlRelaxNGParse(ctx)
	xmlRelaxNGFreeParserCtxt(ctx)
	...
	// create doc
	...
	vc = xmlRelaxNGNewValidCtxt(schema)
	xmlRelaxNGValidateDoc(vc, doc)
	xmlRelaxNGFreeValidCtxt(vc)
	...
	// change doc
	// repeat validation with schema

Thanks,

Stefan

-------- original message --------
Subject: [lxml-dev] lxml RelaxNG validation on hand-built documents
Date: Thu, 30 Oct 2008 16:53:33 +0100
From: Atilla <theatilla gmail com>
To: lxml-dev codespeak net

I've had a very curious issue that I'm trying to find the cause about.
Basically - if I try to validate a document tree that was dynamically
created by lxml with a relaxNG schema, the validation step passses
even if there are invalid elements. If I serialize that same tree to a
string and parse it once again, the newly created XML document fails
the validation. Given that I expect to process fairly large trees, I'd
rather not have to copy so much nformation in memory on every attempt
to validate a document.

Is there any reason why lxml wouldn't validate items that have been
newly created and inserted into the tree, or this is a bug? How would
I make sure a tree is valid, according to a schema, before I
serialized and saved it ?

Basically what i do is:

>>>schema = etree.RelaxNG(file="schema.rng")

>>>doc = etree.fromstring("<valid></valid>")

>>>schema(doc)
True

>>>doc[0].append(etree.Element("invalid"))

>>>schema(doc)
True

>>>schema(etree.fromstring(etree.tostring(doc)))
False

It's really making me think I don't get some point in the whole
validation process. In hindsight - I had the same issues wiht the Perl
LibXML bindings at some point in the past. Is it maybe Libxml -related
?

Cheers,



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