[Xml-compile] adding xml:lang attribute

Mark Overmeer mark at overmeer.net
Fri Feb 27 23:26:48 GMT 2009


* Petar Shangov (pshangov at yahoo.com) [090227 16:18]:
> $schema->addKeyRewrite( pack_type('http://www.w3.org/XML/1998/namespace', 'lang') => 'xml_lang' );
> $element->{'xml_lang'} = 'en';
> # error: key rewrite `{http://www.w3.org/XML/1998/namespace}lang' not understood

keyRewrite() accepts various things, of which one is a translation table.
That is a HASH.  You try to pass a pair.

Rewriting keys only influences how the names used in the Perl HASH
map on node names in XML.  They do not influence the processing of
the nodes, what is needed here.

> $schema->addKeyRewrite( pack_type('xml', 'lang') => 'xml_lang' );
> my $writer = $schema->compile( 'WRITER', $ns, prefixes => { 'http://www.w3.org/XML/1998/namespace' => 'xml' } );
> $element->{'xml_lang'} = 'en';
> # error: key rewrite `{xml}lang' not understood

You can use XMLNS as defined by XML::Compile::Util:
 
   use XML::Compile::Util qw/XMLNS/;
   my $writer = $schema->compile(WRITER => $type, prefixes => [xml => XMLNS] );

but it does not solve your problem: you need a hook.  See earlier mail.
-- 
Regards,

               MarkOv

------------------------------------------------------------------------
       Mark Overmeer MSc                                MARKOV Solutions
       Mark at Overmeer.net                          solutions at overmeer.net
http://Mark.Overmeer.net                   http://solutions.overmeer.net




More information about the Xml-compile mailing list