create a XML file with DOM

Juliano Freitas jubafre at atlas.ucpel.tche.br
Mon Oct 25 16:11:26 EDT 2004


Hello!

i'm usin a DOM module to process a xml file. I'm having problems with
the appenChild function. Why in my example below i can't append the
child 'ele' into the swdb.

<swdb>
  <visualinfo/>
</swdb>

Juliano Freitas

=============================================
from xml.dom import *

xmldoc = getDOMImplementation()
print xmldoc

root = xmldoc.createDocument('', 'swdb', '')
root.firstChild

ele = root.createElement('visualinfo')
root.appendChild(ele)

swdb = root.toprettyxml()
print swdb
=============================================

Traceback (most recent call last):
  File "/home/jubafre/teste_dom2.py", line 10, in -toplevel-
    root.appendChild(root.createElement('visualinfo'))
  File "/usr/lib/python2.3/xml/dom/minidom.py", line 1552, in
appendChild
    raise xml.dom.HierarchyRequestErr(
HierarchyRequestErr: two document elements disallowed




More information about the Python-list mailing list