[XML-SIG] Why do I have twice the same attribute? or is it encoding?

Thomas B. Passin tpassin@home.com
Sun, 9 Dec 2001 18:11:39 -0500


[<horst@freedict.de>]
To: <xml-sig@python.org>
Sent: Sunday, December 09, 2001 1:09 PM
Subject: [XML-SIG] Why do I have twice the same attribute? or is it
encoding?


> Hello,
>
> I am a bit stuck here. - I tried to find some documenation on it, but
> did not find very much on DOM (attribute) handling anyway.
>
> My problem is, that I read in the given XML, and wish to query the
> attributes from "entry", and depending on the value modify it, and store
> the modified XML into a string. However, when doing this, I receive two
> attributes ("author"), with diffent values. I even tried to delete it
> first, but that did not work.
>
> Can anyone help me?
>
> Is my problem related to some internal representation of the data?
>
>

This has disclosed quite several inconsistencies to me.  Some of them have
been changed in the CVS, I think, but some may not have been.

This immediate solution to your problem, using pyxml version 0.6.6, is to
use the "namespace" (i.e., SAX2) methods.  This achieves what you want:

if Root1.getAttributeNS('','author'):
    Roo11.removeAttributeNS('',"author")

In other words, with the default namespace feature in play - which it is
since you didn't change it -, you need the "NS" version, and since there is
no namespace you use '' (that should be changed by now in the CVS to use
None instead of '').  With getAttribute(), the attribute is not found so it
is not removed.

Since you went to the trouble to retrieve Entry1, Root1 in the above should
be replaced by Entry1 (after you adjust it as shown below), although Root1
happens to work here because this particular element is the root element.

Also, you really should use

Entry1 = DOM1.getElementsByTagName('entry')[0]

or even

Entry1 = list(DOM1.getElementsByTagName('entry'))[0]

instead of what you had.

But here are some of the things I noticed, and I hope someone who knows the
DOM better can answer them:

1)  Why does getElementsByTagName() work when getAttribute() does not?
Seems like either you should need the NS version for both or you shouldn't
need it for both.

2) When is documentElement supposed to be a namespace version node, and when
is it not?  Is this tied to the namespace feature?

3) Does this code build non-namespaced element nodes but namespaced
attribute nodes?  If so, it needs to be fixed.

Cheers,

Tom P