Posted to tcl by mjanssen at Mon Aug 08 17:34:23 GMT 2022view pretty
I want to extend an xml file: <ns1:Root xmlns="http://default.com" xmlns:ns1="http://some.otherns.com"> <ns1:Item>Here be text</ns1:Item> <ns1:Item xmlns="">Other text</ns1:Item> </ns1:Root> Into: <ns1:Root xmlns="http://default.com" xmlns:ns1="http://some.otherns.com"> <ns1:Item>Here be text</ns1:Item> <ns1:Item>Other text</ns1:Item> </ns1:Root> But best I can do is: <ns1:Root xmlns="http://default.com" xmlns:ns1="http://some.otherns.com"> <ns1:Item>Here be text</ns1:Item> <ns1:Item xmlns="">Other text</ns1:Item> </ns1:Root> With the code below. What would be the proper way to get the desired output (without xmlns="") package require tdom set xml { <ns1:Root xmlns="http://default.com" xmlns:ns1="http://some.otherns.com"> <ns1:Item>Here be text</ns1:Item> </ns1:Root>} dom parse $xml doc set root [$doc childNodes] set item [$root selectNodes //ns1:Item] set itemLst [$item asList] lset itemLst end end end "Other text" puts [[$root appendFromList $itemLst] asXML]