
RégisDécamps, 21.02.2012 17:11:
I understand that custom XML elements should inherit from `ElementBase`.
For instance, I can create
class FactVariable(etree.ElementBase): ''' Class that represents a XBRL fact variable.''' TAG = '{http://xbrl.org/2008/variable}factVariable'
@property def label(self): return self.attrib['{http://www.w3.org/1999/xlink}label']
@label.setter def label(self, value): self.attrib['{http://www.w3.org/1999/xlink}label'] = value
My problem is that when I create a XML tree and place such nodes, I get
<ns0:factVariable xmlns:ns0="http://xbrl.org/2008/variable" label="azerty"/>
**Question**: I want the namespace to be prefixed `va`, not `ns0`
What is your use case for that? I consider prefixes a serialisation detail that is best ignored.
How can I change that?
You can't currently set that on a per-element basis for custom element classes. It also wouldn't change much, because the prefixes are subject to tree normalisation operations, which means that they may still end up inheriting a prefix from a parent at some point. What you can do is to set the prefix on the root element, so that children can inherit it.
I also tried, without success
etree.register_namespace('va', 'http://xbrl.org/2008/variable')
Hmm, that should generally work, though. I wonder why it wouldn't... Stefan