List Info

Thread:




country flaguser name
Italy
2007-02-05 11:04:58
Stuart McGraw wrote:
> Hello,
> 
> I am processing a large xml file with xml-twig 
> sucessfully but now need to process comments
> in the file and haven't been able to figure out from 
> the twig docs how to do that.
> 
> Here is what I tried:
>   use XML::Twig;
>   $twig = XML::Twig->new (twig_roots=>{
>                             entry=>&entry,
>                            
'#COMMENT'=>&comment},
>                           comments=>'process');
>   $twig->parsefile( "twig-comments.xml" );

> 
>   sub entry { my( $t, $entry ) = _;
>         print "processing entryn"; 
>         $t->purge; 0; }
> 
>   sub comment { my( $t, $entry ) = _;
>         print "processing commentn"; }
> 
> The entry sub gets called for each entry node in the
file 
> as expected, but the comment sub is never called.  If
it
> matters, the comments occur between each node, e.g.
> 
>   <rootnode>
>   <entry>
>   ...
>   </entry>
>   <!-- a comment -->
>   <entry>
>   ...
>   </rootnode>
> 
> Can anyone give me an example of how to get to
> the comments?  I realize I am probably either totally
> misunderstanding the docs or making a bonehead 
> mistake or both, so my apologies in advance, but 
> I am stumped.

Hi,

Or maybe you found a bug...

What happens is that comments are processed by different
callbacks than regular elements. As a result they are not
tested by the code that looks for roots.

You can have the handler called if you replace twig_roots
by
twig_handlers. This also means that the tree will be built
even
outside the entries. This may or may not be a problem. As
you
purge the twig at the end of the entry handler, the memory
used
will not change, unless you have huge amounts of data
outside of
the entries.

Does that help?
_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

Re: comments in xml::twig]
country flaguser name
United States
2007-02-06 15:51:31
"mirod" wrote:
> Stuart McGraw wrote:
> > Hello,
> > 
> > I am processing a large xml file with xml-twig 
> > sucessfully but now need to process comments
> > in the file and haven't been able to figure out
from 
> > the twig docs how to do that.
> > 
> > Here is what I tried:
> >   use XML::Twig;
> >   $twig = XML::Twig->new (twig_roots=>{
> >                            
entry=>&entry,
> >                            
'#COMMENT'=>&comment},
> >                          
comments=>'process');
> >   $twig->parsefile(
"twig-comments.xml" ); 
> > 
> >   sub entry { my( $t, $entry ) = _;
> >         print "processing entryn"; 
> >         $t->purge; 0; }
> > 
> >   sub comment { my( $t, $entry ) = _;
> >         print "processing commentn"; }
> > 
> > The entry sub gets called for each entry node in
the file 
> > as expected, but the comment sub is never called. 
If it
> > matters, the comments occur between each node,
e.g.
> > 
> >   <rootnode>
> >   <entry>
> >   ...
> >   </entry>
> >   <!-- a comment -->
> >   <entry>
> >   ...
> >   </rootnode>
> > 
> > Can anyone give me an example of how to get to
> > the comments?  I realize I am probably either
totally
> > misunderstanding the docs or making a bonehead 
> > mistake or both, so my apologies in advance, but 
> > I am stumped.
> 
> Hi,
> 
> Or maybe you found a bug...
> 
> What happens is that comments are processed by
different
> callbacks than regular elements. As a result they are
not
> tested by the code that looks for roots.
> 
> You can have the handler called if you replace
twig_roots by
> twig_handlers. This also means that the tree will be
built even
> outside the entries. This may or may not be a problem.
As you
> purge the twig at the end of the entry handler, the
memory used
> will not change, unless you have huge amounts of data
outside of
> the entries.
> 
> Does that help?

It does indeed, thank you very much!


_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )