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

horst@freedict.de horst@freedict.de
Sun, 9 Dec 2001 19:09:18 +0100 (CET)


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?


- I did not find much information on the topic on the net. - is there a
  book to reccomend?

Thanks in advance,


Horst

<code>


#!/usr/bin/env python

from xml.dom import ext
from xml.dom.ext.reader import Sax2
from xml.dom import Node, Comment
from xml import xpath
from xml.xpath import Util
from Ft.Lib.pDomlette import PyExpatReader
from StringIO import StringIO

content = """<?xml version="1.0" encoding="UTF-8"  ?>
 
<!DOCTYPE entry       SYSTEM "-//FreeDict 1A//FreeDict dictionary, base on TEI P3//EN//XML">
      <entry dictionary="nld-eng"
             version = "1"
             author="HEY2">
        <form>
          <orth>Aalbeer2</orth>
          <orth>Allbeere</orth>
        </form>
        <trans>
          <tr>wartees1</tr>
          <tr>zwarte</tr>
        </trans>
      </entry>"""


DOM1 = Sax2.FromXml(content)
Root1 = DOM1.documentElement

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

if Root1.getAttribute('author'):
    print "delete it"
    Root1.removeAttribute("author")

Root1.setAttribute("author", "HEY")

version = Root1.getAttributeNode("author")

for at in Root1.attributes:
    print at.name
print

from StringIO import StringIO
stream = StringIO()
ext.PrettyPrint(Root1, stream=stream)
Definition = stream.getvalue()
stream.close()

print Definition



</code>


-- 
Horst@freedict.de
Horst Eyermann 
Germany

You need a dictionary? - visit http://www.freedict.de
for free (GPL) dictionaries (unix; windows work in progress)
For windows, visit http://www.freedict.de/wbuch

A article (in German) about dictionary efforts on the net
http://www.heise.de/tp/deutsch/inhalt/on/5927/1.html