Re: Save changes in the original XML file



On 11月18日, 下午11时03分, suchenwi <richard.suchenwirth-
bauersa...@xxxxxxxxxxx> wrote:
On 18 Nov., 15:11, "haigang0...@xxxxxxxxx" <haigang0...@xxxxxxxxx>
wrote:

I'm trying to update XML file using DOM. But as the dom-tree is stored
in memory, i found the original XML file is not updated after i
modified the value of certain nodes.
Is there any command that saves changes of nodes into the original XML
file?

In tdom that would be (assoming root is the top documentElement):

set f [open $outfile w]
#-- maybe fconfigure -encoding, write <?xml ...> line
$f puts [$root asXML]
close $f

Check your documentation, I'm quite sure tcldom has similar
functionality.

Thanks a lot.
This does works. But in the updated file, XML declaration is missing.
I also tried like this:
set doc [dom parse [read $f]]
close $f
#configure

set f [open $outfile w]
$doc asXML -channel $f
flush $f
close $f

But XML declaration was also missing.
How to fix this?
Thanks!
.