Pluto icon indicating copy to clipboard operation
Pluto copied to clipboard

xml.decode: flat mode

Open Sainan opened this issue 1 year ago • 0 comments

The way xml.decode currently behaves is more akin to a "full" mode. It would be good to also add a "flat" mode to it, but it needs to also consider the same tag being present multiple times:

<entries>
    <entry primary="">
        <name>primary</name>
    </entry>
    <entry/>
</entries>
{
    ["entries"] = {
        ["entry"] = {
            [1] = {
                ["__attributes"] = {
                    ["primary"] = string(0) "",
                },
                ["name"] = string(7) "primary",
            },
            [2] = {},
        },
    },
}

Of course, it would mean that only 1 entry would be flattened like this:

<entries>
    <entry primary="">
        <name>primary</name>
    </entry>
</entries>
{
    ["entries"] = {
        ["entry"] = {
            ["__attributes"] = {
                ["primary"] = string(0) "",
            },
            ["name"] = string(7) "primary",
        },
    },
}

Maybe adding an option to pick how "aggressive" the flattening should be could also help here.

Sainan avatar Mar 03 '24 09:03 Sainan