Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

XML, the Perl way

branch: master
Octocat-spinner-32 Twig simplified XPath variable processing
Octocat-spinner-32 t fixed tests
Octocat-spinner-32 tools fixed RT #81165, xml_pp preserves original file permissions
Octocat-spinner-32 .gitignore made att and class lvalues
Octocat-spinner-32 Changes fixed tests
Octocat-spinner-32 MANIFEST fixed, tested and documented fix to RT #93604 missing entities when p…
Octocat-spinner-32 META.yml replaced by in the docs
Octocat-spinner-32 MYMETA.json more tests and bug fix on xml_split (now includes the XML declaration)
Octocat-spinner-32 MYMETA.yml more tests on handler order
Octocat-spinner-32 Makefile.PL last changes before 3.45
Octocat-spinner-32 README more tests
Octocat-spinner-32 Update
Octocat-spinner-32 Twig_pm.slow updated version number
Octocat-spinner-32 check_optional_modules refactored used_perl to get the Devel::Cover flag added to it when ne…
Octocat-spinner-32 cover_twig added the -i option (incremental: do not delete the coverage db)
Octocat-spinner-32 doc_latin1.xml YAIC
Octocat-spinner-32 doc_utf8.xml YAIC
Octocat-spinner-32 faq.html more tests and bug fix on xml_split (now includes the XML declaration)
Octocat-spinner-32 faq.xml replaced by in the docs
Octocat-spinner-32 filter_for_5.005 YAIC
Octocat-spinner-32 html2xml YAIC
Octocat-spinner-32 my_pod2html fixed formating
Octocat-spinner-32 speedup cleanup =encoding POD instruction
Octocat-spinner-32 test_all tag#id syntax accepted in handlers and navigation
Octocat-spinner-32 twig_faq replaced by in the docs
Octocat-spinner-32 upd_twig more tests, fixes to _add_or_discard_stored_spaces

    XML::Twig - Tree interface to XML documents allowing processing chunk
                by chunk of huge documents.


SUMMARY (see perldoc XML::Twig for full details)

XML::Twig is (yet another!) XML transformation module. 

Its strong points: can be used to process huge documents while still
being in tree mode; not bound by DOM or SAX, so it is very perlish and
offers a very comprehensive set of methods; simple to use; DWIMs as
much as possible

What it doesn't offer: full SAX support (it can export SAX, but only
reads XML), full XPath support (unless you use XML::Twig::XPath), nor
DOM support.

Other drawbacks: it is a big module, and with over 500 methods available
it can be a bit overwhelming. A good starting point is the tutorial at In fact the whole
XML::Twig page at has plenty of information
to get you started with XML::Twig


XML::Twig comes with a few tools built on top of it:

  xml_pp           XML pretty printer
  xml_grep         XML grep - grep XML files using XML::Twig's subset of XPath
  xml_split        split big XML files
  xml_merge        merge back files created by xml_split
  xml_spellcheck   spellcheck XML files skipping tags

Running perl Makefile.PL will prompt you for each tool installation. 
  perl Makefile.PL -y     will install all of the tools without prompt
  perl Makefile.PL -n     will skip the installation of the tools


  single-tree mode    
    my $t= XML::Twig->new();
    $t->parsefile( 'doc.xml');

  chunk mode 
    # print the document, at most one full section is loaded in memory
    my $t= XML::Twig->new( twig_handlers => { section => \&flush});
    $t->parsefile( 'doc.xml');
    sub flush { (my $twig, $section)= @_; $twig->flush; }
  sub-tree mode 
    # print all section title's in the document,
    # all other elements are ignored (and not stored)
    my $t= XML::Twig->new( 
            twig_roots => { 'section/title' => sub { $_->print, "\n" } }
    $t->parsefile( 'doc.xml');

    perl Makefile.PL
    make test
    make install


    XML::Twig needs XML::Parser (and the expat library) installed
    Modules that can enhance XML::Twig are:

    Scalar::Util or WeakRef 
      to avoid memory leaks
    Encode or Text::Iconv or Unicode::Map8 and Unicode::Strings 
      to do encoding conversions
      to use the keep_atts_order option
      to use XML::Twig::XPath
      to use parseurl
      to use the html_encode filter
      to process HTML instead of XML


    See the Changes file    


    Michel Rodriguez (
    The Twig page is at
    git project repository:
    See the XML::Twig tutorial at


       Copyright (c) 1999-2012, Michel Rodriguez. All Rights Reserved.
       This library is free software; you can redistribute it and/or modify
       it under the same terms as Perl itself.
Something went wrong with that request. Please try again.