in reply to Re^5: How to parse this hash? XML question (Twig example)
in thread How to parse this hash? And how to describe my probem?

Thank you! That helped a lot. I spent quite some time to do some basic research on XML Twig and XML.

But I still do not understand how your workaround works. It is cool that you get the league-number for every line. I would like to have something like that for all the 'spreads' as well. But that seems to involve some kind of recursion. And my little brain is to small for that. I have tried to understand this tutorial. But I am not all the way trough...

pad://http://www.xml.com/lpt/a/750

  • Comment on Re^6: How to parse this hash? XML question (Twig example)

Replies are listed 'Best First'.
Re^7: How to parse this hash? XML question (Twig example)
by Discipulus (Canon) on Jun 09, 2015 at 08:10 UTC

      Hm. Ok. I am a step further. But why don't I get the right values with this:

      my $t= XML::Twig->new( twig_handlers => { 'league/id' =>sub +{ $leagueId = $_[1]->text;}, 'event/startDateTime' + =>sub{ $date = $_[1]->text;}, 'event/homeTeam/name' + =>sub{ $home = $_[1]->text;}, 'event/awayTeam/name' + =>sub{ $away = $_[1]->text;}, 'event/periods/period/number' + =>sub{ $period = $_[1]->text;}, 'event/periods/period/description' + =>sub{ $perDescr = $_[1]->text;}, 'event/periods/period/maxBetAmount/moneyLine +' =>sub{ $maxBetML = $_[1]->text;}, 'event/periods/period/moneyLine/homePrice' + =>sub{ $homePrice = $_[1]->text;}, 'event/periods/period/moneyLine/drawPrice' + =>sub{ $drawPrice = $_[1]->text;}, 'event/periods/period/moneyLine/awayPrice' + =>sub{ $awayPrice = $_[1]->text; print "\nMoney,", $lea +gueId, " ", $date, " ", $home, " ", $away, " ", $period, +" ", $perDescr, " ", $maxBetML, " ", $homePrice, " ", $dr +awPrice, " ", $awayPrice; } );

      Your code gives me all fixtures. I am now looking for all moneyline-odds for these fixtures. In the XML there are different periods for a game (mostly match and 1st half). Not all of the periods are given for all matches. And if there is a period there does not have to be a moneyline.

      So I tried the magic workaround with other data. My code tries to store the other relevant data in scalars and then put all together with the last handler-line. But the data is mixed up.

        Eh no! you need to squeeze yourself a bit more.

        The cur_league tricks works because each event is contained strictly inside a league.

        If the event can contain different items, some of them not required, you need a big handler for the event. In this handler you need to check the presence and the content of required (by you) fields and populate the CSV row accordingly.

        XML::Twig has many (oh really maaany) methods to inspect silb, ancestor, attributes..

        L*
        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^7: How to parse this hash? XML question (Twig example)
by Anonymous Monk on Jun 09, 2015 at 07:54 UTC
    If you add  warn $_->path, "\n"; to every callback you can observe a magical hint

    Then try something  'spreads/spread' => sub { ... } ... http://xmltwig.org/tutorial/