http://qs321.pair.com?node_id=1045957


in reply to Re: adding XML records using XML::Twig
in thread adding XML records using XML::Twig

How to insert short-form like: <description mydescription /> ? Thanks.
  • Comment on Re^2: adding XML records using XML::Twig

Replies are listed 'Best First'.
Re^3: adding XML records using XML::Twig
by Loops (Curate) on Jul 23, 2013 at 21:44 UTC
    If you pass text as the third argument to insert_new_elt() it will be bracketed by the given element tags. However, if you pass a hash reference, you can instead change the elements attributes. So:
    $insert->insert_new_elt('last_child','description', 'mydescription' ); # creates: <description>mydescription</description> $insert->insert_new_elt('last_child','description', { desc => 'mydescr +iption' } ); # creates: <description desc="mydescription" />
      How to get to <sites> <site info="123"> <description> <descrip descrip1="abc" descrip2="def"/> </description> </site> </sites> Thanks