alf at leo.logilab.fr
Mon Feb 12 15:50:53 CET 2001
In comp.lang.python Venkatesh Prasad Ranganath <rvprasad at cis.ksu.edu> wrote:
> Now if there are no namespaces specified in the document then should attributes
> be added to DOM using
> setAttributeNS('', Name, Value)
> setAttribute(Name, Value)?
Use the first one, definitely. Event better, define a symbolic constant
that you'll call, for example EMPTY_NS, and set it to '' for now. There
has been some discussion about what should be the prefix of empty namespace
on xml-sig ('' or None), and it is likely that it will change from empty
string to None soon (someone corrects me if I'm wrong, please.)
> The problem I am facing is when reading in a XML document with no explicit
> namespace specified in it through PyXML the attributes are added to the DOM
> using setAttributeNS with an empty NameSpace. So, I wanted to clarify if this
> is a problem with PyXML or is this how other DOM Constructors work.
This is what the DOM L2 spec says. It also says that you should not mix
the ns aware and non-ns aware APIs provided in DOM L2. So this means that
you shoud use Document.createElementNS(EMPTY_NS,name) instead of
Document.createElement(name) to create new element nodes.
I hope this helps.
Narval is the first software agent available as free software (GPL).
LOGILAB, Paris (France).
More information about the Python-list