Mr.Churka has asked for the wisdom of the Perl Monks concerning the following question:
I can't simply call a handler on the ItemID tag because of the duplication. The number I'm looking for is a concatenation of the prefix and stock number. Here's what I'm trying.<us:ItemMaster> <us:ItemMasterHeader> <oa:ItemID agencyRole="Product_Number"> <oa:ID>0123456</oa:ID> </oa:ItemID> <oa:ItemID agencyRole="Prefix_Number"> <oa:ID>AAA</oa:ID> </oa:ItemID> <oa:ItemID agencyRole="Stock_Number_Butted"> <oa:ID>01234</oa:ID> </oa:ItemID> </us:ItemMasterHeader> </us:ItemMaster>
The line raising an exception is my $twig_handlers = {oa:ItemID[my @agencyRole='Prefix_Number']=> \&ITEMnumber}; I've tried a variety of fixes on this line, including using * between the element tag and the [, escaping the @ using double quotes and single quotes, single quotes and double quotes on the element tag alone, omitting the element tag in favor of an *, praying and kicking my machine. None of these have helped much. Any help would be greatly appreciated.use strict; use warnings; use xml::twig; use utf8; my $file= "itemsANDstuff.xml"; my $twig_handlers = {oa:ItemID[my @agencyRole='Prefix_Number']=> \&ITE +Mnumber}; my $twig= new XML::Twig(TwigRoots => {'us:ItemMasterHeader' => 1}, + TwigHandlers => $twig_handlers); $twig->parsefile($file); sub ITEMnumber{ my ($twig, $Item)= @_; my $prefix=($Item->first_child->text); my $stock = (next_sibling->first_child->text); my $itemNUMBER = $prefix.$stock; print "$itemNUMBER \n";};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML Twig Handler Triggers Syntax
by Jenda (Abbot) on Dec 26, 2007 at 16:58 UTC | |
by Mr.Churka (Sexton) on Dec 26, 2007 at 17:45 UTC | |
by Jenda (Abbot) on Dec 26, 2007 at 21:59 UTC | |
|
Re: XML Twig Handler Triggers Syntax
by runrig (Abbot) on Dec 26, 2007 at 18:49 UTC | |
by Mr.Churka (Sexton) on Dec 26, 2007 at 20:03 UTC |