[Xml-compile] repeat tags with XML::Schema
Mark Overmeer
mark at overmeer.net
Tue Jun 25 10:36:17 GMT 2013
* Hugues Max (huguesmax at gmail.com) [130625 09:21]:
> 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);
You can better start with the ::Cache:
my $schema = XML::Compile::Cache->new('./2.xsd'
, prefixes => [ '' => 'urn:iso:std:iso:20022:tech:xsd:2' ]
);
my $write = $schema->compile(WRITER => 'Document');
> $s->{CstmrDrctDbtInitn}->{PmtInf}->{DrctDbtTxInf}->{PmtId}->{InstrId} = $a;
> $s->{CstmrDrctDbtInitn}->{PmtInf}->{DrctDbtTxInf}->{PmtId}->{EndToEndId}
> = $b;
I would advice:
my $pmtid = $s->{CstmrDrctDbtInitn}{PmtInf}{DrctDbtTxInf}{PmtId} ||= {};
$pmtid->{InstrId} = $a;
$pmtid->{EndToEndId} = $b;
my $pmtid = $s->{CstmrDrctDbtInitn}{PmtInf}{DrctDbtTxInf}{PmtId}
= +{ InstrId => $a, EndToEndId => $b };
> 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'}}
> ]}};
my @pmtids;
push @pmtids, +{ PmtId => {InstrId => 1, EndToEndId =>'ref1'}};
push @pmtids, +{ PmtId => {InstrId => 2, EndToEndId =>'ref2'}};
$s->{CstmrDrctDbtInitn}{PmtInf}{DrctDbtTxInf} = \@pmtid;
--
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