
Hello, I'm making use of lxml.objectify with custom element class lookup, as shown in the code below. This was working great for me, but I'm running into a problem when attempting to make use of XInclude to split up my XML files. See the example code below. from lxml import etree, objectify lookup = ... rngschema = ... xmlfile = ... parser = objectify.makeparser(remove_comments=True, no_network=True) parser.set_element_class_lookup(lookup) schema = etree.RelaxNG(etree.parse(rngschema)) xml = objectify.parse(xmlfile, parser) xml.xinclude() The nodes inserted into the tree by xinclude() are of the lxml.etree._Element type, and are not mapped to the custom classes I defined in the class lookup dictionary. Is XInclude not supported for objectify? Or maybe I'm not pushing the correct buttons? Best regards, Brecht

Hi,
Hm, the API ref says this (http://lxml.de/api/lxml.etree._ElementTree-class.html#xinclude): """ xinclude(self) Process the XInclude nodes in this document and include the referenced XML fragments. There is support for loading files through the file system, HTTP and FTP. Note that XInclude does not support custom resolvers in Python space due to restrictions of libxml2 <= 2.6.29. """ But this might actually only cover URI resolving and have nothing to do with element class lookup at all. Have you tried setting objectify's (and etree's?) default parser to your custom objectified parser? S.th. along the lines of parser.set_element_class_lookup(lookup) # set our parser as objectify default parser objectify.set_default_parser(parser) # Set our parser as etree default parser, too. Otherwise etree.Element() # returns etree._Element instead of ObjectifiedElements etree.set_default_parser(parser) ? If this won't work a workaround might be to parse + xinclude with the standard parser and the re-serialize and parse again with a custom-lookup-parser, thought I've never tried this and I don't know if xinclude() puts the included stuff into your including tree. Holger -- NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone! Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

Brecht Machiels, 24.03.2012 22:44:
Only the inserted ones? That sounds unlikely. The lookup is configured at a per-parser level (as you did above), which is inherited by the entire tree. What kind of lookup are you using? Could you provide a self-contained example that shows this behaviour? Stefan

On 26/03/2012 10:02, Stefan Behnel wrote:
Ah, I did not set the namespace on the top-level element of the included file. It's working now. However, it seems comments in the included xml files are not removed, as in the top-level file. See attached files. Again my fault? :) Best regards, Brecht

Hi,
Hm, the API ref says this (http://lxml.de/api/lxml.etree._ElementTree-class.html#xinclude): """ xinclude(self) Process the XInclude nodes in this document and include the referenced XML fragments. There is support for loading files through the file system, HTTP and FTP. Note that XInclude does not support custom resolvers in Python space due to restrictions of libxml2 <= 2.6.29. """ But this might actually only cover URI resolving and have nothing to do with element class lookup at all. Have you tried setting objectify's (and etree's?) default parser to your custom objectified parser? S.th. along the lines of parser.set_element_class_lookup(lookup) # set our parser as objectify default parser objectify.set_default_parser(parser) # Set our parser as etree default parser, too. Otherwise etree.Element() # returns etree._Element instead of ObjectifiedElements etree.set_default_parser(parser) ? If this won't work a workaround might be to parse + xinclude with the standard parser and the re-serialize and parse again with a custom-lookup-parser, thought I've never tried this and I don't know if xinclude() puts the included stuff into your including tree. Holger -- NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone! Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

Brecht Machiels, 24.03.2012 22:44:
Only the inserted ones? That sounds unlikely. The lookup is configured at a per-parser level (as you did above), which is inherited by the entire tree. What kind of lookup are you using? Could you provide a self-contained example that shows this behaviour? Stefan

On 26/03/2012 10:02, Stefan Behnel wrote:
Ah, I did not set the namespace on the top-level element of the included file. It's working now. However, it seems comments in the included xml files are not removed, as in the top-level file. See attached files. Again my fault? :) Best regards, Brecht
participants (3)
-
Brecht Machiels
-
jholg@gmx.de
-
Stefan Behnel