Posted to tcl by mjanssen at Mon Aug 01 14:10:41 GMT 2022view raw

  1. package require tdom
  2. set xml {
  3. <ns1:Root xmlns="http://default.com" xmlns:ns1="http://some.otherns.com">
  4.  
  5. <ns1:Item>Here be text</ns1:Item>
  6. </ns1:Root>}
  7.  
  8. dom parse $xml doc
  9. set root [$doc childNodes]
  10. set item [$root selectNodes //ns1:Item]
  11. set itemLst [$item asList]
  12. lset itemLst end end end "Other text"
  13. puts [[$root appendFromList $itemLst] asXML]
  14.  
  15.  
  16. # Gives output below. Where does the xmlns="" come from? It seems to be caused by the xmlns in the root element, but one could argue that adding an element in a tree should not override the default namespace
  17.  
  18. <ns1:Root xmlns="http://default.com" xmlns:ns1="http://some.otherns.com">
  19. <ns1:Item>Here be text</ns1:Item>
  20. <ns1:Item xmlns="">Other text</ns1:Item>
  21. </ns1:Root>