Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: How to remove empty XML elements using XML::LibXML

by FreakyGreenLeaky (Sexton)
on Feb 18, 2013 at 04:23 UTC ( #1019272=note: print w/replies, xml ) Need Help??

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 ( 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 (Chancellor) on Feb 18, 2013 at 08:46 UTC
    I have no experience with Net::EPP::Frame. What error do you get, or how is the output different from your expectations? Also, what does ref $frame say?
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Running my sample code produces no change at all, and no error. The offending XML elements are still there.

      ref $frame says


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019272]
[erix]: probably on holiday, the slacker
erix is reduced to use a BROWSER. (remember those?)
[Discipulus]: figuring.. i'm still just use the side pm chat..
[erix]: (all this while karls guitar gently weeps...)
[planetscape]: (invade Hungary)++ #I'm hungry
[stonecolddevin]: i went too far down the irc rabbithole to hook this back up there
[Discipulus]: .. yes erix until NodeReaper put jhon coltrane again

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-06-22 21:13 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (531 votes). Check out past polls.