Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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?..

Comment on A Perl module to parse an XML string by string?
Download Code
Re: A Perl module to parse an XML string by string?
by toolic (Chancellor) 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 (Abbot) 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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-08-20 13:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (113 votes), past polls