Re: Naespaces of attributes in python API

[email protected] Wed, 19 Jun 2002 19:53:47 +0200
Newsgroups gmane.comp.gnome.lib.xml.bindings
Message-ID <20020619175347.GC12405@www>
On Wed, Jun 19, 2002 at 01:30:44PM -0400, Daniel Veillard wrote:
> > 
> > Ah, ok. So, if i insert attributes with a naespace that probably doesn't
> > exist in the document in need to add a namespace node to the document
> > first.
> 
>   yes, that's how libxml2 API work :-)
> 
>     def newNs(self, href, prefix):
>         """Creation of a new Namespace. This function will refuse to
>            create a namespace with a similar prefix than an existing
>            one present on this node. We use href==None in the case of
>            an element creation where the namespace was not defined."""

Which brings me to the core of my question (which might be a bit off-topic
on this list): shouldn't prefixing be left to libxml? After all, the namespace
prefix is just a shortcut to the real namespace and doesn't carry any semantic.
Having to provide a prefix for a new namespace seems strange and leads to
code that must test for errors that could be easily avoided:

 # instead of
  
  node.newNs('http://somewhere/over/the/rainbow', 'kansas')

 # we need to do

 done = None
 suff = 0 
 while(not done):
   try:
     node.newNs('http://somewhere/over/the/rainbow', 'pre' + str(suff)) 
     done = 1
   except treeError:
     suff = suff + 1

Ralf attes
  
> Daniel
> 
> -- 
> Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
> [email protected]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
> http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/