[Xml-compile] First steps with XML:Compile

Rolf Schaufelberger rs at plusw.de
Wed Jun 25 23:55:22 BST 2008


add some more info;

Am Donnerstag, 26. Juni 2008 00:14:52 schrieb Rolf Schaufelberger:
> Hi ,
> I'm just trying my first steps in understanding XML::Compile.
> My goal is, to write a XML file according to given xsd files
> So I want to write an openTRANS XML document, (www.opentrans.org)
>
> where I have the xsd files
>
> openTRANS_ORDER_1_0_draft.xsdcountries_draft.xsd
> openbase_1_0_draft.xsd
> currencies_draft.xsd
> lang_draft.xsd
> punit_draft.xsd
> udx_draft.xsd
> unit_draft.xsd
>
> The first one defines the document type, the second library elements and
> the others are included by the second one.
> In my test script I list all files (with absolute path in an array and pass
> it to XML::Compile::Schema->new.
> When I call printIndex I get a long list :
>
>  namespace: http://www.opentrans.org/XMLSchema/1.0_draft
>  filename: /home/rs/openTrans/openTRANS_ORDER_1_0_draft.xsd
>   definitions of elements:
>     ORDER
>     ORDER_HEADER
>     ORDER_INFO
>     ORDER_ITEM_LIST
>     ORDER_SUMMARY
> namespace:
>  filename: /home/rs/openTrans/openbase_1_0_draft.xsd
>   definitions of elements:
>     ACCOUNT
>     ACCOUNTING_INFO
>     ADDRESS
>      ...
>     CONTROL_INFO
>     COST_ACCOUNT
>     ....
>
>
> Now I define a hash like this to define an order:
>
> my $hash = { order=>
> 	     {version=> '1.0',
> 	      type => 'standard',
> 	      ORDER_HEADER => {
> 		  ORDER_INFO => {
> 		      ORDER_ID => 123,
> 		      ORDER_DATE => '2008-06-25',
> 		  }
> 	      },
>               ...
>
> and , taken as example from the docs :
>
> # create and use a writer
> my $doc    = XML::LibXML::Document->new('1.0', 'UTF-8');
> my $myns   = 'http://www.opentrans.org/XMLSchema/1.0_draft';
> my $write  = $schema->compile(WRITER => "{$myns}ORDER");
> my $xml    = $write->($doc, $hash);
>
>
> running this I get an error:./openTrans.pl
> error: cannot find
> element '{http://www.opentrans.org/XMLSchema/1.0_draft}CONTROL_INFO' at
> {http://www.opentrans.org/XMLSchema/1.0_draft}ORDER/ORDER_HEADER/CONTROL_IN
>FO
>
> So it looks like CONTROL_INFo is the first element appearing in
> openTRANS_ORDER_1_0_draft.xsdcountries_draft.xsd
> that is defined in
> openbase_1_0_draft.xsd
> and the mapping with the namespace is not working.
> How do I have to do that ?
>
When I call :
print Dumper $schema->template (PERL=> "CONTROL_INFO");

I get an nice output:

$VAR1 = '{ # sequence of STOP_AUTOMATIC_PROCESSING, GENERATOR_INFO,
  #   GENERATION_DATE, MIME_ROOT

  # is a {http://www.w3.org/2001/XMLSchema}string
  # is optional
  # with some value restrictions
  STOP_AUTOMATIC_PROCESSING => "example",
   ....

but when I call 
print Dumper $schema->template (PERL=> "{$myns}ORDER");

I get the same error as above
error: cannot find 
element '{http://www.opentrans.org/XMLSchema/1.0_draft}CONTROL_INFO' at 
{http://www.opentrans.org/XMLSchema/1.0_draft}ORDER/ORDER_HEADER/CONTROL_INFO

and print Dumper  $schema->namespaces gives 

  .....
 
  'CONTROL_INFO' => {
                                   'ref' => undef,
                                   'name' => 'CONTROL_INFO',
                                    'efd' => 'qualified',
                                   'schema' => $VAR1->{'tns'}{''}[0],
                                    'full' => 'CONTROL_INFO',
                                    'node' => bless( do{\(my $o = 
135642424)}, 'XML::LibXML::Element' ),
                                     'ns' => '',
                                      'sg' => undef,
                                      'abstract' => '',
                                      'type' => 'element',
                                      'id' => undef,
                                       'afd' => 'unqualified',
                                        'prefix' => ''
                                    },
                       ......



-- 
Rolf Schaufelberger



More information about the Xml-compile mailing list