YOu could also consider XML::Twig. Like Perl it makes simple things simple, and most things possible:
use warnings; use strict; use XML::Twig; my $twig = new XML::Twig; $twig->parse (do {local $/; <DATA>}); for ($twig->descendants ('Hotel')) { my $Hotel_name = $_->{'att'}{'name'} || $_->text; next if ! defined $Hotel_name; my $Hotel_id = $_->{'att'}{'ID'}; print "($Hotel_id) " if defined $Hotel_id; print "$Hotel_name\n"; } __DATA__ <all> <Hotel>Marriott</Hotel> <Hotel ID = "123" name = "Savoy"></Hotel> </all>
Prints:
Marriott (123) Savoy
In reply to Re: XML Parsing
by GrandFather
in thread XML Parsing
by saaz11
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |