XML Dom question
John Taylor
john_taylor_1973 at yahoo.com
Wed Sep 15 07:51:03 EDT 2004
Brett,
This works great. Thanks for responding!
-John
"Humphreys, Brett" <bretth at aiinet.com> wrote in message news:<mailman.3309.1095171613.5135.python-list at python.org>...
> 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
More information about the Python-list
mailing list