Posted to tcl by mjanssen at Mon Aug 08 17:34:23 GMT 2022view raw

  1. I want to extend an xml file:
  2.  
  3. <ns1:Root xmlns="http://default.com" xmlns:ns1="http://some.otherns.com">
  4. <ns1:Item>Here be text</ns1:Item>
  5. <ns1:Item xmlns="">Other text</ns1:Item>
  6. </ns1:Root>
  7.  
  8. Into:
  9.  
  10. <ns1:Root xmlns="http://default.com" xmlns:ns1="http://some.otherns.com">
  11. <ns1:Item>Here be text</ns1:Item>
  12. <ns1:Item>Other text</ns1:Item>
  13. </ns1:Root>
  14.  
  15.  
  16. But best I can do is:
  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>
  22.  
  23. With the code below. What would be the proper way to get the desired output (without xmlns="")
  24.  
  25. package require tdom
  26. set xml {
  27. <ns1:Root xmlns="http://default.com" xmlns:ns1="http://some.otherns.com">
  28. <ns1:Item>Here be text</ns1:Item>
  29. </ns1:Root>}
  30.  
  31. dom parse $xml doc
  32. set root [$doc childNodes]
  33. set item [$root selectNodes //ns1:Item]
  34. set itemLst [$item asList]
  35. lset itemLst end end end "Other text"
  36. puts [[$root appendFromList $itemLst] asXML]