in reply to empty element with xml::smart

Can you do <element></element>? That's exactly the same thing as <element/>.

Replies are listed 'Best First'.
Re^2: empty element with xml::smart
by ikegami (Patriarch) on Mar 18, 2008 at 06:36 UTC

    Installed the module... It actually produces <element/> for empty elements:

    use XML::Smart qw( ); my $xml = XML::Smart->new(); $xml->{foo}{bar}{empty} = {}; print scalar $xml->data();
    <?xml version="1.0" encoding="iso-8859-1" ?> <?meta name="GENERATOR" content="XML::Smart/1.6.8 Perl/5.008008 [MSWin +32]" ?> <foo> <bar> <empty/> </bar> </foo>

    If you use a DTD, then you need to specify the "EMPTY" keyword or else it'll generate <empty></empty> (which is fine cause it means the same thing).

    use XML::Smart qw( ); my $xml = XML::Smart->new(); $xml->{foo}{bar}{empty} = {}; $xml->apply_dtd(<<'__EOI__'); <!DOCTYPE foo [ <!ELEMENT foo (bar*)> <!ELEMENT bar (empty*)> <!ELEMENT empty EMPTY> ]> __EOI__ print scalar $xml->data();
      thanks for the reply/solution. i was trying '' and undef as source values (from the db) for xml::smart, that didnt work the way i expected perl to work. sure, the empty hash, i should have tried that too. thanks for help!