Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: removing namespaces with XML::Twig?

by mirod (Canon)
on Jun 12, 2012 at 07:08 UTC ( #975702=note: print w/ replies, xml ) Need Help??


in reply to removing namespaces with XML::Twig?

As mentioned above, you need to set each tag to a non-prefixed version of itself.

_all_ triggers a handler on each tag, tag gives you the tag name and set_tag sets it:

#!/usr/bin/perl use strict; use warnings; use XML::Twig; XML::Twig->new( start_tag_handlers => { _all_ => sub { my $tag= $_->ta +g; $tag=~ s{^[^:]*:}{}; $_->set_tag( $tag); } }, keep_spaces => 1, # to keep for +mating ) ->parse( \*DATA) ->print; __DATA__ <a:houses> <a:house> <a:sq_footage/> <a:address/> </a:house> <a:house> <a:sq_footage/> <a:address/> </a:house> </a:houses>


Comment on Re: removing namespaces with XML::Twig?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (19)
As of 2015-07-02 18:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls