Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: A data structure for XML generation

by ctilmes (Priest)
on Aug 11, 2009 at 13:16 UTC ( #787610=note: print w/ replies, xml ) Need Help??


in reply to A data structure for XML generation

If you've defined two explicit cases for $inner (scalar or array ref), you can always differentiate it from a hash ref, so why not just make the \%attr optional and just omit the empty hashes {}?

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

I also think your example had a couple minor errors (extra array ref and no punctuation between 'children' and its children.)


Comment on Re: A data structure for XML generation
Download Code
Re^2: A data structure for XML generation
by metaperl (Curate) on Aug 11, 2009 at 14:16 UTC
    If you've defined two explicit cases for $inner (scalar or array ref), you can always differentiate it from a hash ref, so why not just make the \%attr optional and just omit the empty hashes {}?
    Yes, I certainly thought of that. And you will often simply provide content without attributes, so I think that is a nice shorthand.
      You may use something like the lol structure of the method new_from_lol in HTML::Element, I think it is very compact and easy to handle.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2014-07-22 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (117 votes), past polls