Validation with XSD using XML::LibXML::Schema, and XML::Validator::Schema

Discussion in 'Perl Misc' started by huntingseasonson, Nov 28, 2006.

  1. Both XML::LibXML::Schema and XML::Validator::Schema error when I
    attempt to validate, yet the XML and XSD files appear to be perfectly
    fine.

    XML::LibXML::Schema errors with:
    Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'ref':
    References from this schema to components in the namespace '' are not
    allowed, since not indicated by an import statement.

    Code:

    my $parser = XML::LibXML->new();
    my $doc = $parser->parse_file("TV.xml");
    my $v = XML::LibXML::Schema->new(location=>"TV.xsd");
    eval { $v->validate($doc); };
    die $@ if $@;

    +++++++++++++++++++++++++++

    XML::Validator::Schema errors with:
    Found <simpleType> illegally combined with <complexType>.
    at
    /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/XML/LibXML/SAX.pm
    line 64
    at ./transform.pl line 234

    <simpleType> is allowed to be nested withen a <complexType> correct? As
    the examples I have seen on the w3c's schema tutorial nest them.
    LibXML's error, well I thought a "ref" to a element withen the same
    namespace (none) is perfectly ok.

    Code:

    my $v = XML::Validator::Schema->new(file=>"TV.xsd");
    my $p = XML::SAX::parserFactory->parser(handler=>$v);
    eval { $p->parse_uri("TV.xml") };
    die $@ if $@;

    Both fXML and XSD files are quite long, but I will post if necessary.
    Im not sure these errors are do to a problem with Perl's
    implementation, in javax.xml.validation.Validator they validated ok;
    maybe Java's implementation is more relaxed....?

    Thanks in advance
     
    huntingseasonson, Nov 28, 2006
    #1
    1. Advertisements

  2. I can't really see how we can comment if you don't make them available
    to us.

    If you can't manage to reduce them to a minimal (but complete) test
    case then rather than actually posting them it may be better to put
    them somewhere public and post a link.
     
    Brian McCauley, Nov 28, 2006
    #2
    1. Advertisements

  3. huntingseasonson, Nov 28, 2006
    #3
  4. I suspect XML::LibXML::Schema may be getting confused by the explicit
    empty namepace declaration.

    <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="package">

    XML::Validator::Schema only supports a subset of XSD. I can't
    immediately see what in your TV.xsd goes beyond what it supports. It
    looks like it's mistaking getting confused here...

    <xs:complexType>
    <xs:simpleContent>
    <xs:extension base="xs:string">
    <xs:attribute name="type" use="required">
    <xs:simpleType>

    Looking in XML::Validator::Schema::parser it seems not to consider the
    possiblity that <xs:attribute> has content so it sees <xs:simpleType>
    as being within the <xs:complexType>. (The <xs:simpleContent> and
    <xs:extension> are handled as specialization of the <xs:complexType>).

    I guess XML::Validator::Schema::parser only supports named types for
    attributes.
     
    Brian McCauley, Nov 28, 2006
    #4
  5. huntingseasonson

    skye.shaw Guest

    Yup that was it.

    Thank you very much!
     
    skye.shaw, Nov 28, 2006
    #5
  6. Not that this as anything to do with Perl, but it would be interesting
    to know if this is a bug in LibXML or if the XSD was at fault. I'm
    inclined to believe the former but I wasn't able to convince myself one
    way or another from a quick look at www.w3.org.
     
    Brian McCauley, Nov 29, 2006
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.