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 DOMCount.xml DOMCreate.xml DOMPrint.xml SAX2Count.xml SAXCount.xml
Date Tue, 07 May 2002 06:23:49 GMT
jasons      02/05/06 23:23:49

  Modified:    sources/xerces-p DOMCount.xml DOMCreate.xml DOMPrint.xml
                        SAX2Count.xml SAXCount.xml
  Log:
  updated versions
  
  Revision  Changes    Path
  1.3       +53 -14    xml-site/sources/xerces-p/DOMCount.xml
  
  Index: DOMCount.xml
  ===================================================================
  RCS file: /home/cvs/xml-site/sources/xerces-p/DOMCount.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DOMCount.xml	9 Jul 2001 05:16:29 -0000	1.2
  +++ DOMCount.xml	7 May 2002 06:23:49 -0000	1.3
  @@ -5,39 +5,78 @@
         <source><![CDATA[
   use strict;
   use XML::Xerces;
  -use Getopt::Std;
  -
  +use Getopt::Long;
  +use Benchmark;
  +use vars qw(%OPTIONS);
   
   #
   # Read and validate command line args
   #
   
  -my $USAGE = "USAGE: $0 [-v][-n] file\n";
  +my $USAGE = <<EOU;
  +USAGE: $0 [-v=xxx][-n] file
  +Options:
  +    -v=xxx      Validation scheme [always | never | auto*]
  +    -n          Enable namespace processing. Defaults to off.
  +    -s          Enable schema processing. Defaults to off.
  +
  +  * = Default if not provided explicitly
  +
  +EOU
  +my $VERSION = q[$Id: DOMCount.xml,v 1.3 2002/05/07 06:23:49 jasons Exp $ ];
  +
  +my $rc = GetOptions(\%OPTIONS,
  +		    'v=s',
  +		    'n',
  +		    's');
  +
  +die $USAGE unless $rc;
   
  -getopts ('vn') and ($#ARGV == 0)	or die "$USAGE";
  --f $ARGV[0] or die "File '$ARGV[0]' does not exist!\n";
  +die $USAGE unless scalar @ARGV;
   
  -my $validate = $::opt_v;
  -my $namespace = $::opt_n;
   my $file = $ARGV[0];
  +-f $file or die "File '$file' does not exist!\n";
  +
  +my $namespace = $OPTIONS{n} || 0;
  +my $schema = $OPTIONS{s} || 0;
  +my $validate = $OPTIONS{v} || 'auto';
  +
  +if (uc($validate) eq 'ALWAYS') {
  +  $validate = $XML::Xerces::DOMParser::Val_Always;
  +} elsif (uc($validate) eq 'NEVER') {
  +  $validate = $XML::Xerces::DOMParser::Val_Never;
  +} elsif (uc($validate) eq 'AUTO') {
  +  $validate = $XML::Xerces::DOMParser::Val_Auto;
  +} else {
  +  die("Unknown value for -v: $validate\n$USAGE");
  +}
  +
   
   #
   # Count the nodes
   #
   
   my $parser = XML::Xerces::DOMParser->new();
  -$parser->setDoValidation ($validate);
  +$parser->setValidationScheme ($validate);
   $parser->setDoNamespaces ($namespace);
  -my $error_handler = new XML::Xerces::perlErrorHandler;
  -$error_handler->setWarningFunction(\&XML::Xerces::warning);
  -$error_handler->setErrorFunction(\&XML::Xerces::error);
  -$error_handler->setFatalErrorFunction(\&XML::Xerces::fatal_error);
  +$parser->setCreateEntityReferenceNodes(1);
  +$parser->setDoSchema ($schema);
  +
  +my $error_handler = XML::Xerces::PerlErrorHandler->new();
   $parser->setErrorHandler($error_handler);
   
  -$parser->parse (XML::Xerces::LocalFileInputSource->new($file));
  +my $t0 = new Benchmark;
  +eval {
  +  $parser->parse ($file);
  +};
  +Xerces::error($@) if ($@);
  +
   my $doc = $parser->getDocument ();
   my $element_count = $doc->getElementsByTagName("*")->getLength();
  +my $t1 = new Benchmark;
  +my $td = timediff($t1, $t0);
   
  -print "$file: ($element_count elems)\n";
  +print STDOUT "$file: duration: ", timestr($td), "\n";
  +print STDOUT "\t($element_count elems)\n";
   ]]></source>
   </s1>
  
  
  
  1.2       +20 -3     xml-site/sources/xerces-p/DOMCreate.xml
  
  Index: DOMCreate.xml
  ===================================================================
  RCS file: /home/cvs/xml-site/sources/xerces-p/DOMCreate.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DOMCreate.xml	27 Mar 2001 00:37:39 -0000	1.1
  +++ DOMCreate.xml	7 May 2002 06:23:49 -0000	1.2
  @@ -12,10 +12,13 @@
   # create a document
   #
   
  -my $doc = XML::Xerces::DOM_Document::createDocument ();
  -my $root = $doc->createElement ("contributors");
  +my $impl = XML::Xerces::DOM_DOMImplementation::getImplementation();
  +my $dt = eval{$impl->createDocumentType('contributors', '', 'contributors.dtd')};
  +error($@) if $@;
  +my $doc = eval{$impl->createDocument('contributors', 'contributors',$dt)};
  +error($@) if $@;
   
  -$doc->appendChild ($root);
  +my $root = $doc->getDocumentElement();
   
   $root->appendChild(CreatePerson(	
   	$doc, 
  @@ -77,5 +80,19 @@
     $person->appendChild ($emailNode);
   }
   
  +
  +sub error {
  +  my $error = shift;
  +  print STDERR "Error in eval: ";
  +  if (ref $error) {
  +    print STDERR "msg: ", $error->getMessage();
  +    if (ref $error eq 'XML::Xerces::DOM_DOMException') {
  +      print STDERR "\n\tcode: ", $error->{code};
  +    }
  +  print STDERR "\n";
  +  } else {
  +    print STDERR $error;
  +  }
  +}
   ]]></source>
   </s1>
  
  
  
  1.2       +50 -12    xml-site/sources/xerces-p/DOMPrint.xml
  
  Index: DOMPrint.xml
  ===================================================================
  RCS file: /home/cvs/xml-site/sources/xerces-p/DOMPrint.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DOMPrint.xml	27 Mar 2001 00:37:39 -0000	1.1
  +++ DOMPrint.xml	7 May 2002 06:23:49 -0000	1.2
  @@ -4,38 +4,76 @@
   <s1 title="DOMPrint.pl">
         <source><![CDATA[
   use strict;
  -
  +# use blib;
   use XML::Xerces;
   use XML::Xerces::DOMParse;
  -use Getopt::Std;
  +use Getopt::Long;
  +use vars qw();
   
   #
   # Read and validate command line args
   #
   
  -my $USAGE = "USAGE: $0 [-v][-n] file\n";
  +my $USAGE = <<EOU;
  +USAGE: $0 [-v=xxx][-n] file
  +Options:
  +    -v=xxx      Validation scheme [always | never | auto*]
  +    -n          Enable namespace processing. Defaults to off.
  +    -s          Enable schema processing. Defaults to off.
  +
  +  * = Default if not provided explicitly
  +
  +EOU
  +my $VERSION = q[$Id: DOMPrint.xml,v 1.2 2002/05/07 06:23:49 jasons Exp $];
  +my %OPTIONS;
  +my $rc = GetOptions(\%OPTIONS,
  +		    'v=s',
  +		    'n',
  +		    's');
  +
  +die $USAGE unless $rc;
   
  -getopts ('vn') and ($#ARGV == 0)	or die "$USAGE";
  --f $ARGV[0] or die "File '$ARGV[0]' does not exist!\n";
  +die $USAGE unless scalar @ARGV;
   
  -my $validate = $::opt_v;
  -my $namespace = $::opt_n;
   my $file = $ARGV[0];
  +-f $file or die "File '$file' does not exist!\n";
   
  +my $namespace = $OPTIONS{n} || 0;
  +my $schema = $OPTIONS{s} || 0;
  +my $validate = $OPTIONS{v} || 'auto';
  +
  +if (uc($validate) eq 'ALWAYS') {
  +  $validate = $XML::Xerces::DOMParser::Val_Always;
  +} elsif (uc($validate) eq 'NEVER') {
  +  $validate = $XML::Xerces::DOMParser::Val_Never;
  +} elsif (uc($validate) eq 'AUTO') {
  +  $validate = $XML::Xerces::DOMParser::Val_Auto;
  +} else {
  +  die("Unknown value for -v: $validate\n$USAGE");
  +}
   
   #
   # Parse and print
   #
   
  -my $file = $ARGV[0];
   my $parser = XML::Xerces::DOMParser->new();
  +$parser->setValidationScheme ($validate);
   $parser->setDoNamespaces ($namespace);
  -$parser->setDoValidation ($validate);
  -$parser->parse (XML::Xerces::LocalFileInputSource->new($file));
  -my $doc = $parser->getDocument ();
  +$parser->setCreateEntityReferenceNodes(1);
  +$parser->setDoSchema ($schema);
  +
  +my $ERROR_HANDLER = XML::Xerces::PerlErrorHandler->new();
  +$parser->setErrorHandler($ERROR_HANDLER);
  +eval {
  +  $parser->parse (XML::Xerces::LocalFileInputSource->new($file));
  +};
  +XML::Xerces::error($@) if ($@);
  +
  +my $doc = $parser->getDocument();
   
   XML::Xerces::DOMParse::unformat ($doc);
   XML::Xerces::DOMParse::format ($doc);
   XML::Xerces::DOMParse::print (\*STDOUT, $doc);
  -      ]]></source>
  +exit(0);
  +]]></source>
   </s1>
  
  
  
  1.2       +71 -11    xml-site/sources/xerces-p/SAX2Count.xml
  
  Index: SAX2Count.xml
  ===================================================================
  RCS file: /home/cvs/xml-site/sources/xerces-p/SAX2Count.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SAX2Count.xml	9 Jul 2001 05:15:05 -0000	1.1
  +++ SAX2Count.xml	7 May 2002 06:23:49 -0000	1.2
  @@ -4,22 +4,53 @@
   <s1 title="DOMCount.pl">
         <source><![CDATA[
   use strict;
  +# use blib;
   use XML::Xerces;
  -use Getopt::Std;
  +use Getopt::Long;
   use vars qw($opt_v $opt_n);
   use Benchmark;
   #
   # Read and validate command line args
   #
   
  -my $USAGE = "USAGE: $0 [-v][-n] file\n";
  +my $USAGE = <<EOU;
  +USAGE: $0 [-v=xxx][-n] file
  +Options:
  +    -v=xxx      Validation scheme [always | never | auto*]
  +    -n          Enable namespace processing. Defaults to off.
  +    -s          Enable schema processing. Defaults to off.
  +
  +  * = Default if not provided explicitly
  +
  +EOU
  +my $VERSION = q[$Id: SAX2Count.xml,v 1.2 2002/05/07 06:23:49 jasons Exp $ ];
  +
  +my %OPTIONS;
  +my $rc = GetOptions(\%OPTIONS,
  +		    'v=s',
  +		    'n',
  +		    's');
   
  -getopts ('vn') && ($#ARGV == 0)	or die "$USAGE";
  --f $ARGV[0] or die "File '$ARGV[0]' does not exist!\n";
  +die $USAGE unless $rc;
  +
  +die $USAGE unless scalar @ARGV;
   
  -my $validate = $opt_v || 0;
  -my $namespace = $opt_n || 0;
   my $file = $ARGV[0];
  +-f $file or die "File '$file' does not exist!\n";
  +
  +my $namespace = $OPTIONS{n} || 0;
  +my $schema = $OPTIONS{s} || 0;
  +my $validate = $OPTIONS{v} || 'auto';
  +
  +if (uc($validate) eq 'ALWAYS') {
  +  $validate = $XML::Xerces::SAX2XMLReader::Val_Always;
  +} elsif (uc($validate) eq 'NEVER') {
  +  $validate = $XML::Xerces::SAX2XMLReader::Val_Never;
  +} elsif (uc($validate) eq 'AUTO') {
  +  $validate = $XML::Xerces::SAX2XMLReader::Val_Auto;
  +} else {
  +  die("Unknown value for -v: $validate\n$USAGE");
  +}
   
   #
   # Count the nodes
  @@ -31,9 +62,12 @@
   @ISA = qw(XML::Xerces::PerlContentHandler);
   
   sub start_element {
  -  my $self = shift;
  +  my ($self,$uri,$localname,$qname,$attrs) = @_;
     $self->{elements}++;
  -  $self->{attrs} = 0;
  +  $self->{attrs} += $attrs->getLength;
  +}
  +sub end_element {
  +  my ($self,$uri,$localname,$qname) = @_;
   }
   sub characters {
     my ($self,$str,$len) = @_;
  @@ -46,16 +80,42 @@
   
   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);
  +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 $@;
  +  }
  +}
   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));
  +};
  +XML::Xerces::error($@) if ($@);
  +
   my $t1 = new Benchmark;
   my $td = timediff($t1, $t0);
   
  
  
  
  1.2       +53 -12    xml-site/sources/xerces-p/SAXCount.xml
  
  Index: SAXCount.xml
  ===================================================================
  RCS file: /home/cvs/xml-site/sources/xerces-p/SAXCount.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SAXCount.xml	9 Jul 2001 05:15:06 -0000	1.1
  +++ SAXCount.xml	7 May 2002 06:23:49 -0000	1.2
  @@ -4,30 +4,62 @@
   <s1 title="DOMCount.pl">
         <source><![CDATA[
   use strict;
  +# use blib;
   use XML::Xerces;
  -use Getopt::Std;
  +use Getopt::Long;
   use vars qw($opt_v $opt_n);
   use Benchmark;
   #
   # Read and validate command line args
   #
   
  -my $USAGE = "USAGE: $0 [-v][-n] file\n";
  +my $USAGE = <<EOU;
  +USAGE: $0 [-v=xxx][-n] file
  +Options:
  +    -v=xxx      Validation scheme [always | never | auto*]
  +    -n          Enable namespace processing. Defaults to off.
  +    -s          Enable schema processing. Defaults to off.
  +
  +  * = Default if not provided explicitly
  +
  +EOU
  +
  +my $VERSION = q[$Id: SAXCount.xml,v 1.2 2002/05/07 06:23:49 jasons Exp $ ];
  +my %OPTIONS;
  +my $rc = GetOptions(\%OPTIONS,
  +		    'v=s',
  +		    'n',
  +		    's');
   
  -getopts ('vn') && ($#ARGV == 0)	or die "$USAGE";
  --f $ARGV[0] or die "File '$ARGV[0]' does not exist!\n";
  +die $USAGE unless $rc;
  +
  +die $USAGE unless scalar @ARGV;
   
  -my $validate = $opt_v || 0;
  -my $namespace = $opt_n || 0;
   my $file = $ARGV[0];
  +-f $file or die "File '$file' does not exist!\n";
  +
  +my $namespace = $OPTIONS{n} || 0;
  +my $schema = $OPTIONS{s} || 0;
  +my $validate = $OPTIONS{v} || 'auto';
  +
  +if (uc($validate) eq 'ALWAYS') {
  +  $validate = $XML::Xerces::SAXParser::Val_Always;
  +} elsif (uc($validate) eq 'NEVER') {
  +  $validate = $XML::Xerces::SAXParser::Val_Never;
  +} elsif (uc($validate) eq 'AUTO') {
  +  $validate = $XML::Xerces::SAXParser::Val_Auto;
  +} else {
  +  die("Unknown value for -v: $validate\n$USAGE");
  +}
   
   #
   # Count the nodes
   #
   
   my $parser = XML::Xerces::SAXParser->new();
  -$parser->setDoValidation ($validate);
  +$parser->setValidationScheme ($validate);
   $parser->setDoNamespaces ($namespace);
  +$parser->setDoSchema ($schema);
   my $ERROR_HANDLER = XML::Xerces::PerlErrorHandler->new();
   $parser->setErrorHandler($ERROR_HANDLER);
   
  @@ -37,9 +69,12 @@
   @ISA = qw(XML::Xerces::PerlDocumentHandler);
   
   sub start_element {
  -  my $self = shift;
  +  my ($self,$name,$attrs) = @_;
     $self->{elements}++;
  -  $self->{attrs} = 0;
  +  $self->{attrs} += $attrs->getLength();
  +}
  +sub end_element {
  +  my ($self,$name) = @_;
   }
   sub characters {
     my ($self,$str,$len) = @_;
  @@ -54,8 +89,16 @@
   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));
  +};
  +XML::Xerces::error($@) if ($@);
  +
   my $t1 = new Benchmark;
   my $td = timediff($t1, $t0);
   
  @@ -64,7 +107,5 @@
   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