in reply to xml::Twig question
If the main list is always going to be in a section, try triggering twig_roots on '/section/list' instead of just list.
Otherwise add a test so you don't print the nested list: print unless( $sec->in( 'list')), or return if the list is nested:
#!/usr/bin/perl use strict; use XML::Twig; my $twig = XML::Twig->new( twig_handlers => { list => \&list}, pretty_ +print=> 'indented'); $twig->parse( \*DATA); sub list { my ($twig, $list) = @_; # I renamed $sec as $list return if( $list->in( 'list')); $list->print; } __DATA__ <?xml version="1.0"?> <camelids> <section> <r>afasdfasdf</r> <section> <list> <list-item>242354</list-item> <list-item>gsdfg <list> <list-item>7989</list-item> <list-item>97989</list-item> </list> </list-item> </list> fasdfas </section> </section> </camelids>
|
|---|