randombox has asked for the wisdom of the Perl Monks concerning the following question:

Nevermind, figured it out. Was an error in code prior to this line. Thanks!
----------------------
Hi Perl Monks, I am writing a small script that uses XML::DOM to create to convert some file into XML. The problem is that when I call setAttribute with a value of 0, the attribute will not show up in the resulting XML.
$s->setAttribute(attrib0, $attr{'a1'}); # or the following $s->setAttribute(attrib0, "0"); $s->setAttribute(attrib1, "0.0"); $s->setAttribute(attrib1, "1"); $s->setAttribute(attrib2, "2");
where $attr{'a1'} = 0 In the example above, attrib0 does not appear in the resulting XML, while attrib1 and attrib2 will show up. Does anyone know about this issue, and whether there is a fix/patch or workaround? Thanks! ml

Replies are listed 'Best First'.
Re: XML::DOM setAttribute issue
by gellyfish (Monsignor) on Jul 19, 2005 at 18:09 UTC

    I think you are going to have to show us more of your surrounding code as there is nothing in the XML::DOM code that would suggest this behaviour and the minimal test case:

    use XML::DOM; + my $d = XML::DOM::Document->new('Test'); my $e = $d->createElement('Foo'); $e->setAttribute('foo',0); $d->appendChild($e); print $d->toString();
    works fine here with 1.43 of the module.

    /J\