Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to output XML declaration line with tdom

25 views
Skip to first unread message

Hai Vu

unread,
Feb 9, 2009, 3:37:25 PM2/9/09
to
Here is a short Tcl program:
package require tdom

set doc [dom parse {<Info><FirstName>Hai</FirstName><LastName>Vu</
LastName></Info>}]

$doc standalone 1
$doc encoding UTF-8
$doc omit-xml-declaration 0

puts "[$doc asXML]"

****************
The actual output:

<Info>
<FirstName>Hai</FirstName>
<LastName>Vu</LastName>
</Info>
****************
How do I change the code so the output is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Info>
<FirstName>Hai</FirstName>
<LastName>Vu</LastName>
</Info>
****************
I have played with the omit-xml-declaration, encoding, standalone
subcommands to no avail. Your help is greatly appreciated. Thank you.

Donal K. Fellows

unread,
Feb 9, 2009, 4:22:20 PM2/9/09
to
On 9 Feb, 20:37, Hai Vu <wuh...@gmail.com> wrote:
> How do I change the code so the output [includes the <?xml...?>]:
[...]

> I have played with the omit-xml-declaration, encoding, standalone
> subcommands to no avail. Your help is greatly appreciated. Thank you.

The simplest technique is to just [puts] the declaration yourself.
That also makes getting the encoding in the decl right easier.

Donal.

Hai Vu

unread,
Feb 9, 2009, 4:27:53 PM2/9/09
to
On Feb 9, 1:22 pm, "Donal K. Fellows" <donal.k.fell...@man.ac.uk>
wrote:

Donal,
Thank you for your suggestion. At this point, it is the only option
for me.
Hai

0 new messages