Hi List,
When I have changed the method
from my $twig = XML::Twig->new(start_tag_
handlers => {
   BSC => \&on_BSC
});
 to
my $twig = XML::Twig->new(TwigHandlers => {
   BSC => \&on_BSC
});

I am able to print the value against the ALPHA tag.

Thanks to you for your support.

Best Regards
Anirban Adhikary.


On Mon, Mar 19, 2012 at 8:15 PM, Anirban Adhikary <
anirban.adhik...@gmail.com> wrote:

> Hi,
> When I am trying to print the value against the tag ALPHA it is not prints
> anything,though it is not showing any warnings.
>
>
> use strict;
> use warnings;
>
> use XML::Twig;
>
> my $twig = XML::Twig->new(start_tag_handlers => {
>    BSC => \&on_BSC
> });
>
> sub on_BSC {
>  my($twig, $bsc)= @_;
>  print $bsc->id, "\n";
>  my $alpha = $bsc->field('ALPHA');
>  print $alpha, "\n";
>  $twig->purge;
> }
>
> $twig->parsefile(ISProducts.xml');
>
>
> On Mon, Mar 19, 2012 at 7:54 PM, Anirban Adhikary <
> anirban.adhik...@gmail.com> wrote:
>
>> Hi Rob,
>> Thanks for your support.The code does exactly what I want
>> .................
>> Can you please suggest me a tutorials with good examples on XML::Twig.
>>
>> Another thing can you please explain me this line in the code my($twig,
>> $bsc)= @_;
>>
>> Best Regards
>> Anirban Adhikary.
>>
>>
>> On Mon, Mar 19, 2012 at 7:41 PM, Rob Dixon <rob.di...@gmx.com> wrote:
>>
>>> On 19/03/2012 13:10, Anirban Adhikary wrote:
>>>
>>>> Hi List,
>>>> I have a XML file which looks like as follows
>>>>
>>>> <ISProducts>
>>>> <StoreInfo>
>>>>    <BSC id="AMIBRB1">
>>>>       <ALPHA>10</ALPHA>
>>>>       <AMRCSFR3MODE>1,3,4,7</**AMRCSFR3MODE>
>>>>       <AMRCSFR3THR>12,16,21</**AMRCSFR3THR>
>>>>       <AMRCSFR3HYST>2,3,3</**AMRCSFR3HYST>
>>>>       <AMRCSFR4MODE>1,3,6,8</**AMRCSFR4MODE>
>>>>       <AMRCSFR4THR>12,17,25</**AMRCSFR4THR>
>>>>       <PAGBUNDLE>50</PAGBUNDLE>
>>>>       <USERDATA>AMI_BRANLY_B_1</**USERDATA>
>>>>     </BSC>
>>>> .........................
>>>> .............................
>>>>
>>>> Now my question is how to extract the value of id in a variable using
>>>> XML::Twig.
>>>> Since the xml file is quite large I like to print the value of id using
>>>> a
>>>> loop.
>>>>
>>>
>>> XML::Twig uses callbacks to process pieces of the XML that you have
>>> defined. In this case you are interested only in the <BSC> start tag so
>>> you can define a "start tag handler". Using $twig->purge empties the
>>> data read so far. If you use this once you have accessed all the
>>> information you need from a given element there is no need to store the
>>> entire XML data in memory.
>>>
>>> The program below doeas what I think you want.
>>>
>>> HTH,
>>>
>>> Rob
>>>
>>>
>>> use strict;
>>> use warnings;
>>>
>>> use XML::Twig;
>>>
>>> my $twig = XML::Twig->new(start_tag_**handlers => {
>>>    BSC => \&on_BSC
>>> });
>>>
>>> sub on_BSC {
>>>  my($twig, $bsc)= @_;
>>>  print $bsc->id, "\n";
>>>  $twig->purge;
>>> }
>>>
>>> $twig->parsefile('ISProducts.**xml');
>>>
>>>
>>>
>>>
>>
>

Reply via email to