Here is *untested* and *possibly hafmful* patch and the test script.

0.44 should be OK.

Riccardo Cambiassi wrote:

> Hallo,
> I was trying to develop some custom scheme handlers with XML::Sablotron,
> but I noticed that my SHGet function gets called just one time (so if my data is 
>bigger than bufsize, all other data is lost).
> Did this happen to anybody else ?
> Do you have any example of scheme handler implementation ?
> 
> Thank you very much,
>       Rick
> 
> 
> 

-- 
Pavel Hlavnicka
Ginger Alliance Ltd.
Prague; Czech Republic
Index: ga/src/Sablot/engine/parser.cpp
diff -c ga/src/Sablot/engine/parser.cpp:1.8 ga/src/Sablot/engine/parser.cpp:1.9
*** ga/src/Sablot/engine/parser.cpp:1.8 Wed Sep  6 19:12:24 2000
--- ga/src/Sablot/engine/parser.cpp     Wed Sep 13 18:35:03 2000
***************
*** 204,210 ****
              XML_ParserFree(parser);
              return NOT_OK;
          };
!         quit = (Bool) (bytes < PARSE_BUFSIZE);
          // res = XML_Parse(parser,buf,bytes,quit);
          res = XML_ParseBuffer(parser,bytes,quit);
          if (situation_.isError())
--- 204,211 ----
              XML_ParserFree(parser);
              return NOT_OK;
          };
!       quit = (Bool) (bytes == 0);
!         //quit = (Bool) (bytes < PARSE_BUFSIZE);
          // res = XML_Parse(parser,buf,bytes,quit);
          res = XML_ParseBuffer(parser,bytes,quit);
          if (situation_.isError())
Index: ga/src/perl/XML/Sablotron.xs
diff -c ga/src/perl/XML/Sablotron.xs:1.21 ga/src/perl/XML/Sablotron.xs:1.22
*** ga/src/perl/XML/Sablotron.xs:1.21   Wed Sep 13 15:28:34 2000
--- ga/src/perl/XML/Sablotron.xs        Wed Sep 13 18:35:03 2000
***************
*** 401,409 ****
        
      value = POPs;
      if SvOK(value) {
!       SvPV(value, len);
        *byteCount = len < *byteCount ? len : *byteCount;
!       strncpy(buffer, SvPV(value, PL_na), *byteCount);
      } else {
        *byteCount = 0;
      }
--- 401,410 ----
        
      value = POPs;
      if SvOK(value) {
!       char *aux;
!       aux = SvPV(value, len);
        *byteCount = len < *byteCount ? len : *byteCount;
!       strncpy(buffer, aux, *byteCount + 1);
      } else {
        *byteCount = 0;
      }
use strict;

use lib qw(blib/lib blib/arch);

use XML::Sablotron;

my $data = "<?xml version='1.0'?><a/>";
my $templ = "<xsl:transform xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version='1.0'>
<xsl:output method='text'/>
<xsl:template match='a'>
<xsl:value-of select='document(\"scheme:/d\")/foo'/>
</xsl:template>
</xsl:transform>";

my $doc = "<?xml version='1.0'?>
<foo>
in document
</foo>";

my $sab = new XML::Sablotron;
my $sh = new SHandler($doc);
$sab->RegHandler(1, $sh);

$sab->RunProcessor("arg:/a", "arg:/b", "arg:/c", undef,
                   ["a", $templ, "b", $data]);

my $foo = $sab->GetResultArg("c");

print "result: $foo\n";


package SHandler;

sub new {
    my ($class, $d) = @_;
    my $self = bless {}, $class;
    $self->{arr} = [ split /\n/, $d ];
    $self->{idx} = 0;
    $self;
}

sub SHOpen {
    print "opening handler\n";
}

sub SHClose {
    print "closing handler\n";
}

sub SHGet {
    my ($self, $processor, $handle, $size) = shift;
    my $line = ${$self->{arr}}[$self->{idx}++];
    print "in SHGet ($size): $line\n";
    $line;
}

__END__

Reply via email to