Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Adding Elements to XML

by choroba (Chancellor)
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).
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004899]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2016-12-08 15:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (143 votes). Check out past polls.