Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: XML::Twig prev_sibling

by mirod (Canon)
on Oct 20, 2011 at 16:50 UTC ( #932721=note: print w/ replies, xml ) Need Help??


in reply to XML::Twig prev_sibling

It looks to me like any mention of 'now' in the parent (maybe excluding children of the parent) would make the entry not rare. So I would check just that: whether you can match 'now' in the parent's text.

You can test your code by building a quick test environment like the one below, that will let you add headers and check that your sub behaves properly:

#!/usr/bin/perl use strict; use warnings; use XML::Twig; use Test::More; XML::Twig->new( twig_handlers => { header => \&test_header }) ->parse( \*DATA); done_testing(); sub test_header { my( $t, $header)= @_; is( $header->att( 'expected'), is_la_rare( $header), $header->spri +nt); } sub is_la_rare { my $elt = shift; foreach my $label ($elt->children('la') ) { next unless $label->text eq "rare"; my $isNowRare = 0; if ( $label->parent->text_only =~ m/[nN]ow / ) { $isNowRare = +1; } if ( !$isNowRare ) { return 1; } } return 0; } __DATA__ <tests> <header expected="1"><la>rare</la></header> <header expected="0">Now <la>rare</la></header> <header expected="0">Now <la>hist.</la> and <la>rare</la></header> </tests>

And it looks like xmltwig.org was down, it's back to life now, !@#$%^&* networks! Sorry for the inconvenience


Comment on Re: XML::Twig prev_sibling
Download Code
Re^2: XML::Twig prev_sibling
by mertserger (Curate) on Oct 21, 2011 at 09:09 UTC
    Thanks Mirod! I'll try that and see if it does what I need.
    Thanks for getting xmltwig.org back up too - I would have tried to sort this out for myself using its guidance but alas it was down yesterday!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://932721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-12-26 00:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls