[XML-SIG] XML Dom question

John Taylor john at fcs.uga.edu
Tue Sep 14 16:22:11 CEST 2004


I am trying to insert a new element and value into a XML Dom structure
and am having some trouble.

When I read the file in from disk, I have this:

    <object name='menu__File__Exit' class='wxMenuItem'>
      <label>E_xit</label>
      <event class='EVT_MENU'>On__File__Exit</event>
    </object>

When I run this code:

        w = walker.currentNode
	if "menu__File__Exit" == name and 0 == needs_value and 0 == test:
		myNode = doc.createElement("shortcut_key")
		myNode.setAttribute("modifier","SHIFT")
		w.appendChild( myNode )  
		test = 1

I get this result:

    <object name='menu__File__Exit' class='wxMenuItem'>
      <label>E_xit</label>
      <event class='EVT_MENU'>On__File__Exit</event>
      <shortcut_key modifier='SHIFT'/>
    </object>

This is what I really want:
      <shortcut_key modifier='SHIFT'/>F4</shortcut_key>

Can some one post code on how to do this?  I tried creating a new Node
(called newNode) and setting the nodeType and NodeValue and the use
the appendChild() method, but I keep getting this error:

code:
myNode.appendChild(newNode)

error:
AttributeError: Node instance has no attribute 'childNodes'

Any help would be greatly appreciated!

Thanks,
-John


More information about the XML-SIG mailing list