Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: A data structure for XML generation

by ELISHEVA (Prior)
on Aug 12, 2009 at 23:24 UTC ( [id://788078]=note: print w/replies, xml ) Need Help??


in reply to A data structure for XML generation

If you require each array to have the following format you can complete eliminate the array around the child tags. The position alone is enough to determine whether or not an array element is a nested tag. Eliminating the extra square brackets around each tag set would help keep the indentation from going halfway across the page or more.

[0] tag name [1] attribute hash reference [2] data [3] ...: one array ref for each nested tag

Your sample data would then look like this:

[ family => { name => 'Kawasaki' } => undef, [father => {} => 'Yasushisa' ], [mother => {} => 'Chizuko' ], [children => {} => undef, [girl => {} => 'Shiori'], [boy => {} => 'Yasuke'], [boy => {} => 'Kairi'] ] ]

Best, beth

Replies are listed 'Best First'.
Re^2: A data structure for XML generation
by dolmen (Beadle) on Aug 12, 2009 at 23:50 UTC
    The attribute hash ref can also be optional: if ref($tag->[1]) ne 'HASH', the tag has no attributes and $tag->[1] is the first child node. So position is only relative and undefs are not needed.
    [ family => { name => 'Kawasaki' }, [father => 'Yasushisa' ], [mother => 'Chizuko' ], [children => [girl => 'Shiori' ], [boy => 'Yasuke' ], [boy => 'Kairi' ] ] ]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2025-11-14 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (70 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.