[XML-SIG] XML Dom question

Thomas B. Passin tpassin at comcast.net
Wed Sep 15 02:18:17 CEST 2004


John Taylor wrote:

> 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>

With the DOM, you have to create a text node and set its nodeValue to 
the  desired content.  Then you can appendChild() it to its to-be-parent 
node.


Cheers,

Tom P

-- 
Thomas B. Passin
Explorer's Guide to the Semantic Web (Manning Books)
http://www.manning.com/catalog/view.php?book=passin


More information about the XML-SIG mailing list