[Xml-compile] adding xml:lang attribute
Mark Overmeer
mark at overmeer.net
Fri Feb 27 23:13:15 GMT 2009
* Petar Shangov (pshangov at yahoo.com) [090227 16:18]:
> I need to add the xml:lang attribute to an element, but I can't
> seem to figure out how to do it.
There are a few spots where schema's are horrible, many to be
backwards compatible. One is, for instance, the use of xsi:type.
Other spots are the attributes which start with xml, and the
"namespace" namespace.
And did you known that schema defines a clean "language" type (which
maps onto an xml:lang)?
The warnings you get are to be expected. And probably, there should
be a clean way to hide a dirty "hook" trick. This could be something
like: (untested)
use XML::Compile::Util qw/XMLNS/;
$schema->new(... , prefixes => [ xml => XMLNS ] );
{ my $lang;
# avoid complaint about unused value for lang
sub before($$$)
{ my ($doc, $values, $path) = @_;
my %copy = %$values;
$lang = delete $copy{lang}; # or xml_lang?
\%copy;
}
sub after($$$)
{ my ($doc, $node, $path) = @_;
$node->setAttribute('xml:lang' => $lang);
$node;
}
$schema->addHook
( type => \@types_with_xmllang
, before => \&before
, after => \&after
);
}
See... it would be nice to have a predefined hook for this.
The other route would be to accept and xml:lang attribute everywhere, but
that would be extremely expensive.
This trick is described in XML::Compile::Translate::Writer, as a
general trick to work around bugs in schema's.
--
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