XML Dom question

Humphreys, Brett bretth at aiinet.com
Tue Sep 14 16:20:01 CEST 2004


John, you actually would add a text node to your 'myNode' object.  For
example:

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

It should create output such as:

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

-Brett

-----Original Message-----
From: python-list-bounces+bretth=aiinet.com at python.org
[mailto:python-list-bounces+bretth=aiinet.com at python.org] On Behalf Of
John Taylor
Sent: Tuesday, September 14, 2004 10:06 AM
To: python-list at python.org
Subject: XML Dom question


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
-- 
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list