[Xml-compile] First steps with XML:Compile
Rolf Schaufelberger
rs at plusw.de
Wed Jun 25 23:14:52 BST 2008
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_INFO
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 ?
Regards
Rolf Schaufelberger
More information about the Xml-compile
mailing list