Here is my updated code, i am able to print the exact node and associated sub elements i want to copy but how can i write the content of $node which is also getting printed in the output to the target file

sub GetMappletList { my $Target_node; my ($TableNm,$ColumnNm,$DomainNm,$AlgoNm); my @MaskingAlgorithmList; my @MappletNode; my $MpltRefFile_Dir = shift; my $MappletXmlName; open GET_MAPPLET_LIST, "<","$Profiler_Dir/$MpltRefFile_Dir/Inve +ntory.rpt" or die "ERROR : Couldn't Open $Profiler_Dir/$MpltRefFile_D +ir/Inventory.rpt $!"; while (my $InvtoryCol = <GET_MAPPLET_LIST> ) { chomp $InvtoryCol; ($TableNm,$ColumnNm,$DomainNm,$AlgoNm) = split(/ +,/,$InvtoryCol); if ($TableNm =~ /$SourceTableName/) { print " The Workflow xml nme is $OutFile +Name\n"; $MappletXmlName = "$Mapplet_Dir/$AlgoNm. +XML"; print "The Dir name is $MappletXmlName\n +"; my $MpltParser = XML::LibXML->new(); my $TargetXml = $MpltParser ->parse_file +("$OutFileName"); my $MpltXml = $MpltParser->parse_file("$ +MappletXmlName"); my @MappletNode = $MpltXml->findnodes( +'//MAPPLET'); for my $node (@MappletNode) { print $node->toString(1 +); } } } close(GET_MAPPLET_LIST); }

The source file content is given below

<?xml version="1.0" encoding="Windows-1252"?> <!DOCTYPE POWERMART SYSTEM "powrmart.dtd"> <POWERMART CREATION_DATE="01/24/2014 18:27:23" REPOSITORY_VERSION="181 +.90"> <REPOSITORY NAME="xyz" VERSION="181" CODEPAGE="MS1252" DATABASETYPE="O +racle"> <FOLDER NAME="DM_POC" GROUP="" OWNER="Administrator" SHARED="NOTSHARED +" DESCRIPTION="" PERMISSIONS="rwx---rwx" UUID="c08574eb-cdf5-4bd1-bda +0-d08519348c79"> <MAPPLET DESCRIPTION ="" ISVALID ="YES" NAME ="mplt_Key_Lkp_NID" O +BJECTVERSION ="1" VERSIONNUMBER ="1"> *****----THERE ARE COUPLE of OTHER SUB ELEMENTS WHICH ARE NOT GIVEN HE +RE------**** </MAPPLET> </FOLDER> </REPOSITORY> </POWERMART>

The Target xml file content looks like the below one

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE POWERMART SYSTEM "powrmart.dtd"> <POWERMART CREATION_DATE="1/25/2014 14:39:55" REPOSITORY_VERSION="181. +90"> <REPOSITORY NAME="rep_brcls_punapp830" VERSION="181" CODEPAGE="MS +1252" DATABASETYPE="Oracle"> <FOLDER NAME="DM_POC" GROUP="" OWNER="Administrator" SHARED= +"NOTSHARED" DESCRIPTION="" PERMISSIONS="rwx---rwx" UUID="c08574eb-cdf +5-4bd1-bda0-d08519348c79"> <SOURCE BUSINESSNAME="" DATABASETYPE="Flat File" DBDNAM +E="Flat_File" DESCRIPTION="" NAME="sample" OBJECTVERSION="1" OWNERNAM +E="" VERSIONNUMBER="1"> <FLATFILE CODEPAGE="US-ASCII" CONSECDELIMITERSASON +E="NO" DELIMITED="YES" DELIMITERS="," ESCAPE_CHARACTER="" KEEPESCAPEC +HAR="NO" LINESEQUENTIAL="NO" MULTIDELIMITERSASAND="NO" NULLCHARTYPE=" +ASCII" NULL_CHARACTER="*" PADBYTES="1" QUOTE_CHARACTER="NONE" REPEATA +BLE="NO" ROWDELIMITER="10" SHIFTSENSITIVEDATA="NO" SKIPROWS="0" STRIP +TRAILINGBLANKS="NO" /> ******-----SOMETHING HERE ,THEY ARE NOT GIVEN AS THEY ARE TOO BIG----- +------***** </SOURCE> </FOLDER> </REPOSITORY> </POWERMART>

I want to copy everything between the tags <MAPPLET> </MAPPLET> from source xml to target xml file and the copied content should be placed in the target, between <FOLDER> </FOLDER> tags

I am totally lost myself in finding correct solution to make this work, Please advise me how can i fix it?


In reply to Re^4: Copy portion of XML elements from one XML file to another exiting XML file by Dravidan
in thread Copy portion of XML elements from one XML file to another exiting XML file by Dravidan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.