[Xml-compile] Clarification XML::Schema::Compile validation option for writers

Mark Overmeer mark at overmeer.net
Thu Dec 6 11:58:24 GMT 2012


* Richard Head Jr. (hsomob1999 at yahoo.com) [121206 01:13]:
> > On Thu, 10/18/12, Mark Overmeer <mark at overmeer.net>
> >
> > XML requires validation.  The only reason to turn it
> > off in XML::Compile is to increase performance if you trust content 
> > of the documents, nothing more.
> 
> With validation off types are still checked, use="required" directives
> and enumerations are still enforced. Can you be more specific about what
> this option does? For example, does it only affect fundamental facets?

The validation option to compile() is documented as:

  XML message must be validated, to lower the chance on abuse.  However,
  of course, it costs performance which is only partially compensated by
  fewer checks in your code.  This flag overrules the C<check_values>,
  C<check_occurs>, and C<ignore_facets>.

So: it is documented to ignore_facets, enumerations are facets.  If that
does not work, then there is a bug (I inspected the code: I see no reason
why it shouldn't work... not tested it)

> > > As an aside, while some of the errors raised by validation => 1
> > > are useful, I think that that without a larger "validation framework"
> > > they're more of a  constraint in certain cases (particularly when used
> > > with typemaps) as:
> > > 
> > > 1. They're not done in a batch
> >
> > I have no idea where you are talking about.
> 
> Error handling is not ideal and, without a larger "framework" in place,

There is a error framework, handling error reporting and exceptions.
It can easily log to files, syslog, etc itself, or be integrated with
Log::Log4Perl and Log::Dispatch when you use that in the rest of your
program.

> messages can be cryptic and or limited.

True.  Suggestions for improvements are welcome.

> For example, a particular object
> may have 10 validation errors but the exception includes only one. It
> is possible that one will have to to bounce their objects off the WRITER
> 10 times to resolve all of the errors.

True again.  However... validation exceptions are also *needed* at
runtime, for instance because a field is a union of (date, datetime).
So, for performance we do need to stop on the encounter of the first
problem.

Besides, caused by the complexity of schema's (choice, all,
substitionGroups, unions, etc etc) it is very hard to decide whether
you can continue after an error in a sane way.  Like the parser errors
when you forget a ';' in Perl, which may result in dozens of errors
which are not errors.  And then worse.

For the moment, I think an attempt for continuation after an error
is doing more wrong than good.

> > > 3. For typemaps + objects, errors with context refer to xpath locations
> >
> > What do you expect differently?  Example?
> 
> Let's say that package has a version attribute that's mapped to an
> emumeration:
>    my $pkg = Package->new(version => 'bad!');
>    $writer->($doc, $pkg);
> 
> When the value given for version is not part of the enum this error
> is raised:
>     error: invalid enumerate `bad!' at {http://example.com}package#facet

Yes, I am aware of this limitation.  On the moment, only the location of
the schema is being used, not the location in the message.  The latter
would be a nice addition.

I have been thinking about that.
For the reader, I have the current node.  What I need is to be able to
translate an XML::LibXML::Node into an XPath expression which brings
you from the top of the document(-fragment) to this element.  I have not
yet found such call.  I do not want to pass it on all the time at runtime
for some rare error.

The writer is an other problem: it constructs the message bottom-up.
The constructor code does not know where it is (can be very nastily
nested, maybe in a dead end of the wrong choice).  In this case, I must
be able to translate a HASH location in the provided data into a path...
Also possible.  And only translated when the error is shown.

It's a welcome improvement, but quite hard to achieve.
-- 
Regards,

               MarkOv

------------------------------------------------------------------------
       Mark Overmeer MSc                                MARKOV Solutions
       Mark at Overmeer.net                          solutions at overmeer.net
http://Mark.Overmeer.net                   http://solutions.overmeer.net




More information about the Xml-compile mailing list