From: robic0 on
On 2 Oct 2006 11:17:36 -0700, "Sean" <seanatpurdue(a)hotmail.com> wrote:

>I downloaded the XML-Parser module from
>http://search.cpan.org/~msergeant/XML-Parser/Parser.pm
>and I untar the source ball to $HOME/local/XML-Parser-2.34.
>Can someone give me some helps? I appreciate!
>
>
<snip>

Just some cut & paste to hopefully get you on track.....
--------------

Using AS Perl:
Its been a couple of years and I can't remeber exactly but
I think all of this is available in the repository and auto
installs using ppm.
Installing Xerces however, is a different thing.
Its great for schema checking. I've only installed it for win32
platform.

After install, my perl docs look like this:

XML
NamespaceSupport
Parser
Expat
Lite
Style
Debug
Objects
Stream
Subs
Tree
SAX
Base
DocumentLocator
Exception
Intro
ParserFactory
PurePerl
Reader
Simple
FAQ

Don't use SAX, its slower than drying paint.
Eventually you should be able to do this:
------------------------------------------------
use XML::Xerces;

use XML::Parser::Expat;
use XML::Simple;
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
#use Data::Dumper;

## Loop through some file list
next if (!ValidateSchema ($fullname));
#open the file

## Parse xml and integrity check
my $parser = new XML::Parser::Expat;
$parser->setHandlers('Start' => \&stag_h,
'End' => \&etag_h,
'Char' => \&cdata_h);
$parser->setHandlers('Comment' => \&comment_h) if (clog);

eval {$parser->parse(*SAMP)};
if ($@) {
## xml integrity failed -log this error
$@ =~ s/^[\x20\n\t]+//; $@ =~ s/[\x20\n\t]+$//;
# attempt strip off program line,col info at end
$@ =~ s/(at line [0-9]+,.+)?at .+ line [0-9]+$/$1/;
reporterror($@, $XML_File);
}
close(SAMP);
$parser->release;


##
##
sub ValidateSchema {
my ($xfile) = @_;
#my $valerr = 0;

# Docs: http://xml.apache.org/xerces-c/apiDocs/classAbstractDOMParser.html#z869_9
my $Xparser = XML::Xerces::XercesDOMParser->new();
$Xparser->setValidationScheme(1);
$Xparser->setDoNamespaces(1);
$Xparser->setDoSchema(1);
#$Xparser->setValidationSchemaFullChecking(1); # full constraint (if enabled, may be time-consuming)

$Xparser->setExternalNoNamespaceSchemaLocation($hVdef{'Schema'});

my $ERROR_HANDLER = XLoggingErrorHandler->new(\&LogX_warn, \&LogX_error, \&LogX_ferror, );
#my $ERROR_HANDLER = XML::Xerces::PerlErrorHandler->new();
$Xparser->setErrorHandler($ERROR_HANDLER);

eval {$Xparser->parse (XML::Xerces::LocalFileInputSource->new($xfile));};
## this not to be used ...
if ($@) {
# if (ref $@) {
# my $msg = $@->getMessage();
# $msg =~ s/^[\x20\n\t]+//; $msg =~ s/[\x20\n\t]+$//;
# LogInfo ($msg,1,0);
# } else {
# die $@;
# $@ =~ s/^[\x20\n\t]+//; $@ =~ s/[\x20\n\t]+$//;
# LogInfo ("$@",1,0);
# }
# $valerr = 1;
}
return 1;
}
##
## Error logging callbacks for Xlogging class
##
sub LogX_warn {...}
sub LogX_error {...}
sub LogX_ferror{...}


################################################################################
## Custom Error logging handler CLASS for Xerces
## (not alot of docs for this, just pass the message to the callers log handlers)
##
package XLoggingErrorHandler;
#use Carp;
use vars qw(@ISA);
@ISA = qw();
sub new {
my $class = shift;
my $self = {};
$self->{'Warnlog_h'} = shift;
$self->{'Errlog_h'} = shift;
$self->{'Ferrlog_h'} = shift;
return bless $self, $class;
}
sub warning
{
my ($self, $iref) = @_;
if (defined $self->{'Warnlog_h'}) {
$self->{'Warnlog_h'}(fmt_msg($iref));
} else {
print "No warning msg handler for msg: ".fmt_msg($iref)."\n";
die ("no msg");
}
}
sub error
{
my ($self, $iref) = @_;
if (defined $self->{'Errlog_h'}) {
$self->{'Errlog_h'}(fmt_msg($iref));
} else {
print "No error msg handler for msg: ".fmt_msg($iref)."\n";
}
die ("no msg");
}
sub fatal_error
{
my ($self, $iref) = @_;
if (defined $self->{'Ferrlog_h'}) {
$self->{'Ferrlog_h'}(fmt_msg($iref));
} else {
print "No fatal error msg handler for msg: ".fmt_msg($iref)."\n";
}
die ("no msg");
}
sub reset_errors {}
sub fmt_msg
{
my $iref = shift;
#return ($iref->getLineNumber.", ".$iref->getColumnNumber.": ".$iref->getMessage);
return ($iref->getMessage." at line ".$iref->getLineNumber.", column ".$iref->getColumnNumber);
}


-------------------------------------------
This goes on the top of your program.
This is a general block to get Perl2Exe to work with this:

## Utf8 bug workaround; Force RE to load.
## Notice- this generates warnings only when running the exe
## if not compiled with warnings off. Go into \perl\lib\utf8_heavy.pl
## and comment "#use warnings", then use P2e to build it.
eval { XMLin( '<hell>hy</hell>' , SuppressEmpty => '') };

OR just turn it off for that module ?

#=====================================================
# For Perl2Exe 8.60 - Win32
#
my $P2E = ($^X =~ /(perl)|(perl\.exe)$/i) ? 0 : 1;
my $progname = $P2E ? "myprog.exe" : "perl myprog.pl";
$0 = $^X unless ($^X =~ m%(^|[/\\])(perl)|(perl.exe)$%i);
my ($progdir) = $0 =~ m%^(.*)[/\\]%;
$progdir ||= ".";# if (length($progdir)>0);

#use XML::NamespaceSupport; # uncomment for P2x binary
#use XML::Parser::Style::Tree; # uncomment for P2x binary
#use bytes; # uncomment for P2x binary
#use File::Glob ':glob'; # uncomment for P2x binary

#perl2exe_include "utf8_heavy.pl";
#require "unicore/lib/SpacePer.pl";
#perl2exe_include "unicore/To/Lower.pl";
#perl2exe_include "unicore/To/Upper.pl";
#perl2exe_include "unicore/To/Fold.pl";
#require "unicore/lib/Digit.pl";
#require "unicore/lib/Word.pl";
#perl2exe_include "Encode/Unicode.pm";

#perl2exe_info FileVersion=1.0.0.0
#perl2exe_info CompanyName=
#perl2exe_info FileDescription=
#perl2exe_info InternalName=
#perl2exe_info LegalCopyright=
#perl2exe_info LegalTrademarks=
#perl2exe_info OriginalFilename=myprog.exe
#perl2exe_info ProductName=
#perl2exe_info ProductVersion=
#
#=====================================================



First  |  Prev  | 
Pages: 1 2
Prev: Is there neq for strings?
Next: Net::SSH stuck