Hi Rob, Thank you for that input. I was also enable to successfully complete the same with the below script. (its a mix up from various scripts :D)
$file1 ="XXXX"; # input file $file2="XXXX.new"; my $flag=0; #output file open(INFO,"$file1"); # Open the first file open(OUT,">$file2"); # open the second file my $t2="\/resource-ref>"; chomp ($t2); while (my $line=<INFO>) { chomp($line1); if ($line =~ /<resource-ref/ and $line =~ /DataSource_/ and $flag==0) { print "$line\n"; #print OUT "$line"; $flag=1; }elsif ($line =~ /$t2/ and $flag==1) { $flag=0; }elsif ( $flag==0) { print OUT "$line"; } } close(INFO); close(OUT); Depending on what i give as param for t1 and t2 i will be able to manipulate what i want to delete. I am just posting this as there may be a possibility someone may not be able to use the libraries. On 7/4/08, Rob Dixon <[EMAIL PROTECTED]> wrote: > > life is beautiful wrote: > > Hi All, > > Can some one help me gain knowledge as how I can > > delete few lines from XML. > > > > Example > > <resource-ref id="ResourceRef_LSSimulator_DataSource_3"> > > <res-ref-name>java:/LockTestDb</res-ref-name> > > <res-type>javax.sql.DataSource</res-type> > > <res-auth>Application</res-auth> > > <res-sharing-scope>Shareable</res-sharing-scope> > > </resource-ref> > > <resource-ref id="ResourceRef_LSSimulator_WorkManager_1"> > > <res-ref-name>wm/default</res-ref-name> > > <res-type>com.ibm.websphere.asynchbeans.WorkManager</res- > > type> > > <res-auth>Container</res-auth> > > <res-sharing-scope>Shareable</res-sharing-scope> > > </resource-ref> > > > > > > Here I need to delete Only > > <resource-ref id="ResourceRef_LSSimulator_DataSource_3"> > > <res-ref-name>java:/LockTestDb</res-ref-name> > > <res-type>javax.sql.DataSource</res-type> > > <res-auth>Application</res-auth> > > <res-sharing-scope>Shareable</res-sharing-scope> > > </resource-ref> > > Meaning .. I need to delete the tag for Datasource occurance. > > Any help will be appreciated > > If you have no preference as to which library you use to handle XML then I > recommend XML::LibXML. > > The XML sample you show isn't well-formed, as it has two root nodes. The > program > below does what you want, but I have enclosed your data in a single <doc> > element. > > HTH, > > Rob > > > use strict; > use warnings; > > use XML::LibXML; > > my $parser = XML::LibXML->new; > > my $doc = $parser->parse_fh(\*DATA); > > my @nodes = > > $doc->findnodes('/doc/[EMAIL > PROTECTED]"ResourceRef_LSSimulator_DataSource_3"]'); > > $_->unbindNode foreach @nodes; > > print $doc->serialize; > > __DATA__ > <doc> > <resource-ref id="ResourceRef_LSSimulator_DataSource_3"> > <res-ref-name>java:/LockTestDb</res-ref-name> > <res-type>javax.sql.DataSource</res-type> > <res-auth>Application</res-auth> > <res-sharing-scope>Shareable</res-sharing-scope> > </resource-ref> > <resource-ref id="ResourceRef_LSSimulator_WorkManager_1"> > <res-ref-name>wm/default</res-ref-name> > <res-type>com.ibm.websphere.asynchbeans.WorkManager</res-type> > <res-auth>Container</res-auth> > <res-sharing-scope>Shareable</res-sharing-scope> > </resource-ref> > </doc> > > > **OUTPUT** > > <?xml version="1.0"?> > <doc> > > <resource-ref id="ResourceRef_LSSimulator_WorkManager_1"> > <res-ref-name>wm/default</res-ref-name> > <res-type>com.ibm.websphere.asynchbeans.WorkManager</res-type> > <res-auth>Container</res-auth> > <res-sharing-scope>Shareable</res-sharing-scope> > </resource-ref> > </doc> > > Tool completed successfully >