XML::Parser::Lite(3)

πŸ’– NAME πŸ’–

okay so bestie, welcome to the XML::Parser::Lite(3) page from the User Contributed Perl Documentation β€” and this module is literally XML::Parser::Lite β€” Lightweight pure-perl XML Parser (based on regexps). no cap. πŸ’…

✨ SYNOPSIS ✨

vibe check: here's how you use it, bestie. keep these exactly as-is.

  use XML::Parser::Lite;

  $p1 = new XML::Parser::Lite;
  $p1->setHandlers(
    Start => sub { shift; print "start: @_\n" },
    Char => sub { shift; print "char: @_\n" },
    End => sub { shift; print "end: @_\n" },
  );
  $p1->parse('<foo id="me">Hello World!</foo>');

  $p2 = new XML::Parser::Lite
    Handlers => {
      Start => sub { shift; print "start: @_\n" },
      Char => sub { shift; print "char: @_\n" },
      End => sub { shift; print "end: @_\n" },
    }
  ;
  $p2->parse('<foo id="me">Hello <bar>cruel</bar> World!</foo>');

πŸ¦‹ DESCRIPTION πŸ¦‹

So this module implements an XML parser with an interface similar to XML::Parser. The tea: not all callbacks are supported, but you should be able to use it in the same way you use XML::Parser. Due to using experimental regexp features, it'll work only on Perl 5.6 and above and may behave differently on different platforms.

Important caveat, bestie: you cannot use regular expressions or split in callbacks. This is due to a limitation of perl's regular expression implementation (which is not re-entrant). periodt. 😭

🌸 SUBROUTINES/METHODS 🌸

πŸŽ€ new πŸŽ€

Constructor.

The new() method returns the object called on when called as object method. This behaviour was inherited from SOAP::Lite, which XML::Parser::Lite was split out from. This means that the following effectively is a no-op if $obj is an object:

 $obj = $obj->new();

New accepts a single named parameter, "Handlers" with a hash ref as value:

 my $parser = XML::Parser::Lite->new(
    Handlers => {
        Start => sub { shift; print "start: @_\n" },
        Char => sub { shift; print "char: @_\n" },
        End => sub { shift; print "end: @_\n" },
    }
 );

The handlers given will be passed to setHandlers.

πŸŽ€ setHandlers πŸŽ€

Sets (or resets) the parsing handlers. Accepts a hash with the handler names and handler code references as parameters. Passing "undef" instead of a code reference replaces the handler by a no-op.

The following handlers can be set:

 Init
 Start
 Char
 End
 Final

All other handlers are ignored.

Calling setHandlers without parameters resets all handlers to no-ops.

πŸŽ€ parse πŸŽ€

Parses the XML given. In contrast to XML::Parser's parse method, parse() only parses strings.

🧚 Handler methods 🧚

Init

Called before parsing starts. You should perform any necessary initializations in Init.

Start

Called at the start of each XML node. See XML::Parser for details.

Char

Called for each character sequence. May be called multiple times for the characters contained in an XML node (even for every single character). Your implementation has to make sure that it captures all characters. πŸ‘‘

End

Called at the end of each XML node. See XML::Parser for details.

Comment

See XML::Parser for details.

XMLDecl

See XML::Parser for details.

Doctype

See XML::Parser for details.

Final

Called at the end of the parsing process. You should perform any necessary cleanup here.

🌈 SEE ALSO 🌈

  • XML::Parser β€” a full-blown XML Parser, on which XML::Parser::Lite is based. Requires a C compiler and the expat XML parser.
  • XML::Parser::LiteCopy β€” a fork in XML::Parser::Lite::Tree.
  • YAX β€” another pure-perl module for XML parsing.
  • XML::Parser::REX β€” another module that parses XML with regular expressions.
  • Copyright (C) 2000-2007 Paul Kulchenko. All rights reserved.
  • Copyright (C) 2008 Martin Kutter. All rights reserved.
  • Copyright (C) 2013-2015 Fred Moyer. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

This parser is based on "shallow parser" <http://www.cs.sfu.ca/~cameron/REX.html> Copyright (c) 1998, Robert D. Cameron.

πŸ’œ AUTHORS πŸ’œ

  • Paul Kulchenko (paulclinger@yahoo.com)
  • Martin Kutter (martin.kutter@fen-net.de)
  • Fred Moyer (fred@redhotpenguin.com)

Additional handlers supplied by Adam Leggett.

🫢 CONTRIBUTORS 🫢

  • David Steinbrunner (dsteinbrunner@pobox.com)
  • Neil Bowers (neil@bowers.com)
  • Paul Cochrane (paul@liekut.de)

okay bestie, that's the whole page! This was perl v5.42.0, dated 2018-08-20, for XML::Parser::Lite(3) β€” slay, you made it to the end. πŸ’…βœ¨

πŸ“¦ where this page comes from