Skip Menu |

This queue is for tickets about the XML-Validator-Schema CPAN distribution.

Report information
The Basics
Id: 7741
Status: resolved
Priority: 0/
Queue: XML-Validator-Schema

People
Owner: Nobody in particular
Requestors: mat_trash [...] hotmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Patch for more debugging information
Hi, this patch adds the debug parameter to the new method so that we can follow the parsing and validation of an xml document. This provide the user with the approximate position in the XML document at which the validation has failed. For example with the test files test.xml & test.xsd with debug set to 1, we have the following output: o foo o int o integer o name o string o bool o date If we modify the test.xml to add a new <null>foo</null> tag, we have: o foo o int o integer o name o string o bool o date o null File failed validation: Found unexpected <null> inside <foo>. This is not a valid child element. at /usr/local/lib/perl/5.8.3/XML/LibXML/SAX.pm line 63 The attributes are also diplayed, for the following xml file: <foo> <int myatt1="one" myatt2="two">1</int> <integer>1</integer> <name>foo</name> <string>...</string> <bool>true</bool> <date>1977-08-02T20:02:00</date> </foo> we have: o foo o int - myatt2 = two - myatt1 = one o integer o name o string o bool o date I hope you'll find this patch useful, I've also updated the pod. Thanks for your module. Mathieu
--- Schema.1.06.pm 2004-09-22 17:47:43.000000000 +0200 +++ Schema.1.07.pm 2004-09-22 17:49:57.000000000 +0200 @@ -4,7 +4,7 @@ use strict; use warnings; -our $VERSION = '1.06'; +our $VERSION = '1.07'; =head1 NAME @@ -68,7 +68,10 @@ eval { $parser->parse_uri('foo.xml') }; die "File failed validation: $@" if $@; - +Setting the optional C<debug> parameter to 1 causes +XML::Validator::Schema to output elements and associated attributes +while parsing and validating the XML document. This provides + useful information on the position where the validation failed. =back @@ -472,12 +475,16 @@ use XML::Validator::Schema::Util qw(_err); our %CACHE; +use constant DEBUG => 0; + # create a new validation filter sub new { my $pkg = shift; my $opt = (@_ == 1) ? { %{shift()} } : {@_}; my $self = bless $opt, $pkg; + $self->{debug} = ( defined $self->{debug} ) ? $self->{debug} : DEBUG; + # check options croak("Missing required 'file' option.") unless $self->{file}; @@ -538,11 +545,21 @@ my $element = $node_stack->[-1]; # check that this alright + print STDERR " " x scalar(@{$node_stack}), " o ", $name, "\n" + if ( $self->{debug} ); my $daughter = $element->check_daughter($name); # check attributes $daughter->check_attributes($data->{Attributes}); + if ( $self->{debug} ) { + foreach my $att ( keys %{ $data->{Attributes} } ) { + print STDERR " " x (scalar(@{$node_stack}) + 2), " - ", + $data->{Attributes}->{$att}->{Name}, " = ", + $data->{Attributes}->{$att}->{Value}, "\n" + } + } + # enter daughter node push(@$node_stack, $daughter);
This is very neat! I'd still like to get filenames and line-numbers into the error output, but this should help for now. I'll put it in for the next release which should come soon.