johnph has asked for the wisdom of the Perl Monks concerning the following question:

hi being a neophyte with perl and xml. I am looking/trying to understand the best way to copy some xml data from one file into a 2nd file, using a template. Which may not have all the same tags and/or more tags than the orignal file. Thanks john

Replies are listed 'Best First'.
Re: perl xml data copy
by gellyfish (Monsignor) on Oct 28, 2004 at 12:40 UTC

    You have a number of options. For instance you load the file into a datastructure using XML::Simple then fiddle around with the structure and save it again, you can use XML::Twig to load and manipulate the file and save it again, or you could use XSLT to transform the document without fiddling with the data in perl. The latter seems to fir your requirement for a template better.

    /J\

Re: perl xml data copy
by samtregar (Abbot) on Oct 28, 2004 at 15:59 UTC
    Please be more specific. How much data do you have? How complex is your tag structure? Are you using namespaces? More than one? Do you know the encoding of the source? Will it be the same in the target? Is performance important? Is memory usage important?

    The answers to these questions (and more) will determine the best solution to your problem.

    -sam

      This is a example of some of data that needs to be copied <userdata> <aaa aaa.1.bbb="" aaa.1.ccc="" aaa.1.ddd="" aaa.1.eee="private" aaa.2.bbb="" aaa.2.ccc="" aaa.2.ddd="" aaa.2.eee="private" aaa.3.bbb="" aaa.3.ccc="" aaa.3.ddd="" aaa.3.eee="private" /> <user> <donot call.donot.per="0"/> <automail call.automail.1.enabled="0" call.automail.1.contact="" call.automail.2.enabled="0" call.automail.2.contact="" call.automail.3.enabled="0" call.automail.3.contact="" /> <DataRebuild call.DataRebuild.1.enabled="0" call.DataRebuild.2.enabled="0" call.DataRebuild.3.enabled="0" /> </user> <msg msg.bypass="0"> <msgAlert msg.Alert.1.subscribe="" msg.Alert.1.Block="registration" msg.Alert.1.callBack="" msg.Alert.2.subscribe="" msg.Alert.2.Block="disabled" msg.Alert.2.callBack="" msg.Alert.3.subscribe="" msg.Alert.3.Block="disabled" msg.Alert.3.callBack="" /> </msg> </userdata>
        That doesn't answer any of my questions!

        -sam