From f3ff6609a1d710a3b8432f881a3a6d63d1987450 Mon Sep 17 00:00:00 2001 From: Jason Edward Stewart <jasons@apache.org> Date: Fri, 13 Oct 2006 21:27:00 +0000 Subject: [PATCH] initial framework for porting PSVIWriter sample git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@463842 13f79535-47bb-0310-9956-ffa450edef68 --- swig/perl/samples/PSVIWriter.pl | 109 ++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 swig/perl/samples/PSVIWriter.pl diff --git a/swig/perl/samples/PSVIWriter.pl b/swig/perl/samples/PSVIWriter.pl new file mode 100644 index 000000000..004fe54e2 --- /dev/null +++ b/swig/perl/samples/PSVIWriter.pl @@ -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(); +} -- GitLab