[Xml-compile] Attribute named "type" causing problems?
Mark Overmeer
mark at overmeer.net
Mon May 3 10:33:37 GMT 2010
* Heiko Jansen (heiko_jansen at web.de) [100502 21:27]:
> Am Sonntag, 2. Mai 2010 22:58:25 schrieb Mark Overmeer:
> > No, both schemas have attributeFormDefault="unqualified"
> > mods-3-3.xsd explicitly, xlink.xsd implicitly (its the default)
>
> But the "xlink.xsd" that is imported here says
>
> <attributeGroup name="simpleLink">
> <attribute name="type" type="string" fixed="simple" form="qualified" />
>
> Maybe it's a modified version of the original "XLink" schema?!
Support for namespace qualified attributes was added "recently", but
did not work well with key_rewrite. The latter is needed to avoid
collission between mods:type and xlink:type.
Attached, you see the script which I got to work. It shows how best
use key_rewrite. ::Cache is a very useful extension in ::Schema.
>From operational point of view, I would advice you against runtime
loading of the schemas.
My version of your script is attached, for everyone to learn. An
intermediate release of XML::Compile will be sent directly to you,
off-list.
--
Success
MarkOv
------------------------------------------------------------------------
Mark Overmeer MSc MARKOV Solutions
Mark at Overmeer.net solutions at overmeer.net
http://Mark.Overmeer.net http://solutions.overmeer.net
-------------- next part --------------
#!/usr/bin/env perl
use warnings;
use strict;
#use Log::Report mode => "DEBUG";
use XML::Compile::Cache;
use XML::Compile::Util qw/pack_type/;
use Data::Dumper;
$Data::Dumper::Indent = 1;
my @prefixes =
( mods => 'http://www.loc.gov/mods/v3'
, xlink => 'http://www.w3.org/1999/xlink'
);
my $schema = XML::Compile::Cache->new
( ['mods-3-3.xsd','xml.xsd','xlink.xsd']
, opts_rw => [ key_rewrite => 'PREFIXED' ]
, prefixes => \@prefixes
);
my $elem = "mods:mods";
my $read = $schema->compile(READER => $elem);
print Dumper $read;
#print $schema->template(PERL => $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
# warn Dumper $data;
my $doc = XML::LibXML::Document->new( "1.0", "UTF-8" );
my $write = $schema->compile( WRITER => $elem );
my $xml = $write->( $doc, $data );
$doc->setDocumentElement($xml);
print $doc->toString(1);
More information about the Xml-compile
mailing list