OK, the code below should do the trick. 2 comments: if you have control over the output format, I would have the TABLE and USERSQL elements merged into 1 element, either a simple one with the table as an attribute, or just an englobing one with 2 sub-elements. These 2 elements are linked, the format should show this. And I had to guess what to do with the GENSQL property that appeared before the USERSQL one for the second table.

#!/usr/bin/perl use strict; use warnings; use XML::Twig::XPath; my $t= XML::Twig::XPath->new( twig_roots => { Job => \&job}, pretty_pr +int => 'indented'); $t->parsefiel( $ARGV[0]); exit; sub job { my ($t, $job)= @_; my @sub_record_table= $job->findnodes( './/SubRecord[./Property[@N +ame="Name" and text()="TABLE"]]'); return unless( @sub_record_table); my $out_job= XML::Twig::Elt->new( job => { identifier => $job->att +( 'Identifier') }); foreach my $sub_record ( @sub_record_table) { my $table = $sub_record->field( 'Property[@Name="Value"]'); $out_job->insert_new_elt( last_child => TABLE => $table); my $found_sql=0; while( !$found_sql) { $sub_record= $sub_record->next_sibling( 'SubRecord') or la +st; my $tag= $sub_record->field( 'Property[@Name="Name"]'); my $content= $sub_record->field( 'Property[@Name="Value"]' +); if( $content ne 'No') { $found_sql=1; $out_job->insert_new_elt( last_child => $tag => $conte +nt); } } } $out_job->print(); $t->purge; # if you need to free the memory }

In reply to Re^5: XML::Twig usage incomprehension by mirod
in thread XML::Twig usage incomprehension by Jerome

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.