On Jan 17, 2008 5:53 AM, Allam Reddy, Thomas <[EMAIL PROTECTED]> wrote:
snip
> I have got an xml like this below. I want to read this file in Perl and
> want to retrieve the text which end with .xml.
>
> For example , I want to print the text "jms/hppjmsmodules-jms.xml",
> since it ends with .xml
snip
> <descriptor-file-name>jms/hppjmsmodules-jms.xml</descriptor-file-name>
snip

There is a quick and dirty way and a right way.  The quick and dirty
way (which is prone to errors) is

perl -ne 'print "$1\n" if m{([-/.\w]+[.]xml)}' file.xml

The right way is to use an XML parser and look for the contents of the
descriptor-file-name tag.

#!/usr/bin/perl

use strict;
use warnings;
use XML::Twig;

my $t = XML::Twig->new(
        twig_handlers => {
                'descriptor-file-name' => sub {
                        print $_->text, "\n";
                }
        }
);

$t->parsefile($_) for @ARGV;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to