Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Everyone has been so helpful I thought I would ask one last question regarding XML::Twig.
I'm using the following code
#!/perl/bin/perl -w use strict; use XML::Twig; my $twig= new XML::Twig; open( XML_OUT, ">output.xml") or die $!; $twig->parsefile( "RoamAboutAP_173.253.52.82.xml"); my $root= $twig->root; my @ds= $root->children; foreach my $attr (@ds) { my $look = $attr->parent('rrd')->text; print $look; my $blg= sprintf( "TESTING PLACEMENT"); my $eblg= new XML::Twig::Elt( 'Average', $blg); $eblg->paste( 'first_child', $attr); } # $twig->set_pretty_print('indented'); $twig->print( \*XML_OUT); close XML_OUT;
My XML file looks like this:
What I want to do is search for a specidifc tag, say maybe <ds> or the <v> tag.- <rrd> <version>0001</version> <step>300</step> - <!-- Seconds --> <lastupdate>1042244888</lastupdate> - <!-- 2003-01-10 19:28:08 Eastern Standard Time --> - <ds> <name>ifOutOctets1</name> <type>COUNTER</type> <minimal_heartbeat>600</minimal_heartbeat> <min>NaN</min> <max>NaN</max> - <!-- PDP Status --> <last_ds>1636141175</last_ds> <value>6.2416000000e+002</value> <unknown_sec>0</unknown_sec> </ds> - <!-- Round Robin Archives --> - <rra> <cf>AVERAGE</cf> <pdp_per_row>1</pdp_per_row> - <!-- 300 seconds --> <xff>5.0000000000e-001</xff> - <cdp_prep> - <ds> <value>NaN</value> <unknown_datapoints>0</unknown_datapoints> </ds> - <ds> <value>NaN</value> <unknown_datapoints>0</unknown_datapoints> </ds> </cdp_prep> - <database> - <!-- 2003-01-08 17:30:00 Eastern Standard Time / 1042065000 --> - <row> <v>NaN</v> <v>NaN</v> <v>NaN</v> <v>NaN</v> </row> - <!-- 2003-01-08 17:35:00 Eastern Standard Time / 1042065300 --> - <row> <v>6.3173066667e+001</v> <v>2.2418133333e+001</v> <v>3.7560151111e+002</v> <v>1.7984751111e+002</v> </row> - <!-- 2003-01-10 19:25:00 Eastern Standard Time / 1042244700 --> - <row> <v>9.5548400000e+001</v> <v>3.1534622222e+001</v> <v>4.0781324444e+002</v> <v>1.9573493333e+002</v> </row> </database> </rra> </rrd>
I am able to sucessfully look at the root tag, but how can I look at the children of the root node in my foreach loop?
I'll continue reading the perldoc
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML Twig parse
by mirod (Canon) on Jan 20, 2003 at 20:39 UTC | |
|
Re: XML Twig parse
by boo_radley (Parson) on Jan 20, 2003 at 20:41 UTC | |
by mirod (Canon) on Jan 20, 2003 at 21:43 UTC | |
by Anonymous Monk on Jan 21, 2003 at 14:21 UTC | |
by mirod (Canon) on Jan 21, 2003 at 15:30 UTC |