[lxml-dev] getting back RelaxNG tree
Hello, I'd like to use a set of RelaxNG documents to construct a validation API. The documents will be modular and combined using the externalRef and include tags. I will need a way to access the merged files as if they were one Russian-Doll style file. I see that etree.RelaxNG can be passed an ElementTree object. I assume that etree.parse is not going to resolve RelaxNG references like , and . Does the object etree.RelaxNG return have methods to access the document as if it were built Russian-Doll style, or is it strictly limited to validation? Is there any access to the libxml function xmlRelaxNGDumpTree which I assume may do something like this, but to a file? Ditto for xmlRelaxNGParse? Thank you.
Hi, Eric Scheidemantle wrote:
I'd like to use a set of RelaxNG documents to construct a validation API. The documents will be modular and combined using the externalRef and include tags. I will need a way to access the merged files as if they were one Russian-Doll style file.
uhm, just for clarity: you mean the XML tree of the merged RelaxNG file, right?
I see that etree.RelaxNG can be passed an ElementTree object.
or a filename alternatively.
I assume that etree.parse is not going to resolve RelaxNG references like , and .
Sorry, like what?
Does the object etree.RelaxNG return have methods to access the document as if it were built Russian-Doll style, or is it strictly limited to validation?
It does validation, nothing more.
Is there any access to the libxml function xmlRelaxNGDumpTree which I assume may do something like this, but to a file?
No, not currently. Should be easy to add, though. Just add a method (or property?) to the RelaxNG class that retrieves the in-memory tree. Maybe the XMLSchema class could do the same? I'd prefer a string result over writing to a file, BTW. It's easy to write a string to a file, but it's overhead to read in a file when all you wanted is a string. Oh, and: I assume building an ElementTree from the internal RelaxNG schema is not a good idea, as it could interfere too much with the validation. Copying them first /might/ work, though.
Ditto for xmlRelaxNGParse?
That's the function used for parsing. What does the "ditto" refer to here? You can look up the code in the file src/lxml/relaxng.pxi. It's pretty short and easy to read. Stefan
Hi, Eric Scheidemantle wrote:
I'd like to use a set of RelaxNG documents to construct a validation API. The documents will be modular and combined using the externalRef and include tags. I will need a way to access the merged files as if they were one Russian-Doll style file.
Is there any access to the libxml function xmlRelaxNGDumpTree which I assume may do something like this, but to a file?
I did some testing and found that xmlRelaxNGDumpTree does not give you access to the complete structure. It only returns the normal RNG document that was parsed, not a merged one. Includes seem to be resolved at validation time, so there is no gain in adding to the API here. Stefan
participants (2)
-
Eric Scheidemantle
-
Stefan Behnel