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

Re: XML::Twig Help

by mirod (Canon)
on Jul 06, 2010 at 16:23 UTC ( [id://848266]=note: print w/replies, xml ) Need Help??


in reply to XML::Twig Help

The error you get comes from the fact that you need to quote djn-geo, as it doesn't look like a bareword to Perl.

That said there are many other problems with your code. I suspect what you want is something like this (untested):

#!/usr/bin/perl use strict; use warnings; use XML::Twig; # get the user input. die if it doesn't look right my $enter = <STDIN>; my @fields = split(/ /, $enter); if( @fields != 2) { die "usage $0 <input_file> <output_file>\n"; } # no need to open the file, quote djn-geo my $t= XML::Twig->new( twig_roots => { 'djn-geo' => 1}); $t->parsefile($fields[0]); # print_to_file was added in XML::Twig 3.23 $twig->print_to_file( $fields[1]);

Replies are listed 'Best First'.
Re^2: XML::Twig Help
by shravnk (Initiate) on Jul 06, 2010 at 17:17 UTC

    mirod:

    This has been enormously helpful, and your code works when I process one tree at a time. However, the xml doc that I am trying to work with contains hundreds of trees with the same format. How can I get the XML::Twig module to iterate over many trees within one document. (This will be my last question, I promise)

    Thanks again

    shravnk

      There should not be more than 1 root element in a proper XML file. If that is what you mean by "many trees", otherwise mirod has a few posts here on pm regarding how to process XML in chunks. When I started with XML::Twig, I read all his posts here and that answered every question. If you have perldoc, you can look at the twig page and search for flush and purge. I can't seem to reach xmltwig.com for the last week from around here, so I can't link those examples.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-03-19 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found