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

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?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2016-10-21 15:46 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.