I'm working on a web-app which I would like to collect information and then dump to an XML file.

I started with an XML file that I created (by hand). I can easily read it in via XML::Simple which loads it into a nice data structure (dumped with Data::Dumper).

I then started to think OO, and break sub elements of the XML structure down into objects.

I've written a few Perl Objects (been a while) breaking things down into separate classes(packages).

But when I dump the base object through data dumper, it has all the "bless" structures in there. I had hoped to come up with a structure similar to the one that was created by reading in the XML file.

So I guess the question is, is there a way to create objects within Perl and have the data structure come out similar.

Simple Sample of the XML:

<map> <location name="test"> <items> <item> <desc>some item1</desc> </item> <item> <desc>some item2</desc> </item> </items> <features> <desc>...</desc> </features> </location> </map>
Which loads nicely into by XML::Simple:
$VAR1 = { 'location' => { 'items' => { 'item' => [ { 'desc' => 'some i +tem1' }, { 'desc' => 'some i +tem2' } ] }, 'features' => { 'desc' => '...' }, 'name' => 'test' } };
When I try to create it with objects, and sub-objects I get the types and bless(...) stuff mixed in. The inital objects were Features and Item.

I figure I could create my own XML::Parser but that is more work than I had hoped, also Simple already does a great job.

Please help


In reply to Objects and Data structure similar to XML by Syrkres

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.