GH_perler has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
when transfering a simple data structure with XML::Simple xmlout I got an unwanted behaviour by XML::Simple.
The basic hash as simple as it can be:
my %xmlData; $xmlData{'Date'}='2018-10-15'; $xmlData{'Time'}='18:20:00'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'Type'} = 'D'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'ImportID'} = '123; $xmlData{'Depot'}{'Account'}{'Consignment'}{'Reference'} = 'RefNo +'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'Number'} = 'ShipN +o'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'Lifts'} = '3'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'Weight'} = '1800' +; $xmlData{'Depot'}{'Account'}{'Consignment'}{'ManifestNote'} = 'Freig +ht to load'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'CollectionDate'} = '2018- +10-15'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'DeliveryDate'} = '2018- +10-17'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'DeliveryTime'} = '15:00 +:00'; [...] Code between [...] $xmlData{'Depot'}{'Account'}{'Consignment'}{'Pallet'}='PID_987654'; $xmlData{'Depot'}{'Account'}{'Consignment'}{'BillUnit'}{'Type'}='QP'? $xmlData{'Depot'}{'Account'}{'Consignment'}{'BillUnit'}{'Amount'}='3';
Using this code I get mostly what I want, but unfortunately not at all
my $xml = new XML::Simple; my $xmlout = $xml -> XMLout(\%xmlData, NoAttr => 1, RootName => 'Manif +est', KeyAttr => 'Account', NoSort => 1, SuppressEmpty => undef ); $xmlout = '<?xml version="1.0" encoding="UTF-8"?>'."\n".$xmlout;
XML Result is like:
<?xml version="1.0" encoding="UTF-8"?> <Manifest> <Depot> <name>Account</name> <Consignment> <Address> <Town>[...]</Town> <Type>[...]</Type> <Line>[...]</Line> <Country>[...]</Country> <County>[...]</County> <CompanyName>[...]</CompanyName> <ContactName>[...]</ContactName> <PostCode>[...]</PostCode> <Telephone>[...]</Telephone> </Address> <Address> <CompanyName>[...]</CompanyName> <PostCode>[...]</PostCode> <Town>[...]</Town> <Country>[...]</Country> <Type>[...]</Type> <Line>[...]</Line> </Address> <Lifts>[...]</Lifts> <Number>[...]</Number> <CollectionDate>[...]</CollectionDate> <Pallet>[...]</Pallet> <Reference>[...]</Reference> <BillUnit> <Type>[...]</Type> <Amount>[...]</Amount> </BillUnit> <Service> <ServiceGroupCode>[...]</ServiceGroupCode> <ServiceCode>[...]</ServiceCode> <Type>[...]</Type> </Service> <Weight>[...]</Weight> <DeliveryDate>[...]</DeliveryDate> <ImportID>[...]</ImportID> <ManifestNote>[...]</ManifestNote> <Type>[...]</Type> <DeliveryTime>[...]</DeliveryTime> </Consignment> </Depot> <Date>[...]</Date> <Time>[...]</Time> </Manifest>
The problem ist, that I donīt get <Account>..</Account> as wrapper of <consignment>...</consignment> but <name>Account</name> (when using SuppressEmpty => undef) or <Account>Account</Account> (when not using SuppressEmpty => undef).
Does anyone of you know why or what to configure to get the result I need?
Thanks in advance
George
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Simple Data->xml element conversion problem
by Discipulus (Canon) on Oct 15, 2018 at 16:52 UTC | |
|
Re: XML::Simple Data->xml element conversion problem
by poj (Abbot) on Oct 15, 2018 at 18:02 UTC | |
|
Re: XML::Simple Data->xml element conversion problem
by holli (Abbot) on Oct 17, 2018 at 01:09 UTC |