Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: removing namespaces with XML::Twig?

by bitingduck (Friar)
on Jun 12, 2012 at 03:45 UTC ( #975682=note: print w/ replies, xml ) Need Help??


in reply to removing namespaces with XML::Twig?

I tried the obvious of taking the example for "map_xmlns" and seeing if I could substitute an empty prefix. The result was that it leaves the prefix unchanged:

#!/usr/bin/perl #very slightly modified example lifted from the docs use strict; use warnings; use XML::Twig; my $t= XML::Twig->new( map_xmlns => {'http://www.w3.org/2000/svg' => " +"}, twig_handlers => { 'svg:circle' => sub { $_->set_att( r => 2 +0) } }, pretty_print => 'indented', ) ->parse( '<doc xmlns:gr="http://www.w3.org/2000/svg" +> <gr:circle cx="10" cy="90" r="10"/> </doc>' ) ->print;

The output is:

<doc xmlns:gr="http://www.w3.org/2000/svg"> <gr:circle cx="10" cy="90" r="10"/> </doc>

If I put the "svg"in the example back in the hash, it works as in the example. If I put a space, I get a prefix that's a space and a colon. XML::LibXML::Element will let you turn off the namespace prefix element by element, but I'm too lazy right now to work through that one. Try poking around through the various XML::LibXML children.


Comment on Re: removing namespaces with XML::Twig?
Select or Download Code
Re^2: removing namespaces with XML::Twig?
by Anonymous Monk on Jun 12, 2012 at 06:24 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://975682]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2014-07-10 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (217 votes), past polls