http://www.perlmonks.org?node_id=872584


in reply to XML Manipulation

How complex are those XPath expression? If they are simple and do not require backtracking, then XML::Twig is ideal for it: set the twig_roots option to a hash <xpath> => 1, then use the twig_print_outside_roots option to output the rest of the XML. See "Building an XML filter" in the docs for an example of that kind of processing, and "twig_handlers" to see the subset of XPath that you can use in this mode.

Alternatively you can use XML::Twig::XPath, parse the file, then go through you list of XPath expressions, use findnodes to get the hits, and delete them.

Beyond XML::Twig, you could try XML::LibXML, which also supports XPath. it is faster and better maintained than XML::XPath. Processing would be the same as above.