Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: I want to find a group of pattern in a xml file

by kubrat (Scribe)
on Sep 16, 2008 at 14:44 UTC ( #711711=note: print w/replies, xml ) Need Help??

in reply to I want to find a group of pattern in a xml file

Or you could just use XML::Simple. Borrowing from toolic's example:

use strict; use warnings; use XML::Simple; my $xfile = <<EOF; <people> <person><name>Jane Doe</name><age>42</age></person> <person><name>John Doe</name><age>43</age></person> <person><name>Foo Bar</name><age>43</age></person> </people> EOF my $people = XMLin($xfile); foreach (keys %{$people->{person}}) { my $person = $people->{person}->{$_}; next if $person->{age} != 43; print "$_ is $person->{age}\n"; } __END__ John Doe is 43 Foo Bar is 43

Replies are listed 'Best First'.
Re^2: I want to find a group of pattern in a xml file
by cybär (Initiate) on Sep 17, 2008 at 08:11 UTC
    But everytime when I use one of the xml parser modules (twig, simple, etc.) I got errors.
    With the code from superdoc I get following error:
    syntax error at line 1, column 0, byte 0 at C:/Perl/site/lib/XML/ line 187
    The only thing I changed, was instead of the $xfile=text, I wrote $xfile="data.xml";
    Why the hell it's so difficult to use the perl xml modules?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2016-10-24 17:18 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (309 votes). Check out past polls.