in reply to How Xerces validation access http schemas ?

[ This question was also asked on StackOverflow. ]

From the source:

if ($strict) { TRACE("Using strict validation"); $DOMparser->setValidationScheme("$XML::Xerces::AbstractDOMPars +er::Val_Auto"); $DOMparser->setIncludeIgnorableWhitespace(0); $DOMparser->setDoSchema(1); $DOMparser->setDoNamespaces(1); $DOMparser->setValidationSchemaFullChecking(1); $DOMparser->setLoadExternalDTD(1); $DOMparser->setExitOnFirstFatalError(1); $DOMparser->setValidationConstraintFatal(1); } else { TRACE("Using no validation"); $DOMparser->setValidationScheme("$XML::Xerces::AbstractDOMPars +er::Val_Never"); $DOMparser->setDoSchema(0); $DOMparser->setDoNamespaces(0); $DOMparser->setValidationSchemaFullChecking(0); $DOMparser->setLoadExternalDTD(0); }

Notice the setLoadExternalDTD setting is only true in strict validation mode.

Using the following should do the trick:

my $validator = XML::Validate::Xerces->new( strict_validation => 1 );

Seeking work! You can reach me at ikegami@adaelis.com

Replies are listed 'Best First'.
Re^2: How Xerces validation access http schemas ?
by jjmoka (Beadle) on Apr 09, 2021 at 10:36 UTC
    Thanks for having a look. That strict value is the default:
    the var $VALID_OPTIONS at Validate/Xerces.pm#L16
    and it's indeed 1, both dubugging interactively or also dumping with Devel::Trace as hippo kindly adviced, and which is easier to share here:
    Note that at lines 70-72 it is taken the branch strict.
    Note also that the local execution (the one referencing the schema locally) is absolutely the same of this report till line 101:
    It's then the $DOMparser->parse($input); instruction which fails in the case of schema on the web.
    When the schema is local, the validation is still strict, but $DOMparser->parse($input); lands me smoothly to the next instruction if ($self->last_error) { So I'm still believing it's a network configuration problem.
     23 >> a3.web.short.pm:12:     my %options;
     24 >> a3.web.short.pm:13:     my $validator = new XML::Validate::Xerces(%options);
     25 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:21:    my $class = shift;
     26 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:22:    my %options = @_;
     27 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:23:    my $self = {};
     28 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:24:    bless ($self, $class);
     29 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:26:    $self->clear_errors();
     30 >> /usr/local/share/perl5/XML/Validate/Base.pm:33:      my $self = shift;
     31 >> /usr/local/share/perl5/XML/Validate/Base.pm:34:      $self->{error} = undef;
     32 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:27:    $self->set_options(\%options,$VALID_OPTIONS);
     33 >> /usr/local/share/perl5/XML/Validate/Base.pm:38:      my $self = shift;
     34 >> /usr/local/share/perl5/XML/Validate/Base.pm:39:      my ($supplied_options,$valid_options) = @_;
     35 >> /usr/local/share/perl5/XML/Validate/Base.pm:40:      foreach my $option (keys %{$supplied_options}) {
     36 >> /usr/local/share/perl5/XML/Validate/Base.pm:40:      foreach my $option (keys %{$supplied_options}) {
     37 >> /usr/local/share/perl5/XML/Validate/Base.pm:45:      $self->{options} = {%{$valid_options},%{$supplied_options}};
     38 >> /usr/local/share/perl5/XML/Validate/Base.pm:45:      $self->{options} = {%{$valid_options},%{$supplied_options}};
     39 >> /usr/local/share/perl5/XML/Validate/Base.pm:45:      $self->{options} = {%{$valid_options},%{$supplied_options}};
     40 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:29:    DUMP("Instantiating XML::Validate::Xerces", $self);
     41 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:111: sub DUMP  { XML::Validate::Base::DUMP(@_)  }
     42 >> /usr/local/share/perl5/XML/Validate/Base.pm:57: sub DUMP {}
     43 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:31:    return $self;
     44 >> a3.web.short.pm:14:     my $valid = $validator->validate($xml) ? '' : 'in';
     45 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:39:    my $self = shift;
     46 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:40:    my ($xml) = @_;
     47 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:41:    TRACE("Validating with Xerces. XML => " . defined($xml) ? $xml : 'undef' );
     48 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:110: sub TRACE { XML::Validate::Base::TRACE(@_) }
     49 >> /usr/local/share/perl5/XML/Validate/Base.pm:56: sub TRACE {}
     50 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:43:    $self->clear_errors();
     51 >> /usr/local/share/perl5/XML/Validate/Base.pm:33:      my $self = shift;
     52 >> /usr/local/share/perl5/XML/Validate/Base.pm:34:      $self->{error} = undef;
     53 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:44:    $self->{DOMParser} = undef;
     54 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:46:    die "validate called with no data to validate\n" unless defined $xml and length $xml > 0;
     55 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:48:    my $DOMparser = new XML::Xerces::XercesDOMParser;
     56 >> /usr/local/lib64/perl5/XML/Xerces.pm:6036:     my $pkg = shift;
     57 >> /usr/local/lib64/perl5/XML/Xerces.pm:6037:     my $self = XML::Xercesc::new_XercesDOMParser(@_);
     58 >> /usr/local/lib64/perl5/XML/Xerces.pm:6038:     bless $self, $pkg if defined($self);
     59 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:50:    $self->_set_validation($DOMparser, $self->options->{strict_validation});
     60 >> /usr/local/share/perl5/XML/Validate/Base.pm:17:      my $self = shift;
     61 >> /usr/local/share/perl5/XML/Validate/Base.pm:18:      return $self->{options};
     62 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:77:    my $self = shift;
     63 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:78:    my $DOMparser = shift;
     64 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:79:    my $strict = shift;
     65 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:81:    TRACE("_set_validation called");
     66 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:110: sub TRACE { XML::Validate::Base::TRACE(@_) }
     67 >> /usr/local/share/perl5/XML/Validate/Base.pm:56: sub TRACE {}
     68 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:83:    if ($strict) {
     69 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:84:            TRACE("Using strict validation");
     70 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:110: sub TRACE { XML::Validate::Base::TRACE(@_) }
     71 >> /usr/local/share/perl5/XML/Validate/Base.pm:56: sub TRACE {}
     72 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:85:            $DOMparser->setValidationScheme("$XML::Xerces::AbstractDOMParser::Val_Auto");
     73 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:86:            $DOMparser->setIncludeIgnorableWhitespace(0);
     74 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:87:            $DOMparser->setDoSchema(1);
     75 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:88:            $DOMparser->setDoNamespaces(1);
     76 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:89:            $DOMparser->setValidationSchemaFullChecking(1);
     77 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:90:            $DOMparser->setLoadExternalDTD(1);
     78 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:91:            $DOMparser->setExitOnFirstFatalError(1);
     79 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:92:            $DOMparser->setValidationConstraintFatal(1);
     80 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:53:    my $ErrorHandler = XML::Validate::Xerces::ErrorHandler->new($self);
     81 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:122:   my $class = shift;
     82 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:123:   my ($validator) = @_;
     83 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:124:   my $self = {
     84 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:127:   return bless($self,$class)
     85 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:54:    $DOMparser->setErrorHandler($ErrorHandler);
     86 >> /usr/local/lib64/perl5/XML/Xerces.pm:6063:   my ($self,$handler) = @_;
     87 >> /usr/local/lib64/perl5/XML/Xerces.pm:6064:   my $callback = XML::Xerces::PerlErrorCallbackHandler->new($handler);
     88 >> /usr/local/lib64/perl5/XML/Xerces.pm:6391:     my $pkg = shift;
     89 >> /usr/local/lib64/perl5/XML/Xerces.pm:6392:     my $self = XML::Xercesc::new_PerlErrorCallbackHandler(@_);
     90 >> /usr/local/lib64/perl5/XML/Xerces.pm:6393:     bless $self, $pkg if defined($self);
     91 >> /usr/local/lib64/perl5/XML/Xerces.pm:6065:   $XML::Xerces::REMEMBER{tied(% {$self})}->{__ERROR_HANDLER} = $callback;
     92 >> /usr/local/lib64/perl5/XML/Xerces.pm:6065:   $XML::Xerces::REMEMBER{tied(% {$self})}->{__ERROR_HANDLER} = $callback;
     93 >> /usr/local/lib64/perl5/XML/Xerces.pm:6067:   return XML::Xercesc::XercesDOMParser_setErrorHandler($self,$callback);
     94 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:57:    my $input = XML::Xerces::MemBufInputSource->new($xml,$self->options->{base_uri});
     95 >> /usr/local/share/perl5/XML/Validate/Base.pm:17:      my $self = shift;
     96 >> /usr/local/share/perl5/XML/Validate/Base.pm:18:      return $self->{options};
     97 >> /usr/local/lib64/perl5/XML/Xerces.pm:3394:   my $pkg = shift;
     98 >> /usr/local/lib64/perl5/XML/Xerces.pm:3396:   if (scalar @_ == 1) {
     99 >> /usr/local/lib64/perl5/XML/Xerces.pm:3400:   my $self = XML::Xercesc::new_MemBufInputSource(@_);
    100 >> /usr/local/lib64/perl5/XML/Xerces.pm:3402:   bless $self, $pkg if defined($self);
    101 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:59:    $DOMparser->parse($input);
    102 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:141:   my ($self, $exception) = @_;
    103 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:142:   $self->add_error($exception,"XML error");
    104 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:146:   my $self = shift;
    105 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:147:   my ($exception,$message_prefix) = @_;
    106 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:148:   my $error = {
    107 >> /usr/local/share/perl5/XML/Validate/Xerces.pm:153:   $self->{validator}->add_error($error);
    108 >> /usr/local/share/perl5/XML/Validate/Base.pm:27:      my $self = shift;