Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: XML Parsing

by reneeb (Chaplain)
on Feb 02, 2006 at 00:16 UTC ( [id://527196]=note: print w/replies, xml ) Need Help??


in reply to XML Parsing

And with XML::LibXML...

use warnings; use strict; use XML::LibXML; my $parser = new XML::LibXML; my $tree = $parser->parse_file('hotels.xml'); my $root = $tree->getDocumentElement(); for ($root->getElementsByTagName('hotel')){ my $Hotel_name = $_->getAttribute('name') || $_->getData(); next if ! defined $Hotel_name; my $Hotel_id = $_->getAttribute('ID'); print "($Hotel_id) " if defined $Hotel_id; print "$Hotel_name\n"; }

hotels.xml:
<all> <Hotel>Marriott</Hotel> <Hotel ID = "123" name = "Savoy"></Hotel> </all>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://527196]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found