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


In reply to XML::Simple Data->xml element conversion problem by GH_perler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.