I love XML::Twig, but here's what I still do with HTML, and did with XML before I learned about XML::Twig ;)
use XML::TokeParser; my $file = 'REC-xml-19980210.xml'; my $i = 0; my $p = XML::TokeParser->new($file); my $Ret = ""; while(defined(my $t = $p->get_token() )){ if($t->[0] eq 'S' and $t->[1] eq 'lhs') { $i++; $Ret = join '', "[$i] ", $p->get_text('/lhs'), " ::= "; }elsif( $t->[0] eq 'S' and $t->[1] eq 'rhs'){ $Ret .= $p->get_text('/rhs'); }elsif($t->[0] eq 'E' and $t->[1] eq 'prod'){ print clean($Ret),"\n"; $Ret = ""; } } undef $Ret; undef $p; ## mirod already did this, so I'm borrowing sub prod { my( $twig, $prod)= @_; my $lhs= $prod->field( 'lhs'); my $rhs= join '', map {$_->text} $prod->children( 'rhs'); $i++; my $prod_text = "[$i] $lhs ::= $rhs"; print clean( $prod_text) . "\n"; } sub clean { my( $string)= @_; $string =~ s/\xc2\xa0/ /sg; $string =~ s/\s+/ /g; $string=~ s{\s$}{}g; return $string; }

____________________________________________________
** The Third rule of perl club is a statement of fact: pod is sexy.


In reply to Re: XML Examples (and a call for participation) by PodMaster
in thread XML Examples (and a call for participation) by mirod

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.