[lxml-dev] etree.Element from RNG schema?
Stefan Behnel
stefan_ml at behnel.de
Thu Jul 17 07:03:40 CEST 2008
Hi,
Frank Cusack wrote:
> Can lxml give me back an Element object from a parsed RNG schema?
> That is, given
>
> parser = etree.RelaxNG(etree.parse(file("foo.rng")))
>
> I'd like to do something like parser.getroot() in order to get back
> an Element/ElementTree which is like the original schema except with
> grammar/define's expanded.
>
> What I want is to go from
>
> <grammar>
> <start>
> <element name="foo">
> <ref name="bar" />
> </element>
> </start>
>
> <define name="bar">
> <text />
> </define>
> </grammar>
>
> to
>
> <element name="foo">
> <text />
> </element>
libxml2 does not expose the internals of its schemas (RNG/XSD).
But if all you want is resolved <ref> tags, you can do that yourself very
easily, without passing through RelaxNG at all. (You might want to use
.iter(tag) for that instead of XPath, BTW).
Stefan
More information about the lxml-dev
mailing list