You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ja...@apache.org on 2001/10/10 22:08:58 UTC

cvs commit: xml-xerces/perl/samples SAX2Count.pl SAXCount.pl

jasons      01/10/10 13:08:58

  Modified:    perl/samples SAX2Count.pl SAXCount.pl
  Log:
  	* samples/SAXCount.pl (Repository):
  	* samples/SAX2Count.pl (Repository):
  	Added USAGE output if no input files are specified
  	new exception handling code
  
  Revision  Changes    Path
  1.7       +39 -15    xml-xerces/perl/samples/SAX2Count.pl
  
  Index: SAX2Count.pl
  ===================================================================
  RCS file: /home/cvs/xml-xerces/perl/samples/SAX2Count.pl,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SAX2Count.pl	2001/09/10 07:13:36	1.6
  +++ SAX2Count.pl	2001/10/10 20:08:58	1.7
  @@ -83,7 +83,7 @@
     * = Default if not provided explicitly
   
   EOU
  -my $VERSION = q[$Id: SAX2Count.pl,v 1.6 2001/09/10 07:13:36 jasons Exp $ ];
  +my $VERSION = q[$Id: SAX2Count.pl,v 1.7 2001/10/10 20:08:58 jasons Exp $ ];
   
   my %OPTIONS;
   my $rc = GetOptions(\%OPTIONS,
  @@ -91,8 +91,10 @@
   		    'n',
   		    's');
   
  -die "$USAGE" unless $rc;
  +die $USAGE unless $rc;
   
  +die $USAGE unless scalar @ARGV;
  +
   my $file = $ARGV[0];
   -f $file or die "File '$file' does not exist!\n";
   
  @@ -120,9 +122,9 @@
   @ISA = qw(XML::Xerces::PerlContentHandler);
   
   sub start_element {
  -  my ($self,$name,$attrs) = @_;
  +  my ($self,$uri,$localname,$qname,$attrs) = @_;
     $self->{elements}++;
  -  $self->{attrs} = 0;
  +  $self->{attrs} += $attrs->getLength;
   }
   sub end_element {
     my ($self,$name) = @_;
  @@ -138,25 +140,47 @@
   
   package main;
   my $parser = XML::Xerces::XMLReaderFactory::createXMLReader();
  -$parser->setFeature("http://xml.org/sax/features/namespaces", $namespace);
  -if ($validate eq $XML::Xerces::SAX2XMLReader::Val_Auto) {
  -  $parser->setFeature("http://xml.org/sax/features/validation", 1);
  -  $parser->setFeature("http://apache.org/xml/features/validation/dynamic", 1);
  -} elsif ($validate eq $XML::Xerces::SAX2XMLReader::Val_Never) {
  -  $parser->setFeature("http://xml.org/sax/features/validation", 0);
  -} elsif ($validate eq $XML::Xerces::SAX2XMLReader::Val_Always) {
  -  $parser->setFeature("http://xml.org/sax/features/validation", 1);
  -  $parser->setFeature("http://apache.org/xml/features/validation/dynamic", 0);
  +eval {
  +  $parser->setFeature("http://xml.org/sax/features/namespaces", $namespace);
  +  if ($validate eq $XML::Xerces::SAX2XMLReader::Val_Auto) {
  +    $parser->setFeature("http://xml.org/sax/features/validation", 1);
  +    $parser->setFeature("http://apache.org/xml/features/validation/dynamic", 1);
  +  } elsif ($validate eq $XML::Xerces::SAX2XMLReader::Val_Never) {
  +    $parser->setFeature("http://xml.org/sax/features/validation", 0);
  +  } elsif ($validate eq $XML::Xerces::SAX2XMLReader::Val_Always) {
  +    $parser->setFeature("http://xml.org/sax/features/validation", 1);
  +    $parser->setFeature("http://apache.org/xml/features/validation/dynamic", 0);
  +  }
  +  $parser->setFeature("http://apache.org/xml/features/validation/schema", $schema);
  +};
  +if ($@) {
  +  if (ref $@) {
  +    die $@->getMessage();
  +  } else {
  +    die $@;
  +  }
   }
  -$parser->setFeature("http://apache.org/xml/features/validation/schema", $schema);
   my $error_handler = XML::Xerces::PerlErrorHandler->new();
   $parser->setErrorHandler($error_handler);
   
   my $CONTENT_HANDLER = MyContentHandler->new();
   $parser->setContentHandler($CONTENT_HANDLER);
  +$CONTENT_HANDLER->{elements} = 0;
  +$CONTENT_HANDLER->{attrs} = 0;
  +$CONTENT_HANDLER->{ws} = 0;
  +$CONTENT_HANDLER->{chars} = 0;
   
   my $t0 = new Benchmark;
  -$parser->parse (XML::Xerces::LocalFileInputSource->new($file));
  +eval {
  +  $parser->parse (XML::Xerces::LocalFileInputSource->new($file));
  +};
  +if ($@) {
  +  if (ref $@) {
  +    die $@->getMessage();
  +  } else {
  +    die $@;
  +  }
  +}
   my $t1 = new Benchmark;
   my $td = timediff($t1, $t0);
   
  
  
  
  1.6       +19 -4     xml-xerces/perl/samples/SAXCount.pl
  
  Index: SAXCount.pl
  ===================================================================
  RCS file: /home/cvs/xml-xerces/perl/samples/SAXCount.pl,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SAXCount.pl	2001/09/10 01:16:10	1.5
  +++ SAXCount.pl	2001/10/10 20:08:58	1.6
  @@ -84,15 +84,17 @@
   
   EOU
   
  -my $VERSION = q[$Id: SAXCount.pl,v 1.5 2001/09/10 01:16:10 jasons Exp $ ];
  +my $VERSION = q[$Id: SAXCount.pl,v 1.6 2001/10/10 20:08:58 jasons Exp $ ];
   my %OPTIONS;
   my $rc = GetOptions(\%OPTIONS,
   		    'v=s',
   		    'n',
   		    's');
   
  -die "$USAGE" unless $rc;
  +die $USAGE unless $rc;
   
  +die $USAGE unless scalar @ARGV;
  +
   my $file = $ARGV[0];
   -f $file or die "File '$file' does not exist!\n";
   
  @@ -129,7 +131,7 @@
   sub start_element {
     my ($self,$name,$attrs) = @_;
     $self->{elements}++;
  -  $self->{attrs} = 0;
  +  $self->{attrs} += $attrs->getLength();
   }
   sub end_element {
     my ($self,$name) = @_;
  @@ -147,8 +149,21 @@
   my $DOCUMENT_HANDLER = MyDocumentHandler->new();
   $parser->setDocumentHandler($DOCUMENT_HANDLER);
   
  +$DOCUMENT_HANDLER->{elements} = 0;
  +$DOCUMENT_HANDLER->{attrs} = 0;
  +$DOCUMENT_HANDLER->{ws} = 0;
  +$DOCUMENT_HANDLER->{chars} = 0;
   my $t0 = new Benchmark;
  -$parser->parse (XML::Xerces::LocalFileInputSource->new($file));
  +eval {
  +  $parser->parse (XML::Xerces::LocalFileInputSource->new($file));
  +};
  +if ($@) {
  +  if (ref $@) {
  +    die $@->getMessage();
  +  } else {
  +    die $@;
  +  }
  +}
   my $t1 = new Benchmark;
   my $td = timediff($t1, $t0);
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org