[lxml-dev] lxml RelaxNG validation on hand-built documents
Atilla
theatilla at gmail.com
Thu Oct 30 16:53:33 CET 2008
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,
More information about the lxml-dev
mailing list