Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Sort xml nodes by schema

by AlexTape (Monk)
on Sep 10, 2013 at 09:20 UTC ( [id://1053207]=note: print w/replies, xml ) Need Help??


in reply to Sort xml nodes by schema


XML::Simple on CPAN

to supress XMLout generating empty hash entry use 'SuppressEmpty'

SuppressEmpty => 1 | '' | undef # in+out - handy

This option controls what XMLin() should do with empty elements (no attributes and no content). The default behaviour is to represent them as empty hashes. Setting this option to a true value (eg: 1) will cause empty elements to be skipped altogether. Setting the option to 'undef' or the empty string will cause empty elements to be represented as the undefined value or the empty string respectively. The latter two alternatives are a little easier to test for in your code than a hash with no keys.

The option also controls what XMLout() does with undefined values. Setting the option to undef causes undefined values to be output as empty elements (rather than empty attributes), it also suppresses the generation of warnings about undefined values. Setting the option to a true value (eg: 1) causes undefined values to be skipped altogether on output.

sorting: maybe you can presort your data in an array before invoking XMLout() with it?

mabye this can help:
XML Schema: order of elements
XML Schema: Allow any order

$perlig =~ s/pec/cep/g if 'errors expected';

Replies are listed 'Best First'.
Re^2: Sort xml nodes by schema
by laozi (Novice) on Sep 10, 2013 at 10:09 UTC

    Thanks!

    Suppress empty does ease the pain

    I have another issue i forgot to mention

    i need a certain key value pair to translate to an element rather than an attribute

    is there a way to do that with XML::Simple ?

      can you give an example?
      $perlig =~ s/pec/cep/g if 'errors expected';

        This is the hash structure

        'image' => { 'linux_axp_lpae' => { # Mandatory image_name => 'uImage-axp-lpae', code_ref => 'linux_3.2.40_13q3_uni', linux_image => { compiler => 'v7_le_sfp_latest', defconfig => 'armada_xp_v7smp_defconfig', modules => '1', config => { 'CONFIG_ARM_LPAE' => {value => 'y'}, 'CONFIG_SQUASHFS' => {value => 'y'} }, }, 'post_script' => ['cesa/openswan/ipsec_build.sh'] }, }
        and this is the xml i get
        <image image_name="uImage-axp-lpae" code_ref="linux_3.2.40_13q3_uni"> <linux_image compiler="v7_le_sfp_latest" defconfig="armada_xp_v7smp_defconfig" modules="1"> <config image="CONFIG_ARM_LPAE" value="y" /> <config image="CONFIG_SQUASHFS" value="y" /> </linux_image> <post_script>cesa/openswan/ipsec_build.sh</post_script> </image>
        as you can see "code_ref" becomes a attribute but i need it to be an element

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1053207]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-23 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found