[Xml-compile] Re: XML::Compile: xsi:type support in schema

Mark Overmeer mark at overmeer.net
Mon Sep 15 09:55:40 BST 2008


[I have posted this reply to the XML::Compile mailinglist as well,
 because it might be useful to other people]

* mirod (xmltwig at gmail.com) [080915 08:06]:
> Are XML Schema types supported in XML::Compile? I mean a type attribute 
> which gives the type of the content of an element.

Well, no... because they frustrate the idea of pre-compilation.  You
cannot compile beforehand types you do not know of.  However... where
the schema does not tell you, the protocol designer still knows it.
You have to add this knowledge.

> <eb:PaymentMethod xsi:type="eb:UniversalBankTransactionType">

The best way to defined this in a schema is via substitutionGroups,
but they are newer than most of these specifications. (Or maybe: they
were introduced after the schema authors learned the schema specs)

Probably, you should address this like: (untested)

  use XML::Compile::Util 'SCHEMA2001i';

  my $xml  = XML::Compile->dataToXML($msg);
  my $root = $xml->documentElement;
  my $type = $root->getAttributeNS(SCHEMA2001i, 'type');
  my ($prefix) = $type =~ s/(.*)\://;
  my $ns   = $root->namespaceURI($prefix);

  if($type eq 'UniversalBankTransactionType')
  {   my $call = $schema->compile(READER => "{$ns}$type");
      my $data = $call->($root);
  }

In case of a daemon, the compile() should be moved into the
initiation phase.

I see good opportunities to get this as feature into XML::Compile::Cache,
but it isn't there yet.  Probably as hook, to enable the type detection.
-- 
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