[Xml-compile] Attribute named "type" causing problems?
Heiko Jansen
heiko_jansen at web.de
Sat May 1 22:19:45 GMT 2010
Hi there,
I'm currently right at the beginning of writing a module to deal with MODS
records (cf. http://loc.gov/mods) and I'm just trying to evaluate if
XML::Compile::Schema could be of any help there.
Being also a complete newbie to XML::Compile::* I decided to start with a
rather simple round trip experiment: reading in a MODS record and dumping it
again afterwards.
I am, however, just getting an error message from XML::Compile::Schema and I
don't really understand if that's my fault or if I just stumbled on an error
in X::C::S.
Here's my test case:
-- snip --
use Log::Report mode => "DEBUG";
use XML::Compile::Schema;
use XML::Compile::Util qw/pack_type/;
use XML::LibXML; # need 1.70
my $mods = XML::LibXML->load_xml( location =>
"http://www.loc.gov/standards/mods/v3/mods-3-3.xsd" );
my $xmls = XML::LibXML->load_xml( location =>
"http://www.w3.org/2001/XMLSchema.xsd" );
my $xml = XML::LibXML->load_xml( location =>
"http://www.loc.gov/mods/xml.xsd" );
my $xlnk = XML::LibXML->load_xml( location =>
"http://www.loc.gov/standards/xlink/xlink.xsd" );
my $schema = XML::Compile::Schema->new();
$schema->importDefinitions($mods);
$schema->importDefinitions($xmls);
$schema->importDefinitions($xml);
$schema->importDefinitions($xlnk);
my $elem = pack_type "http://www.loc.gov/mods/v3", "mods";
my $read = $schema->compile( READER => $elem );
my $data = $read->(<<"END_MODS_RECORD");
<?xml version="1.0" encoding="UTF-8"?>
<mods
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.loc.gov/mods/v3"
version="3.3"
xsi:schemaLocation="http://www.loc.gov/mods/v3
http://www.loc.gov/standards/mods/v3/mods-3-3.xsd">
<titleInfo>
<title>Sound and fury :</title>
<subTitle>the making of the punditocracy</subTitle>
</titleInfo>
<name type="personal">
<namePart>Alterman, Eric</namePart>
<role><roleTerm type="text">creator</roleTerm></role>
</name>
<typeOfResource>text</typeOfResource>
<genre authority="marcgt">bibliography</genre>
<originInfo>
<place><placeTerm type="text">Ithaca, N.Y</placeTerm></place>
<publisher>Cornell University Press</publisher>
<dateIssued>c1999</dateIssued>
</originInfo>
<physicalDescription>
<form authority="marcform">print</form>
<extent>vii, 322 p. ; 23 cm.</extent>
</physicalDescription>
</mods>
END_MODS_RECORD
# use Data::Dumper; warn Dumper($data);
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $write = $schema->compile( WRITER => $elem );
warn $write->( $doc, $data )->toString(1);
-- snip --
All I get beyond the debug trace is this error:
-- snip --
error: invalid enumerate `simple' at
{http://www.loc.gov/mods/v3}mods/name#facet
at /usr/lib/perl5/site_perl/5.10.0/XML/Compile/Schema/BuiltInFacets.pm line
167
-- / snip --
If I dump $data this is the output fragment for the "name" element:
-- snip --
{
'name' => {
'cho_namePart' => [
{
'namePart' => {
'_' => 'Alterman, Eric'
}
},
{
'role' => {
'seq_roleTerm' => [
{
'roleTerm' => {
'type' => 'text',
'_' => 'creator'
}
}
]
}
}
],
'type' => 'simple'
}
},
-- / snip --
I'm using XML::Compile 1.14, Perl 5.10.0 on openSUSE 11.2 x86_64.
Hopefully someone can explain what's going on...
Thx!
Heiko
More information about the Xml-compile
mailing list