[lxml-dev] "Extract" namespace from tag
Hi, I know I had some discussions about this already but in a different context, I think. I'd like to be able to extract the namespace and namespace prefix for an element and it seems I can't do that with the current API (unless I'm overlooking something). Is there a way to make this work? Of course I can just "parse" the tag name for the namespace, but this doesn't give me the namespace prefix used. Andreas -- You will forget that you ever knew me.
Hi Andreas, Andreas Pakulat wrote:
I'd like to be able to extract the namespace and namespace prefix for an element and it seems I can't do that with the current API (unless I'm overlooking something). Is there a way to make this work?
Of course I can just "parse" the tag name for the namespace, but this doesn't give me the namespace prefix used.
The prefix is returned by the "prefix" property on an Element. However, there is currently no direct way to parse a tag name, although IMHO there should be. Maybe we should extend the QName class with "namespace" and "local_name" attributes to provide a way for parsing "{ns}tag" names. Stefan
On 03.06.06 09:11:48, Stefan Behnel wrote:
Hi Andreas,
Andreas Pakulat wrote:
I'd like to be able to extract the namespace and namespace prefix for an element and it seems I can't do that with the current API (unless I'm overlooking something). Is there a way to make this work?
Of course I can just "parse" the tag name for the namespace, but this doesn't give me the namespace prefix used.
The prefix is returned by the "prefix" property on an Element. However, there is currently no direct way to parse a tag name, although IMHO there should be.
Seems I overlooked that one.
Maybe we should extend the QName class with "namespace" and "local_name" attributes to provide a way for parsing "{ns}tag" names.
I think prefix should be in there too. Andreas -- You will triumph over your enemy.
Hi Andreas, Andreas Pakulat wrote:
On 03.06.06 09:11:48, Stefan Behnel wrote:
Maybe we should extend the QName class with "namespace" and "local_name" attributes to provide a way for parsing "{ns}tag" names.
I think prefix should be in there too.
Hmmm, it's easy to say that. However, why should a prefix be part of a qualified tag name? Stefan
On 03.06.06 12:09:54, Stefan Behnel wrote:
Andreas Pakulat wrote:
On 03.06.06 09:11:48, Stefan Behnel wrote:
Maybe we should extend the QName class with "namespace" and "local_name" attributes to provide a way for parsing "{ns}tag" names.
I think prefix should be in there too.
Hmmm, it's easy to say that. However, why should a prefix be part of a qualified tag name?
Well according to the XML Namespace standard it belongs to a QName: http://www.w3.org/TR/REC-xml-names/#ns-qualnames Is that enough? Andreas -- You recoil from the crude; you tend naturally toward the exquisite.
Hi Andreas, Andreas Pakulat wrote:
On 03.06.06 12:09:54, Stefan Behnel wrote:
Andreas Pakulat wrote:
On 03.06.06 09:11:48, Stefan Behnel wrote:
Maybe we should extend the QName class with "namespace" and "local_name" attributes to provide a way for parsing "{ns}tag" names. I think prefix should be in there too. Hmmm, it's easy to say that. However, why should a prefix be part of a qualified tag name?
Well according to the XML Namespace standard it belongs to a QName: http://www.w3.org/TR/REC-xml-names/#ns-qualnames
Is that enough?
Sure, I mixed that up (didn't see the prefix between all those element trees). So, you can pass QNames into Element() and the like. That would be a rather handy way of specifying prefixes for elements without using the nsmap dictionary, I'd say... I'll have to think this through a bit more to see if there are other implications, but I'm close to liking this. Stefan
participants (2)
-
Andreas Pakulat
-
Stefan Behnel