TJRandall has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $out_file = 'C:\web_bu.xml'; my $t = XML::Twig->new( twig_roots => {'display-name' => \&convert}, twig_print_outside_roots => 1, pretty_print => 'nice' ); # including data for ease of post #$t->parsefile( $file); $t->parse(*DATA); # export the XML open (my $fh_out, '>', $out_file) or die "unable to open '$out_file' f +or writing: $!"; $t->print($fh_out); # this prints to the filehandle #$t->print(); sub convert { my ($t, $elt) = @_; my $txt = $elt->text(); if ($txt =~ /wtw_reports/i) { $elt->set_text('SOMEGUY'); } else { $elt->set_text($txt); } } __DATA__ <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/n +s/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:sch +emaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ +ns/j2ee/web-app_2_4.xsd"> <display-name>wtw_reports-CIMS_MMA_20110429_DEV</display-name> <servlet> <display-name> Apache-Axis Servlet</display-name> <servlet-name>AxisServlet</servlet-name> <servlet-class> org.apache.axis.transport.http.AxisServlet</servlet-class> </servlet> <servlet> <display-name> Axis Admin Servlet</display-name> <servlet-name>AdminServlet</servlet-name> <servlet-class> org.apache.axis.transport.http.AdminServlet</servlet-class> <load-on-startup>100</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/servlet/AxisServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>*.jws</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AdminServlet</servlet-name> <url-pattern>/servlet/AdminServlet</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Missing values in XML::Twig Output
by mirod (Canon) on May 03, 2011 at 16:00 UTC | |
|
Re: Missing values in XML::Twig Output
by toolic (Bishop) on May 03, 2011 at 14:37 UTC | |
by TJRandall (Sexton) on May 03, 2011 at 14:40 UTC | |
by toolic (Bishop) on May 03, 2011 at 15:08 UTC | |
by TJRandall (Sexton) on May 03, 2011 at 15:26 UTC | |
by toolic (Bishop) on May 03, 2011 at 15:42 UTC | |
| |
|
Re: Missing values in XML::Twig Output
by eff_i_g (Curate) on May 03, 2011 at 15:15 UTC | |
by TJRandall (Sexton) on May 03, 2011 at 15:21 UTC | |
|
Re: Missing values in XML::Twig Output
by choroba (Cardinal) on May 03, 2011 at 21:21 UTC |