prefix_objectify - a better lxml.objectify : progress report
Dear lxml people! You may have noticed that I am working on a better lxml.objectify. I have not decided yet on a final name for this so lets name it "prefix_objectify" in the meanwhile. This name reflects on its aim - to include the ns-prefix information into the Python property name. Motivation: If I have a ISO19139 snipplet |<gmd:MD_Metadata xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco" > <gmd:fileIdentifier> <gco:CharacterString>2ce585df-df23-45f6-b8e1-184e64e7e3b5</gco:CharacterString> </gmd:fileIdentifier> <gmd:language> <gmd:LanguageCode codeList="https://www.loc.gov/standards/iso639-2/" codeListValue="ger">ger</gmd:LanguageCode> </gmd:language> </gmd:MD_Metadata> | lxml is not capable to expose the |gco:CharacterString as a Python property.| |https://stackoverflow.com/questions/71212909/python-lxml-objectify-gives-no-... | So I decided to come up with a better solution including the namespace-prefix into the Python property name (as all other frameworks dealing with qualified names are doing). So |gco:CharacterString will be exposed as a Python property '|||gco_CharacterString'.|| Even the recent discussion on the flaws of lxml.objectify is rather controversical. So I decided to contribute "prefix_objectify" as different python package/project and not as a fork of LXML to avoid a clash. The usage of "prefix_objectify" should be as easy as : from lxml.objectify import ObjectifyElementClassLookup from lxml import etree from prefix_objectify import PrefixObjectifiedElement obj2_lookup = ObjectifyElementClassLookup(tree_class=PrefixObjectifiedElement) parser = etree.XMLParser() parser.set_element_class_lookup(obj2_lookup) node = etree.parse('4157d397-e2c3-4e6e-8a84-0712aa9c1162.xml', parser=parser).getroot() ATM while I do reverse engineering of the lxml.objectify code it is more convenient to make a fork first. This is e.g. due to the lack of pxd-file describing lxml.objectify. My fork of lxml lives here https://github.com/Inqbus/lxml/tree/objectify_prefix in the branch 'objectify_prefix'. Around half of the tests are running good. This is after hour work in progress and I welcome any feedback or contribution. Cheers, Volker -- ========================================================= inqbus Scientific Computing Dr. Volker Jaenisch Hungerbichlweg 3 +49 (8860) 9222 7 92 86977 Burggenhttps://inqbus.de =========================================================
participants (1)
-
Dr. Volker Jaenisch