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

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]


# 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

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