Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: adding XML records using XML::Twig

by murugu (Curate)
on Aug 26, 2010 at 01:59 UTC ( #857350=note: print w/replies, xml ) Need Help??


in reply to adding XML records using XML::Twig

#!/usr/bin/perl -w use strict; my $sitefile='/app/sites.xml'; my $twig=new XML::Twig; $twig -> parsefile($sitefile); my %hash = (name=>"name3",address=>"address3",contact=>"contact3"); my $root=$twig->root; my $insert = $root->insert_new_elt('last_child', site => {siteid=>"THR +EE"}); foreach my $element (keys %hash){ $insert->insert_new_elt('last_child',$element,$hash{$element}) } $root->print;

Regards,
Murugesan Kandasamy
use perl for(;;);

Replies are listed 'Best First'.
Re^2: adding XML records using XML::Twig
by Anonymous Monk on Jul 23, 2013 at 21:22 UTC
    How to insert short-form like: <description mydescription /> ? Thanks.
      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://857350]
help
Chatterbox?
[ambrus]: Eily: also webpages aren't displayed on my monitor no matter what I click with the mouse, and there's a blackout right now, could that be a problem?
[robby_dobby]: ambrus: Yes
[hippo]: erix++: "the browser ate my code"
[robby_dobby]: Eily: Now, people are trying to be inventive with crowdsourcing their work, eh? Sure, call on the admins to k-line these sockpuppet accounts!
[robby_dobby]: hippo: I like how you equated your browser to a dog....
[Eily]: well, Anonymonk is everyone's sockpuppet :D

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2017-04-25 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (454 votes). Check out past polls.