Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

A Perl module to parse an XML string by string?

by Doctrin (Beadle)
on Dec 21, 2012 at 17:22 UTC ( #1009941=perlquestion: print w/replies, xml ) Need Help??
Doctrin has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone! Could anyone tell if there is a Perl XML parser that reads input XML file string by string, not the whole at once?.. The reason of such question is - I have a real big XML, about 1G, and want Perl to find all "id" attributes of nodes with a particular path, say, "root/mynode":
<root> blah-blah, some nodes here <mynode id=500> and some nodes here also </mynode> ... blah-blah, some nodes here <mynode id=500> and some nodes here also </mynode> </root>
Thanks in advance for your help P.S. Does XML::XPath do so?..

Replies are listed 'Best First'.
Re: A Perl module to parse an XML string by string?
by toolic (Bishop) on Dec 21, 2012 at 17:40 UTC
    XML::Twig "A perl module for processing huge XML documents in tree mode."
      Thank you! That is just what I need.
Re: A Perl module to parse an XML string by string?
by runrig (Abbot) on Dec 21, 2012 at 18:24 UTC
    An example with XML::Rules
    use XML::Rules; my $xml = <<XML; <root> <mynode id='500'> </mynode> <mynode id='500'> </mynode> </root> XML my @rules = ( # Only get 'mynode' directly under root mynode => [ '/root' => sub { print "$_[1]->{id}\n"; return }, _defau +lt => undef ], _default => undef, ); my $xr = XML::Rules->new(rules => \@rules); $xr->parse($xml);
Re: A Perl module to parse an XML string by string?
by choroba (Chancellor) on Dec 22, 2012 at 13:25 UTC
    You can use XML::LibXML::Reader.

    Note that your example XML is not well formed: attribute values must be enclosed in single or double quotes.

    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1009941]
Approved by Corion
help
Chatterbox?
[shmem]: you can break up the chain MP3::Tag->new($_)- >interpolate("\%S ") and test whether MP3::Tag->new($_) is true
[Lady_Aleena]: shmem, no to deletion.
[shmem]: can't help you there since that song is not on my bench
[Lady_Aleena]: shmem, I need to look at MP3::Tag to see how to get the date from one song.
shmem sticks himself into the envelope. gn.(1<<3) all

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2017-04-23 22:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.