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 2006/10/13 23:27:02 UTC

svn commit: r463842 - /xerces/c/trunk/swig/perl/samples/PSVIWriter.pl

Author: jasons
Date: Fri Oct 13 14:27:00 2006
New Revision: 463842

URL: http://svn.apache.org/viewvc?view=rev&rev=463842
Log:
initial framework for porting PSVIWriter sample

Added:
    xerces/c/trunk/swig/perl/samples/PSVIWriter.pl

Added: xerces/c/trunk/swig/perl/samples/PSVIWriter.pl
URL: http://svn.apache.org/viewvc/xerces/c/trunk/swig/perl/samples/PSVIWriter.pl?view=auto&rev=463842
==============================================================================
--- xerces/c/trunk/swig/perl/samples/PSVIWriter.pl (added)
+++ xerces/c/trunk/swig/perl/samples/PSVIWriter.pl Fri Oct 13 14:27:00 2006
@@ -0,0 +1,109 @@
+ #
+ #  Copyright 2002,2004 The Apache Software Foundation.
+ #
+ #  Licensed under the Apache License, Version 2.0 (the "License");
+ #  you may not use this file except in compliance with the License.
+ #  You may obtain a copy of the License at
+ #
+ #       http://www.apache.org/licenses/LICENSE-2.0
+ #
+ #  Unless required by applicable law or agreed to in writing, software
+ #  distributed under the License is distributed on an "AS IS" BASIS,
+ #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ #  See the License for the specific language governing permissions and
+ #  limitations under the License.
+ #
+
+######################################################################
+#
+# PSVIWriter
+#
+# This sample is modeled after its Xerces-C counterpart.  You give it an
+# XML file and it parses it and writes out PSVI information.
+#
+######################################################################
+
+use strict;
+# use blib;
+use XML::Xerces::DOM;
+use XML::Xerces::SAX;
+use Getopt::Long;
+use Benchmark;
+use vars qw(%OPTIONS);
+
+#
+# Read and validate command line args
+#
+
+my $USAGE = <<EOU;
+USAGE: $0 file
+EOU
+my $VERSION = q[$Id: DOMCount.pl,v 1.13 2002/08/27 19:33:19 jasons Exp $ ];
+
+my $rc = GetOptions(\%OPTIONS,
+		    'help');
+
+die $USAGE if exists $OPTIONS{help};
+die $USAGE unless scalar @ARGV;
+
+my $file = $ARGV[0];
+-f $file or die "File '$file' does not exist!\n";
+
+  # NOTICE: We must now explicitly call XMLPlatformUtils::Initialize()
+  #   when the module is loaded. Xerces.pm no longer does this.
+  #
+  #
+XML::Xerces::XMLPlatformUtils::Initialize();
+
+my $TRUE = 1;
+my $FALSE = 0;
+my $use_schema = $FALSE;
+my $unrep_flags = $XML::Xerces::XMLFormatter::UnRep_Fail;
+my $encoding_name = "UTF8";
+
+my $parser = XML::Xerces::XMLReaderFactory::createXMLReader();
+$parser->setFeature($XML::Xerces::XMLUni::fgSAX2CoreNameSpaces, $TRUE);
+$parser->setFeature($XML::Xerces::XMLUni::fgXercesSchema, $TRUE);
+$parser->setFeature($XML::Xerces::XMLUni::fgXercesSchemaFullChecking, $use_schema);
+$parser->setFeature($XML::Xerces::XMLUni::fgSAX2CoreNameSpacePrefixes, $FALSE);
+$parser->setFeature($XML::Xerces::XMLUni::fgSAX2CoreValidation, $TRUE);
+$parser->setFeature($XML::Xerces::XMLUni::fgXercesDynamic, $TRUE);
+
+
+my $psvi_target = XML::Xerces::StdOutFormatTarget->new();
+my $psvi_formatter = XML::Xerces::XMLFormatter->new($encoding_name,
+						   $psvi_target,
+						   $XML::Xerces::XMLFormatter::NoEscapes,
+						   $unrep_flags);
+
+my $error_target = XML::Xerces::StdOutFormatTarget->new();
+my $error_formatter = XML::Xerces::XMLFormatter->new($encoding_name,
+						     $error_target,
+						     $XML::Xerces::XMLFormatter::NoEscapes,
+						     $unrep_flags);
+
+
+my $t0 = new Benchmark;
+eval {$parser->parse($file)};
+error($@) if $@;
+
+
+my $count = $parser->getErrorCount();
+if ($count == 0) {
+  printf STDOUT "Successful parse\n";
+} else {
+  print STDERR "Errors occurred, no output available\n";
+}
+my $t1 = new Benchmark;
+my $td = timediff($t1, $t0);
+
+print STDOUT "$file: duration: ", timestr($td), "\n";
+exit(0);
+
+END {
+  # NOTICE: We must now explicitly call XMLPlatformUtils::Terminate()
+  #   when the module is unloaded. Xerces.pm no longer does this for us
+  #
+  #
+  XML::Xerces::XMLPlatformUtils::Terminate();
+}



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