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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/