[Xml-compile] repeat tags with XML::Schema

Hugues Max huguesmax at gmail.com
Tue Jun 25 09:20:48 GMT 2013


Hello  All
I use XML::Compile::Schema

my $schema = XML::Compile::Schema->new('./2.xsd');

my $write = $schema->compile(WRITER => 
'{urn:iso:std:iso:20022:tech:xsd:2}Document', use_default_namespace => 
1, include_namespaces => 1);

and XML::LibXML to generate  xml

my $doc = XML::LibXML::Document->new('1.0', 'UTF-8');

$s->{CstmrDrctDbtInitn}->{PmtInf}->{DrctDbtTxInf}->{PmtId}->{InstrId} = $a;
$s->{CstmrDrctDbtInitn}->{PmtInf}->{DrctDbtTxInf}->{PmtId}->{EndToEndId} 
= $b;
..
..

my $xml    = $write->($doc, $s);
$doc->setDocumentElement($xml);
print $doc->toString(1);


All works correctly if all my data respect xsd.

But now, one part of my xml file must be appear multiple time ,
<DrctDbtTxInf>.... </DrctDbtTxInf>
<DrctDbtTxInf>.... </DrctDbtTxInf>



$s->{CstmrDrctDbtInitn}->{PmtInf}->{DrctDbtTxInf}->{PmtId}->{InstrId} = $a;
$s->{CstmrDrctDbtInitn}->{PmtInf}->{DrctDbtTxInf}->{PmtId}->{EndToEndId} 
= $b;


$s->{CstmrDrctDbtInitn}->{PmtInf}->{DrctDbtTxInf}->{PmtId}->{InstrId} = $c;
$s->{CstmrDrctDbtInitn}->{PmtInf}->{DrctDbtTxInf}->{PmtId}->{EndToEndId} 
= $d;



If I do that, in my xml file there are only $c and $d

If I create manually $s using [..] it'working

my $s = CstmrDrctDbtInitn => {  PmtInf => { DrctDbtTxInf =>
[
{PmtId     => { InstrId => '1', EndToEndId =>'ref1'}},
{PmtId     => { InstrId => '2', EndToEndId =>'ref2'}}
]}};

but how I can use this notation "->" , and  create a loop to push my 
data in $s ?

$s->{CstmrDrctDbtInitn}->{PmtInf}->{DrctDbtTxInf}->{PmtId}->{InstrId}




More information about the Xml-compile mailing list