Rob, thanks a lot for the response, this is some code that actually gets the text out of terminal nodes only. But, it prints the text of sister nodes together which makes it non usable. Can you please lead me to solve this problem? thanks a lot.

a sample input file with the message I sent is below. As you can see when you run it, you get the text of the sister nodes ...thanks printed together with reputation. I tried your line of code, but I can't make it work. thanks again, Ivo

#!/bin/perl -w use strict; use XML::Twig; my $twig= XML::Twig->new(); my $file = "message.xml"; $twig ->parsefile( $file ); my $root = $twig->root; my @nodes = $root ->children; foreach my $node ( @nodes) { my $content = $node->text ; print "$content "; }
OUtput:

perlquestion Isanchez Hi, I have to recursively go over xml files (that look very differently from each other) in a folder and collect every content for every tag. I have tried with TWig code but it doesn't work because it grabs all tags including parent tags and then prints first the contents that belong to the parents i.e. all and then the contents again but this time for each doughter node. Can any wise monk give some idea of what to do ? thanks,"reputation"

edited: Thu May 1 21:28:03 2003 by jeffa - code tags, formatting


In reply to Re: Re: getting the txt of terminal nodes only XML::TWIG by Isanchez
in thread getting the txt of terminal nodes only XML::TWIG by Isanchez

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.