Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Missing values in XML::Twig Output

by eff_i_g (Curate)
on May 03, 2011 at 15:15 UTC ( #902732=note: print w/ replies, xml ) Need Help??


in reply to Missing values in XML::Twig Output

This is going to STDOUT:

twig_print_outside_roots => 1,
And this to the file:
$t->print($fh_out);
Try opening your file first and:
twig_print_outside_roots => $fh_out,


Comment on Re: Missing values in XML::Twig Output
Select or Download Code
Re^2: Missing values in XML::Twig Output
by TJRandall (Sexton) on May 03, 2011 at 15:21 UTC
    hmm - I think I made the changes correctly - I changed my code to:
    #!/usr/bin/perl use strict; use warnings; use XML::Twig; my $out_file = 'C:\web_bu.xml'; # export the XML open (my $fh_out, '>', $out_file) or die "unable to open '$out_file' f +or writing: $!"; my $t = XML::Twig->new( twig_roots => {'display-name' => \&convert}, twig_print_outside_roots => $fh_out, pretty_print => 'nice' ); # including data for ease of post #$t->parsefile( $file); $t->parse(*DATA); 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>
    But still get file with the missing <display-name> output:
    <?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"> <servlet> <servlet-name>AxisServlet</servlet-name> <servlet-class> org.apache.axis.transport.http.AxisServlet</servlet-class> </servlet> <servlet> <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>

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-12-21 16:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls