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

Has anyone had any experience validating XSD (schema) files with XML::Validator::Schema? I can't seem to rid myself of an error when the mod parses the .xsd file.

Error is:
"Found <simpleType> illegally combined with <complexType>."

The .xsd file parses and validates fine under XMLSpy (Windows). I, unfortunately, can't alter the .xsd file as it was provided by a 3 party and serves as a template for their system requirements.

Below is the (simplified) code:

use XML::SAX::ExpatXS;
use XML::Validator::Schema;

my $xml_path = '/path/to/xml/document.xml';
my $xsd_path = '/path/to/schema/document.xsd';

my $xml_va = XML::Validator::Schema->new(file => $xsd_path);
my $parser = XML::SAX::ExpatXS->new(Handler => $xml_va);
eval { $parser->parse_uri($xml_path) };
die "File failed validation: $@" if $@;


Also, I can't seem to find alternate schema validation tools on CPAN. The schema tools I run into are used to create the .xsd which isn't an option currently.

Any help is appreciated.

Replies are listed 'Best First'.
Re: .XSD (schema) Validation issue
by samtregar (Abbot) on Feb 16, 2005 at 21:17 UTC
    Have you read the documentation? In particular pay attention to the schema support section. It's likely that you're trying to do something that isn't supported yet by XML::Validator::Schema.

    If you've read the docs and you're reasonably sure that you're painting within the lines then please post the XSD file. If it's huge try to find a smallish snippet that reproduces the problem.



      Thanks for posting!
      Yes, I made sure to read the documentation very closely but it didn't seem to shed any light on this particular error - other than "SimpleTypes must come after their base types in the schema body."

      I searched through the module source and found where the error was being generated:

      _err("Found <simpleType> illegally combined with complexType>.") if $mother->{is_complex};

      By "illegally combined" does the error mean simpleType cannot be a child (or parent) of complexType?

      I hope the following .xsd snippet will be helpful as it seem s exemplary of the file as a whole.


      <xsd:element name="Phone" type="PhoneType" minOccurs="0"/> <xsd:element name="Fax" minOccurs="0"> <xsd:complexType> <xsd:sequence> <xsd:element name="F_AreaCode" nillable="1"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:length value="3"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="F_Prefix" nillable="1"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:length value="3"/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name="F_Suffix" nillable="1"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:length value="4"/> </xsd:restriction> </xsd:simpleType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element>


      Any help is appreciated.


        Yes, I made sure to read the documentation very closely but it didn't seem to shed any light on this particular error

        I wouldn't expect that it would. XML::Validator::Schema has terrible failure behavior. If it's trying to process a schema which is doing things it can't support it won't generally give you much help figuring out why.

        I hope the following .xsd snippet will be helpful

        Not particularly... I don't see any place in that snippet where a simpleType is the (direct) child of a complexType. Are you sure you've found the problem?

        Here's what I need if I'm going to find and fix this bug:

        • A small, complete XSD file containing the problematic construct. No more than 20 lines would be ideal.
        • A small XML file which you posit should validate against the sample XSD. Again, smaller is better.

        In some cases I can create these myself but you haven't given me enough information to do the job.