![](https://secure.gravatar.com/avatar/bc4259003fffe3e1cb3543db975bea0d.jpg?s=120&d=mm&r=g)
Hi, I think it would be nice to modify lxml's fine namespace extensions mechanisms to allow for using a custom element class for every element regardless of its namespace, if no specialized namespace registry has been defined for a namespace. Something along the lines of (diff based on lxml 1.0.1 nsclasses.pxi): $ diff -c ../../lxml-1.0.1/src/lxml/nsclasses.pxi src/lxml/nsclasses.pxi *** ../../lxml-1.0.1/src/lxml/nsclasses.pxi Thu Jun 8 16:18:04 2006 --- src/lxml/nsclasses.pxi Fri Jun 23 12:16:59 2006 *************** *** 33,38 **** --- 33,43 ---- _ClassNamespaceRegistry(ns_uri) return registry + def DefaultNamespace(): + """Retrieve the namespace object associated with the default namespace URI + ('*'). Creates a new default if it does not yet exist.""" + return Namespace('*') + def FunctionNamespace(ns_uri): """Retrieve the function namespace object associated with the given URI. Creates a new one if it does not yet exist. A function namespace can *************** *** 188,194 **** dict_result = python.PyDict_GetItem( __NAMESPACE_REGISTRIES, None) if dict_result is NULL: ! return _Element registry = <_NamespaceRegistry>dict_result classes = registry._entries --- 193,203 ---- dict_result = python.PyDict_GetItem( __NAMESPACE_REGISTRIES, None) if dict_result is NULL: ! dict_result = python.PyDict_GetItemString( ! __NAMESPACE_REGISTRIES, '*') ! ! if dict_result is NULL: ! return _Element registry = <_NamespaceRegistry>dict_result classes = registry._entries Of course one would have to think about what default registry key/URI to use for the fallback, I simply took '*'. Comments? Holger Note: This stems from a question I wrote in thread '"even-more-pythonic" API on top of lxml' "Holger Joukl" <Holger.Joukl@LBBW.de> schrieb am 22.06.2006 16:35:40:
Hi,
Stefan Behnel <behnel_ml@gkec.informatik.tu-darmstadt.de> schrieb am 22.06.2006 12:57:22:
Have a look here, that should get you going: http://codespeak.net/lxml/namespace_extensions.html
Thanks! Simply overlooked that part of the documentation. Can I get this mechanism to always return custom elements regardless of the namespace, without having to register the custom element class for every possible namespace?
I guess some ns-uri wildcard would have to be introduced ('*' ?) and the custom element registered for the wildcard, with an additional check for a wildcard registry in _find_element_class. Right?
Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde, verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version.