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/targets/xerces-p domcount.html domcreate.html domprint.html sax2count.html saxcount.html
Date Tue, 07 May 2002 06:24:32 GMT
jasons      02/05/06 23:24:32

  Modified:    targets/xerces-p domcount.html domcreate.html domprint.html
                        sax2count.html saxcount.html
  Log:
  updated versions
  
  Revision  Changes    Path
  1.8       +53 -14    xml-site/targets/xerces-p/domcount.html
  
  Index: domcount.html
  ===================================================================
  RCS file: /home/cvs/xml-site/targets/xerces-p/domcount.html,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- domcount.html	9 Jul 2001 05:29:42 -0000	1.7
  +++ domcount.html	7 May 2002 06:24:32 -0000	1.8
  @@ -15,40 +15,79 @@
         <DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="4" width="464"><TR><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" width="1"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD
bgcolor="#ffffff" width="462"><FONT size="-1"><PRE>
   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 = &quot;USAGE: $0 [-v][-n] file\n&quot;;
  +my $USAGE = &lt;&lt;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.html,v 1.8 2002/05/07 06:24:32 jasons Exp $ ];
  +
  +my $rc = GetOptions(\%OPTIONS,
  +		    'v=s',
  +		    'n',
  +		    's');
  +
  +die $USAGE unless $rc;
   
  -getopts ('vn') and ($#ARGV == 0)	or die &quot;$USAGE&quot;;
  --f $ARGV[0] or die &quot;File '$ARGV[0]' does not exist!\n&quot;;
  +die $USAGE unless scalar @ARGV;
   
  -my $validate = $::opt_v;
  -my $namespace = $::opt_n;
   my $file = $ARGV[0];
  +-f $file or die &quot;File '$file' does not exist!\n&quot;;
  +
  +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(&quot;Unknown value for -v: $validate\n$USAGE&quot;);
  +}
  +
   
   #
   # Count the nodes
   #
   
   my $parser = XML::Xerces::DOMParser-&gt;new();
  -$parser-&gt;setDoValidation ($validate);
  +$parser-&gt;setValidationScheme ($validate);
   $parser-&gt;setDoNamespaces ($namespace);
  -my $error_handler = new XML::Xerces::perlErrorHandler;
  -$error_handler-&gt;setWarningFunction(\&amp;XML::Xerces::warning);
  -$error_handler-&gt;setErrorFunction(\&amp;XML::Xerces::error);
  -$error_handler-&gt;setFatalErrorFunction(\&amp;XML::Xerces::fatal_error);
  +$parser-&gt;setCreateEntityReferenceNodes(1);
  +$parser-&gt;setDoSchema ($schema);
  +
  +my $error_handler = XML::Xerces::PerlErrorHandler-&gt;new();
   $parser-&gt;setErrorHandler($error_handler);
   
  -$parser-&gt;parse (XML::Xerces::LocalFileInputSource-&gt;new($file));
  +my $t0 = new Benchmark;
  +eval {
  +  $parser-&gt;parse ($file);
  +};
  +Xerces::error($@) if ($@);
  +
   my $doc = $parser-&gt;getDocument ();
   my $element_count = $doc-&gt;getElementsByTagName(&quot;*&quot;)-&gt;getLength();
  +my $t1 = new Benchmark;
  +my $td = timediff($t1, $t0);
   
  -print &quot;$file: ($element_count elems)\n&quot;;
  +print STDOUT &quot;$file: duration: &quot;, timestr($td), &quot;\n&quot;;
  +print STDOUT &quot;\t($element_count elems)\n&quot;;
   </PRE></FONT></TD><TD bgcolor="#0086b2" width="1"><IMG border="0"
height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD></TR></TABLE></DIV>
   </TD></TR></TABLE></TD></TR></TABLE><BR><TABLE
border="0" cellpadding="0" cellspacing="0" width="620"><TR><TD bgcolor="#0086b2"><IMG
height="1" src="images/dot.gif" width="1"></TD></TR><TR><TD align="center"><FONT
color="#0086b2" size="-1"><I>
                 Copyright &copy; 2001 The Apache Software Foundation.
  
  
  
  1.7       +20 -3     xml-site/targets/xerces-p/domcreate.html
  
  Index: domcreate.html
  ===================================================================
  RCS file: /home/cvs/xml-site/targets/xerces-p/domcreate.html,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- domcreate.html	9 Jul 2001 05:29:42 -0000	1.6
  +++ domcreate.html	7 May 2002 06:24:32 -0000	1.7
  @@ -22,10 +22,13 @@
   # create a document
   #
   
  -my $doc = XML::Xerces::DOM_Document::createDocument ();
  -my $root = $doc-&gt;createElement (&quot;contributors&quot;);
  +my $impl = XML::Xerces::DOM_DOMImplementation::getImplementation();
  +my $dt = eval{$impl-&gt;createDocumentType('contributors', '', 'contributors.dtd')};
  +error($@) if $@;
  +my $doc = eval{$impl-&gt;createDocument('contributors', 'contributors',$dt)};
  +error($@) if $@;
   
  -$doc-&gt;appendChild ($root);
  +my $root = $doc-&gt;getDocumentElement();
   
   $root-&gt;appendChild(CreatePerson(	
   	$doc, 
  @@ -87,6 +90,20 @@
     $person-&gt;appendChild ($emailNode);
   }
   
  +
  +sub error {
  +  my $error = shift;
  +  print STDERR &quot;Error in eval: &quot;;
  +  if (ref $error) {
  +    print STDERR &quot;msg: &quot;, $error-&gt;getMessage();
  +    if (ref $error eq 'XML::Xerces::DOM_DOMException') {
  +      print STDERR &quot;\n\tcode: &quot;, $error-&gt;{code};
  +    }
  +  print STDERR &quot;\n&quot;;
  +  } else {
  +    print STDERR $error;
  +  }
  +}
   </PRE></FONT></TD><TD bgcolor="#0086b2" width="1"><IMG border="0"
height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD></TR></TABLE></DIV>
   </TD></TR></TABLE></TD></TR></TABLE><BR><TABLE
border="0" cellpadding="0" cellspacing="0" width="620"><TR><TD bgcolor="#0086b2"><IMG
height="1" src="images/dot.gif" width="1"></TD></TR><TR><TD align="center"><FONT
color="#0086b2" size="-1"><I>
                 Copyright &copy; 2001 The Apache Software Foundation.
  
  
  
  1.7       +50 -12    xml-site/targets/xerces-p/domprint.html
  
  Index: domprint.html
  ===================================================================
  RCS file: /home/cvs/xml-site/targets/xerces-p/domprint.html,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- domprint.html	9 Jul 2001 05:29:43 -0000	1.6
  +++ domprint.html	7 May 2002 06:24:32 -0000	1.7
  @@ -14,40 +14,78 @@
   <IMG border="0" height="14" hspace="0" src="resources/close.gif" vspace="0" width="120"><BR></TD><TD
align="left" valign="top" width="500"><TABLE border="0" cellpadding="3" cellspacing="0"><TR><TD>
         <DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="4" width="464"><TR><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" width="1"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD
bgcolor="#ffffff" width="462"><FONT size="-1"><PRE>
   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 = &quot;USAGE: $0 [-v][-n] file\n&quot;;
  +my $USAGE = &lt;&lt;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.html,v 1.7 2002/05/07 06:24:32 jasons Exp $];
  +my %OPTIONS;
  +my $rc = GetOptions(\%OPTIONS,
  +		    'v=s',
  +		    'n',
  +		    's');
  +
  +die $USAGE unless $rc;
   
  -getopts ('vn') and ($#ARGV == 0)	or die &quot;$USAGE&quot;;
  --f $ARGV[0] or die &quot;File '$ARGV[0]' does not exist!\n&quot;;
  +die $USAGE unless scalar @ARGV;
   
  -my $validate = $::opt_v;
  -my $namespace = $::opt_n;
   my $file = $ARGV[0];
  +-f $file or die &quot;File '$file' does not exist!\n&quot;;
   
  +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(&quot;Unknown value for -v: $validate\n$USAGE&quot;);
  +}
   
   #
   # Parse and print
   #
   
  -my $file = $ARGV[0];
   my $parser = XML::Xerces::DOMParser-&gt;new();
  +$parser-&gt;setValidationScheme ($validate);
   $parser-&gt;setDoNamespaces ($namespace);
  -$parser-&gt;setDoValidation ($validate);
  -$parser-&gt;parse (XML::Xerces::LocalFileInputSource-&gt;new($file));
  -my $doc = $parser-&gt;getDocument ();
  +$parser-&gt;setCreateEntityReferenceNodes(1);
  +$parser-&gt;setDoSchema ($schema);
  +
  +my $ERROR_HANDLER = XML::Xerces::PerlErrorHandler-&gt;new();
  +$parser-&gt;setErrorHandler($ERROR_HANDLER);
  +eval {
  +  $parser-&gt;parse (XML::Xerces::LocalFileInputSource-&gt;new($file));
  +};
  +XML::Xerces::error($@) if ($@);
  +
  +my $doc = $parser-&gt;getDocument();
   
   XML::Xerces::DOMParse::unformat ($doc);
   XML::Xerces::DOMParse::format ($doc);
   XML::Xerces::DOMParse::print (\*STDOUT, $doc);
  -      </PRE></FONT></TD><TD bgcolor="#0086b2" width="1"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD></TR></TABLE></DIV>
  +exit(0);
  +</PRE></FONT></TD><TD bgcolor="#0086b2" width="1"><IMG border="0"
height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD></TR></TABLE></DIV>
   </TD></TR></TABLE></TD></TR></TABLE><BR><TABLE
border="0" cellpadding="0" cellspacing="0" width="620"><TR><TD bgcolor="#0086b2"><IMG
height="1" src="images/dot.gif" width="1"></TD></TR><TR><TD align="center"><FONT
color="#0086b2" size="-1"><I>
                 Copyright &copy; 2001 The Apache Software Foundation.
                 All Rights Reserved.
  
  
  
  1.3       +71 -11    xml-site/targets/xerces-p/sax2count.html
  
  Index: sax2count.html
  ===================================================================
  RCS file: /home/cvs/xml-site/targets/xerces-p/sax2count.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- sax2count.html	9 Jul 2001 05:29:43 -0000	1.2
  +++ sax2count.html	7 May 2002 06:24:32 -0000	1.3
  @@ -14,22 +14,53 @@
   <IMG border="0" height="14" hspace="0" src="resources/close.gif" vspace="0" width="120"><BR></TD><TD
align="left" valign="top" width="500"><TABLE border="0" cellpadding="3" cellspacing="0"><TR><TD>
         <DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="4" width="464"><TR><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" width="1"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD
bgcolor="#ffffff" width="462"><FONT size="-1"><PRE>
   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 = &quot;USAGE: $0 [-v][-n] file\n&quot;;
  +my $USAGE = &lt;&lt;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.html,v 1.3 2002/05/07 06:24:32 jasons Exp $ ];
  +
  +my %OPTIONS;
  +my $rc = GetOptions(\%OPTIONS,
  +		    'v=s',
  +		    'n',
  +		    's');
   
  -getopts ('vn') &amp;&amp; ($#ARGV == 0)	or die &quot;$USAGE&quot;;
  --f $ARGV[0] or die &quot;File '$ARGV[0]' does not exist!\n&quot;;
  +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 &quot;File '$file' does not exist!\n&quot;;
  +
  +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(&quot;Unknown value for -v: $validate\n$USAGE&quot;);
  +}
   
   #
   # Count the nodes
  @@ -41,9 +72,12 @@
   @ISA = qw(XML::Xerces::PerlContentHandler);
   
   sub start_element {
  -  my $self = shift;
  +  my ($self,$uri,$localname,$qname,$attrs) = @_;
     $self-&gt;{elements}++;
  -  $self-&gt;{attrs} = 0;
  +  $self-&gt;{attrs} += $attrs-&gt;getLength;
  +}
  +sub end_element {
  +  my ($self,$uri,$localname,$qname) = @_;
   }
   sub characters {
     my ($self,$str,$len) = @_;
  @@ -56,16 +90,42 @@
   
   package main;
   my $parser = XML::Xerces::XMLReaderFactory::createXMLReader();
  -$parser-&gt;setFeature(&quot;http://xml.org/sax/features/namespaces&quot;,
$namespace);
  -$parser-&gt;setFeature(&quot;http://xml.org/sax/features/validation&quot;,
$validate);
  +eval {
  +  $parser-&gt;setFeature(&quot;http://xml.org/sax/features/namespaces&quot;,
$namespace);
  +  if ($validate eq $XML::Xerces::SAX2XMLReader::Val_Auto) {
  +    $parser-&gt;setFeature(&quot;http://xml.org/sax/features/validation&quot;,
1);
  +    $parser-&gt;setFeature(&quot;http://apache.org/xml/features/validation/dynamic&quot;,
1);
  +  } elsif ($validate eq $XML::Xerces::SAX2XMLReader::Val_Never) {
  +    $parser-&gt;setFeature(&quot;http://xml.org/sax/features/validation&quot;,
0);
  +  } elsif ($validate eq $XML::Xerces::SAX2XMLReader::Val_Always) {
  +    $parser-&gt;setFeature(&quot;http://xml.org/sax/features/validation&quot;,
1);
  +    $parser-&gt;setFeature(&quot;http://apache.org/xml/features/validation/dynamic&quot;,
0);
  +  }
  +  $parser-&gt;setFeature(&quot;http://apache.org/xml/features/validation/schema&quot;,
$schema);
  +};
  +if ($@) {
  +  if (ref $@) {
  +    die $@-&gt;getMessage();
  +  } else {
  +    die $@;
  +  }
  +}
   my $error_handler = XML::Xerces::PerlErrorHandler-&gt;new();
   $parser-&gt;setErrorHandler($error_handler);
   
   my $CONTENT_HANDLER = MyContentHandler-&gt;new();
   $parser-&gt;setContentHandler($CONTENT_HANDLER);
  +$CONTENT_HANDLER-&gt;{elements} = 0;
  +$CONTENT_HANDLER-&gt;{attrs} = 0;
  +$CONTENT_HANDLER-&gt;{ws} = 0;
  +$CONTENT_HANDLER-&gt;{chars} = 0;
   
   my $t0 = new Benchmark;
  -$parser-&gt;parse (XML::Xerces::LocalFileInputSource-&gt;new($file));
  +eval {
  +  $parser-&gt;parse (XML::Xerces::LocalFileInputSource-&gt;new($file));
  +};
  +XML::Xerces::error($@) if ($@);
  +
   my $t1 = new Benchmark;
   my $td = timediff($t1, $t0);
   
  
  
  
  1.3       +53 -12    xml-site/targets/xerces-p/saxcount.html
  
  Index: saxcount.html
  ===================================================================
  RCS file: /home/cvs/xml-site/targets/xerces-p/saxcount.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- saxcount.html	9 Jul 2001 05:29:43 -0000	1.2
  +++ saxcount.html	7 May 2002 06:24:32 -0000	1.3
  @@ -14,30 +14,62 @@
   <IMG border="0" height="14" hspace="0" src="resources/close.gif" vspace="0" width="120"><BR></TD><TD
align="left" valign="top" width="500"><TABLE border="0" cellpadding="3" cellspacing="0"><TR><TD>
         <DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="4" width="464"><TR><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" width="1"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD
bgcolor="#ffffff" width="462"><FONT size="-1"><PRE>
   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 = &quot;USAGE: $0 [-v][-n] file\n&quot;;
  +my $USAGE = &lt;&lt;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.html,v 1.3 2002/05/07 06:24:32 jasons Exp $ ];
  +my %OPTIONS;
  +my $rc = GetOptions(\%OPTIONS,
  +		    'v=s',
  +		    'n',
  +		    's');
   
  -getopts ('vn') &amp;&amp; ($#ARGV == 0)	or die &quot;$USAGE&quot;;
  --f $ARGV[0] or die &quot;File '$ARGV[0]' does not exist!\n&quot;;
  +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 &quot;File '$file' does not exist!\n&quot;;
  +
  +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(&quot;Unknown value for -v: $validate\n$USAGE&quot;);
  +}
   
   #
   # Count the nodes
   #
   
   my $parser = XML::Xerces::SAXParser-&gt;new();
  -$parser-&gt;setDoValidation ($validate);
  +$parser-&gt;setValidationScheme ($validate);
   $parser-&gt;setDoNamespaces ($namespace);
  +$parser-&gt;setDoSchema ($schema);
   my $ERROR_HANDLER = XML::Xerces::PerlErrorHandler-&gt;new();
   $parser-&gt;setErrorHandler($ERROR_HANDLER);
   
  @@ -47,9 +79,12 @@
   @ISA = qw(XML::Xerces::PerlDocumentHandler);
   
   sub start_element {
  -  my $self = shift;
  +  my ($self,$name,$attrs) = @_;
     $self-&gt;{elements}++;
  -  $self-&gt;{attrs} = 0;
  +  $self-&gt;{attrs} += $attrs-&gt;getLength();
  +}
  +sub end_element {
  +  my ($self,$name) = @_;
   }
   sub characters {
     my ($self,$str,$len) = @_;
  @@ -64,8 +99,16 @@
   my $DOCUMENT_HANDLER = MyDocumentHandler-&gt;new();
   $parser-&gt;setDocumentHandler($DOCUMENT_HANDLER);
   
  +$DOCUMENT_HANDLER-&gt;{elements} = 0;
  +$DOCUMENT_HANDLER-&gt;{attrs} = 0;
  +$DOCUMENT_HANDLER-&gt;{ws} = 0;
  +$DOCUMENT_HANDLER-&gt;{chars} = 0;
   my $t0 = new Benchmark;
  -$parser-&gt;parse (XML::Xerces::LocalFileInputSource-&gt;new($file));
  +eval {
  +  $parser-&gt;parse (XML::Xerces::LocalFileInputSource-&gt;new($file));
  +};
  +XML::Xerces::error($@) if ($@);
  +
   my $t1 = new Benchmark;
   my $td = timediff($t1, $t0);
   
  @@ -74,8 +117,6 @@
   print &quot;attrs: &quot;, $DOCUMENT_HANDLER-&gt;{attrs}, &quot;\n&quot;;
   print &quot;whitespace: &quot;, $DOCUMENT_HANDLER-&gt;{ws}, &quot;\n&quot;;
   print &quot;characters: &quot;, $DOCUMENT_HANDLER-&gt;{chars}, &quot;\n&quot;;
  -
  -
   </PRE></FONT></TD><TD bgcolor="#0086b2" width="1"><IMG border="0"
height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="462"><IMG
border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="462"></TD><TD
bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif"
vspace="0" width="1"></TD></TR></TABLE></DIV>
   </TD></TR></TABLE></TD></TR></TABLE><BR><TABLE
border="0" cellpadding="0" cellspacing="0" width="620"><TR><TD bgcolor="#0086b2"><IMG
height="1" src="images/dot.gif" width="1"></TD></TR><TR><TD align="center"><FONT
color="#0086b2" size="-1"><I>
                 Copyright &copy; 2001 The Apache Software Foundation.
  
  
  

---------------------------------------------------------------------
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