xml-general-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jas...@apache.org
Subject cvs commit: xml-site/sources/xerces-p SAX2Count.xml SAXCount.xml
Date Mon, 09 Jul 2001 05:15:06 GMT
jasons      01/07/08 22:15:06

  Added:       sources/xerces-p SAX2Count.xml SAXCount.xml
  Log:
  	* SAXCount.xml (Repository):
  	* SAX2Count.xml (Repository):
  	new sample
  
  Revision  Changes    Path
  1.1                  xml-site/sources/xerces-p/SAX2Count.xml
  
  Index: SAX2Count.xml
  ===================================================================
  <?xml version="1.0" standalone="no"?>
  <!DOCTYPE s1 SYSTEM "sbk:/style/dtd/document.dtd">
  
  <s1 title="DOMCount.pl">
        <source><![CDATA[
  use strict;
  use XML::Xerces;
  use Getopt::Std;
  use vars qw($opt_v $opt_n);
  use Benchmark;
  #
  # Read and validate command line args
  #
  
  my $USAGE = "USAGE: $0 [-v][-n] file\n";
  
  getopts ('vn') && ($#ARGV == 0)	or die "$USAGE";
  -f $ARGV[0] or die "File '$ARGV[0]' does not exist!\n";
  
  my $validate = $opt_v || 0;
  my $namespace = $opt_n || 0;
  my $file = $ARGV[0];
  
  #
  # Count the nodes
  #
  
  package MyContentHandler;
  use strict;
  use vars qw(@ISA);
  @ISA = qw(XML::Xerces::PerlContentHandler);
  
  sub start_element {
    my $self = shift;
    $self->{elements}++;
    $self->{attrs} = 0;
  }
  sub characters {
    my ($self,$str,$len) = @_;
    $self->{chars} += $len;
  }
  sub ignorable_whitespace {
    my ($self,$str,$len) = @_;
    $self->{ws} += $len;
  }
  
  package main;
  my $parser = XML::Xerces::XMLReaderFactory::createXMLReader();
  $parser->setFeature("http://xml.org/sax/features/namespaces", $namespace);
  $parser->setFeature("http://xml.org/sax/features/validation", $validate);
  my $error_handler = XML::Xerces::PerlErrorHandler->new();
  $parser->setErrorHandler($error_handler);
  
  my $CONTENT_HANDLER = MyContentHandler->new();
  $parser->setContentHandler($CONTENT_HANDLER);
  
  my $t0 = new Benchmark;
  $parser->parse (XML::Xerces::LocalFileInputSource->new($file));
  my $t1 = new Benchmark;
  my $td = timediff($t1, $t0);
  
  print "$file: duration: ", timestr($td), "\n";
  print "elems: ", $CONTENT_HANDLER->{elements}, "\n"; 
  print "attrs: ", $CONTENT_HANDLER->{attrs}, "\n";
  print "whitespace: ", $CONTENT_HANDLER->{ws}, "\n";
  print "characters: ", $CONTENT_HANDLER->{chars}, "\n";
  
  exit(0);
  ]]></source>
  </s1>
  
  
  
  1.1                  xml-site/sources/xerces-p/SAXCount.xml
  
  Index: SAXCount.xml
  ===================================================================
  <?xml version="1.0" standalone="no"?>
  <!DOCTYPE s1 SYSTEM "sbk:/style/dtd/document.dtd">
  
  <s1 title="DOMCount.pl">
        <source><![CDATA[
  use strict;
  use XML::Xerces;
  use Getopt::Std;
  use vars qw($opt_v $opt_n);
  use Benchmark;
  #
  # Read and validate command line args
  #
  
  my $USAGE = "USAGE: $0 [-v][-n] file\n";
  
  getopts ('vn') && ($#ARGV == 0)	or die "$USAGE";
  -f $ARGV[0] or die "File '$ARGV[0]' does not exist!\n";
  
  my $validate = $opt_v || 0;
  my $namespace = $opt_n || 0;
  my $file = $ARGV[0];
  
  #
  # Count the nodes
  #
  
  my $parser = XML::Xerces::SAXParser->new();
  $parser->setDoValidation ($validate);
  $parser->setDoNamespaces ($namespace);
  my $ERROR_HANDLER = XML::Xerces::PerlErrorHandler->new();
  $parser->setErrorHandler($ERROR_HANDLER);
  
  package MyDocumentHandler;
  use strict;
  use vars qw(@ISA);
  @ISA = qw(XML::Xerces::PerlDocumentHandler);
  
  sub start_element {
    my $self = shift;
    $self->{elements}++;
    $self->{attrs} = 0;
  }
  sub characters {
    my ($self,$str,$len) = @_;
    $self->{chars} += $len;
  }
  sub ignorable_whitespace {
    my ($self,$str,$len) = @_;
    $self->{ws} += $len;
  }
  
  package main;
  my $DOCUMENT_HANDLER = MyDocumentHandler->new();
  $parser->setDocumentHandler($DOCUMENT_HANDLER);
  
  my $t0 = new Benchmark;
  $parser->parse (XML::Xerces::LocalFileInputSource->new($file));
  my $t1 = new Benchmark;
  my $td = timediff($t1, $t0);
  
  print "$file: duration: ", timestr($td), "\n";
  print "elems: ", $DOCUMENT_HANDLER->{elements}, "\n"; 
  print "attrs: ", $DOCUMENT_HANDLER->{attrs}, "\n";
  print "whitespace: ", $DOCUMENT_HANDLER->{ws}, "\n";
  print "characters: ", $DOCUMENT_HANDLER->{chars}, "\n";
  
  
  ]]></source>
  </s1>
  
  
  

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


Mime
View raw message