Re: [tDOM] Writing parsed xml document back to a file



Daniel Kirsch wrote:
I want to write a parsed XML document back to a file.

I have:

set courseFile [tDOM::xmlOpenFile $fileName];
dom parse -channel $courseFile courseDoc;

When using
$courseDoc asXML
all header information including the encoding definition are missing.

That's because tDOM can't know what encoding you've configured the output channel to. As you control this (using [chan configure -encoding]), it is up to you to output the appropriate XML header. It's easy enough to do:

proc xmlWriteFile {doc file} {
set out [open $file w]
chan configure $out -encoding utf-8
puts $out "<?xml version='1.0' encoding='utf-8'?>"
puts $out [$doc asXML]
close $out
}

-- Neil
.



Relevant Pages