http://www.perlmonks.org?node_id=836749


in reply to XML::Writer

The above was good for reference .. i had to generate XML in the following format: <games> <game name="chess" players="3" \> <games> ... the <game > tag doesnt have an end tag </game> .. how can i do this using XML writer ??? it would be helpful if u could reply

Replies are listed 'Best First'.
Re^2: XML::Writer
by mirod (Canon) on Apr 26, 2010 at 09:58 UTC

    I can try being helpful, but without your code, it is not that easy...

    That said, are you sure the game tag is not <game name="chess" players="3" /> (with a slash instead of a backslash)? In that case it doesn't need a closing tag. The / before the closing angle bracket means that the tag is empty and should be treated as both an opening and a closing tag. As far as an XML parser is concerned <game name="chess" players="3" /> is equivalent to <game name="chess" players="3"></game>, so the XML you are generating should be OK (did you try checking it with an XML parser?).

Re^2: XML::Writer
by Anonymous Monk on Jul 01, 2013 at 23:43 UTC
    We could use this:
    $writer->emptyTag('game', 'name' => 'chess', 'players' => '3');