in reply to How to remove empty XML elements using XML::LibXML
#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $xml = XML::LibXML->load_xml( location => '1.xml'); my $xpc = XML::LibXML::XPathContext->new($xml); $xpc->registerNs('contact', 'urn:ietf:params:xml:ns:contact-1.0'); for my $name (qw(rem add)) { for my $node ($xpc->findnodes("//contact:$name".'[not(*|text()|@*| +processing-instruction()|comment())]', $xml->documentElement)) { $node = $node->parentNode->removeChild($node); } } print $xml->serialize;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to remove empty XML elements using XML::LibXML
by FreakyGreenLeaky (Sexton) on Feb 18, 2013 at 04:23 UTC | |
by choroba (Cardinal) on Feb 18, 2013 at 08:46 UTC | |
by FreakyGreenLeaky (Sexton) on Feb 18, 2013 at 16:52 UTC |