[Xml-compile] Writer not playing nice

Anthony Wood bessington at gmail.com
Wed Aug 29 08:38:26 GMT 2012


Hi All

I'm playing around trying to make XML::Compile 'eat it's own dog-food' by
consuming a Perl structure produced by the template() method.

I have :

#!/usr/local/bin/perl

use warnings;
use strict;
use Data::Dumper;
use XML::Compile::Schema;

# xsd copied locally from http://www.loc.gov/standards/mets/mets.xsd
my $xsd =3D '/cygdrive/h/tony.wood/xml/xsd/mets.xsd';
my $schema =3D XML::Compile::Schema->new($xsd);
$schema->addSchemaDirs('/cygdrive/h/tony.wood/xml/xsd');

# xlink.xsd is from http://www.loc.gov/standards/xlink/xlink.xsd
$schema->importDefinitions('xlink.xsd');

# create the type for XML::Compile::Schema->compile()
use XML::Compile::Util qw/pack_type/;
my $type =3D pack_type 'http://www.loc.gov/METS/', 'mets';

# generate a string containing an example data structure.
my $hash_text =3D $schema->template('PERL', '{http://www.loc.gov/METS/}mets=
');

# i then do some slight munging on the string to make it legal Perl
$hash_text =3D~ s/[.][.][.]//g;     # remove ellipses

my $href =3D eval $hash_text;
warn $@ if $@;

# create and use a writer
my $doc    =3D XML::LibXML::Document->new('1.0', 'UTF-8');
my $writer =3D $schema->compile(WRITER =3D> $type);

# attempt to write resultant XML
my $xml    =3D $writer->($doc, $href);

The data structure produced is 1400 lines long, so i wont copy it here in
its entirety,

The first error i get (from the last line of code)  is :

error: too few 'any' elements, got 0 for minimum 1 at {
http://www.loc.gov/METS/}mets/dmdSec/mdWrap/xmlData#any

the relevant part of the data structure is :

        xmlData =3D>
        { # sequence of ANY

          # any element in any namespace
          # occurs 1 <=3D # <=3D unbounded times
          ANY =3D> [ "Anything", ], },

I've tried converting 'ANY' to lower case, no difference.I don't get it, it
looks like there is precisely 1 'any' element.

If i remove this part of the data structure, the error moves on to :

error: attribute `LOCTYPE' is required at {
http://www.loc.gov/METS/}mets/dmdSec/mdRef/@LOCTYPE

here, the relevant part of the data structure is :

  dmdSec =3D>
  [ { # all of mdRef, mdWrap

      # is an unnamed complex
      # is optional
      mdRef =3D>
      { # is a xs:ID
        ID =3D> "id_0",

        # is a xs:string
        # attribute LOCTYPE is required
        # Enum: ARK DOI HANDLE OTHER PURL URL URN
        LOCTYPE =3D> "ARK",

As you can see LOCTYPE is present. What is the significance of the '@' in
@LOCTYPE ? Could this be a namespace problem ? I've hacked xlink.xsd to get
around namespace issues, it looks like :

<!-- METS XLink Schema, v. 2, Nov. 15, 2004 -->
<schema xmlns=3D"http://www.w3.org/2001/XMLSchema" xmlns:xlink=3D"
http://www.w3.org/1999/xlink" targetNamespace=3D"http://www.w3.org/1999/xli=
nk"
elementFormDefault=3D"qualified">
etc.....

I've added both the xmlns and xmlns:xlink field / value pairs to work
around issues generating errors during importDefinitions() - my bad ?

Any ideas ?
Thanks in advance
Tony Wood
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20120829/91=
1e60c5/attachment.htm


More information about the Xml-compile mailing list