Hello again,

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:

- <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>
What I want to do is search for a specidifc tag, say maybe <ds> or the <v> tag.

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!


In reply to XML Twig parse by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.