Thanks a lot Rob for your nice help.

Best Regards
Anirban Adhikary.

On Tue, Mar 20, 2012 at 4:38 PM, Rob Dixon <rob.di...@gmx.com> wrote:

> On 19/03/2012 14:45, Anirban Adhikary wrote:
>
>> On Mon, Mar 19, 2012 at 7:41 PM, Rob Dixon<rob.di...@gmx.com>  wrote:
>>>
>>>>
>>>> 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');
>>>>
>>>
>>> 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)= @_;
>>>
>>>
>> 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');
>>
>
> Hi Anirban
>
> I use the POD documentation supplied with the module, but I agree it is
> a little opaque. XML::Twig has its own website at http://xmltwig.org
> where you will find some tutorials that may help you.
>
> The line
>
>  my ($twig, $bsc)= @_;
>
> copies the values supplied as parameters to the callback into local
> variables. $twig is the XML::Twig object itself, and $bsc is an
> XML::Twig::Elt object representing the <BSC> XML element that has been
> found.
>
> You are unable to access the child elements of each <BSC> because I have
> suggested you specify "start_tag_handlers" for which only the start tag
> is available. That was fine when you just wanted the "id" attribute from
> the tag, but there is no information about any other part of the XML.
>
> You need to use "twig_handlers" instead, when the entire <BSC> element
> will be accessible using
>
>  $bsc->first_child_trimmed_**text('ALPHA')
>
> HTH,
>
> Rob
>

Reply via email to