in reply to Re: How to remove empty XML elements using XML::LibXML
in thread How to remove empty XML elements using XML::LibXML
Thanks - that works perfectly when operating on 1.xml or another XML document object.
Your sample uncovered another layer/problem:
my XML document comes from Net::EPP::Frame (cpan.org says "This module implements a subclass of the XML::LibXML::Document..."), so I'm doing something wrong when I try:use Net::EPP::Frame; my $frame = Net::EPP::Frame::Command::Update::Contact->new; #... my $xpc = XML::LibXML::XPathContext->new($frame); $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())]', $frame->documentElement)) +{ $node = $node->parentNode->removeChild($node); } } print $frame->toString(1);
My thinking is that because Net::EPP::Frame inherits from XML::LibXML::Document, I should be able to operate on $frame (the XML document) similarly to your original solution... but I'm missing something.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to remove empty XML elements using XML::LibXML
by choroba (Cardinal) on Feb 18, 2013 at 08:46 UTC | |
by FreakyGreenLeaky (Sexton) on Feb 18, 2013 at 16:52 UTC |