Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Adding Elements to XML

by choroba (Canon)
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?

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 lurking in the Monastery: (12)
As of 2015-12-01 17:17 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (21 votes), past polls