jjmoka has asked for the wisdom of the Perl Monks concerning the following question:

This self contained example (pathname: /root/stef/test.pl) works fine on a server A-OK, while it doesn't work on another server B-NOK.
use strict; use XML::Validate::Xerces; sub main { my $rsep = $/; undef $/; my $xml = <DATA>; $/ = $rsep; warn "working on this xml:[\n$xml]"; my %options; my $validator = new XML::Validate::Xerces(%options); my $valid = $validator->validate($xml) ? '' : 'in'; warn "Document is ${valid}valid\n"; } main(); __DATA__ <?xml version="1.0"?> <note xmlns="https://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.w3schools.com http://www.w3schools.c +om/xml/note.xsd"> <!-- xsi:schemaLocation="https://www.w3schools.com file:///root/stef/note +.xsd"> --> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>

If I swap with the commented out line (i.e. I change http://www.w3schools.com/xml/note.xsd to be file:///root/stef/note.xsd) so with the schema as a local file, then it works fine even in B-NOK.

The only difference then seems when the schema is on http.

Note that, the local file was downloaded as wget http://www.w3schools.com/xml/note.xsd so that not only I know that the content of the schema file is the same (local & remote) but also that http:80 works fine to catch stuff out there.

I didn't do anything special to have Xerces working over http:80 for server A-OK. I would then expect to do nothing on server B-NOK to have Xerces going out there and grab the schema.

I didn't find clear info if/how Xerces should be instructed to use http. Neither which mechanism it has built-in, to behave like wget to download URLs. I cannot understand then if I must add some config vars. The admin of server B-NOK told me that he didn't see anything attempting to reach http://www.w3schools.com apart when doing the manual wget. This does seem Xerces doesn't bother at all to get that URL.

Really thank you in advance for any hint.


====================== SOLVED / UPDATE ================
I wasn't given details but network settings on B-NOK server and behind have been performed and currently that fixed my issue.
I'm left then embarrassed to come here and apologise to everyone for the time spent on this.
To be honest I've spent ages and I didn't know what much else to try. 
I've had the opportunity to learn from the good advices received so that's still a positive outcome for me.
For you instead again my apologies.
====================== SOLVED / UPDATE ================

Replies are listed 'Best First'.
Re: How Xerces validation access http schemas ?
by hippo (Archbishop) on Apr 08, 2021 at 12:33 UTC

    Hints are all I can offer, unfortunately.

    You could use Module::Versions::Report at the end of your script to list out all the loaded versions of the modules used and compare the results between the 2 servers.

    Similarly, you could use Devel::Trace on both servers to determine where the execution paths differ.

    It's worth noting that the most recent versions of XML::Validate and XML::Xerces are from 15 years ago and may not play so well with modern systems (O/S, Module dependencies, Perl itself, etc.).

    Good luck with your investigations.


    🦛

      Apache's Xerxes project is still active and the Perl interface is simply a front-end to it. The Perl-wrapper version on their site is 2.7.0-0. The library version is 3.2.3.
Re: How Xerces validation access http schemas ?
by ikegami (Patriarch) on Apr 09, 2021 at 02:47 UTC

    [ 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

      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;
      
Re: How Xerces validation access http schemas ?
by bliako (Abbot) on Apr 08, 2021 at 20:04 UTC

    I don't know if it's important (i know sysadmin said nothing comes out ...) but when trying to access http://www.w3schools.com/xml/note.xsd there is a redirect/moved/301 to https://www.w3schools.com/xml/note.xsd

Re: How Xerces validation access http schemas ?
by jcb (Parson) on Apr 08, 2021 at 23:38 UTC

    While I am unsure where this would be set, having not actually worked with Xerces, there may be a security policy on server B-NOK that prohibits retrieving XSD documents from the network. If one server is much newer than the other, a default may have changed.