Dravidan has asked for the wisdom of the Perl Monks concerning the following question:
Hi Perl Monks, after going through the documentation about the module XML::LibXML::Document,XML::LibXML::Node, i have come up with the latest code,again the expected portion of xml elements from source is getting displaced by the variable $TargetContent but the same is not written to the target file $OutFileName. The Target file is created by the below mentioned way,I ending the write( using $writer->end() ) and closing the target file( using $OutXmlFile->close() ) before calling the function GetMappletList. I hope,this will give more idea about what i am trying to do
my $OutXmlFile = IO::File->new(">$OutFileName"); my $writer = XML::Writer->new(OUTPUT => $OutXmlFile,DATA_MODE=>1,DAT +A_INDENT=>5);
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"); $SourceRoot= $MpltXml->documentElement() +; my @SourceNode = $MpltXml->findnodes("// +MAPPLET"); my $SourceRootNode = $SourceNode[0]; $TargetXml->setDocumentElement( '/POWE +RMART/REPOSITORY/FOLDER' ); #$TargetXml->setDocumentElement( '/POW +ERMART/REPOSITORY/FOLDER' ); $TargetXml->adoptNode($SourceRootNode) +; #$TargetXml->adoptNode('/POWERMART/REP +OSITORY/FOLDER/MAPPLET'); my $TargetContent = $TargetXml->addChi +ld($SourceRootNode); print $TargetContent; } } close(GET_MAPPLET_LIST); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Copy portion of XML elements from one XML file to another exiting XML file
by Corion (Patriarch) on Jan 25, 2014 at 08:26 UTC | |
by Dravidan (Novice) on Jan 25, 2014 at 13:56 UTC | |
by Corion (Patriarch) on Jan 25, 2014 at 15:14 UTC | |
by Dravidan (Novice) on Jan 25, 2014 at 19:55 UTC | |
by Corion (Patriarch) on Jan 25, 2014 at 20:01 UTC | |
|