Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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


Comment on Re: I want to find a group of pattern in a xml file
Download Code
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/Parser.pm 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-12-23 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (135 votes), past polls