Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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,

Replies are listed 'Best First'.
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?
[1nickt]: my $x = $aohoaoh->[0]->{' foo'}->[0]->{'bar' }; should work
[thepkd]: not indexing
[thepkd]: getting data out of the ds
[choroba]: it depends. Give more details, please
[thepkd]: i used a series of {}'s but it dont work
[choroba]: You need square brackets for arrays
[GotToBTru]: you can certainly construct a single expression to access any part of the data structure, without using temp variables. but you might make it easier on yourself and any other poor soul who has to understand your code if you do
[thepkd]: to dereference i mean
LanX .oO( oh tempz, oh moretz)
[thepkd]: @GotToBTru Sure. But.

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2016-12-06 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (104 votes). Check out past polls.