Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Adding Elements to XML

by choroba (Abbot)
on Nov 21, 2012 at 11:01 UTC ( #1004899=note: print w/ replies, xml ) Need Help??


in reply to Adding Elements to XML

Using XML::XSH2, a wrapper around XML::LibXML:

open 1.xml ; cd /dict ; insert element key prepend . ; set key[1] 'ADDKEY' ; my $array := insert chunk '<array><dict/></array>' after key[1] ; my $key := insert element key into $array/dict ; insert text 'SAMPLEKEY' into $key ; my $array2 := insert element array after $key ; set $array2/string 'STRING' ; delete key[last()] ; xmove :r string[last()] before preceding-sibling::key[1] ; save :b ;
I tried to demonstrate several ways of creating new nodes: via insert and set (more than one node can be created by both, see insert chunk and setting of string).
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Adding Elements to XML
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-04-19 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls