in reply to Re: Pasing an XML file to generate a certain output.
in thread Pasing an XML file to generate a certain output.

eh, i was trying the same solution but with the code below (your's) and with my attempt too i get not well-formed (invalid token) at line 1, column 29, byte 29 at.. tht seems to be the comment.
If i entirely remove the comment it runs fine. i'm playng with comments => "process" as the authors said, but with no luck.

#!/usr/bin/perl use XML::Twig; # at most one div will be loaded in memory my $twig=XML::Twig->new( twig_handlers => { channel => sub { my( $node )= @_; my( $id )= $node->{'att'}->{id}; my( $chan )= $node->{'att'}->{chan}; my( $sign )= $node->text; print qq(UPDATE channel SET channum="$chan",xmltvid="$id" WHER +E callsign="$sign"); $node->purge; }, }, ); $twig->parse(<DATA>); __DATA__ <channel id="6945.dvb.guide" <!-- number="84" type="0x19" flags="0xf" +bouquet="4110" region="2000000e" sid="6945" --> > <display-name>6945</display-name> </channel>

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.

Replies are listed 'Best First'.
Re^3: Pasing an XML file to generate a certain output.
by Anonymous Monk on May 13, 2015 at 10:56 UTC

    If i entirely remove the comment it runs fine. i'm playng with comments => "process" as the authors said, but with no luck.

    Hmm, xml parsers are required to reject invalid xml -- comments inside tags are invalid xml :)

    I wouldn't play anymore :D

      Ah ok thanks, it appeared to me as a very bad thing having a comment inside a tag, but i was not aware it was not valid XML.

      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.
      Hmmm,

      What if I remove all the rubbish I dont need from the file, how would I parse it then.
      http://paste.ubuntu.com/11112412/
        The closing > is now missing for opening channel tags.
        <channel id="9601.dvb.guide" number="101"> <display-name>RTE One</display-name> ^ </channel> | Here
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ