Dear Brethren of the Order,

My module takes a chunk of three level simple XML from XML::Simple with $xml=XMLin($xmlstream); and converts the resulting array/hash into a variety of formats.

The code below reads in and stores the element names and their contents. This means that no prior knowledge of the element names is necessary, so that the module can read any three level simple XML file.
sub init() { my ($self)=@_; my $source=$self->matrix; foreach my $node(keys (%$source)) { my $elem=$source->{$node}; my $count=0; foreach my $attr (@$elem) { ##### line 60 $self->print.="\n\n$node $count\n\n"; if ($count<1) {$self->nodename=$node;} foreach my $subnode(keys(%$attr)) { $self->print.=$subnode."\t".$attr->{$subnode}."\n"; } $count++; } } }
It worked beautifully until I started to test the boundaries. With huge chunks of XML it works fine, with smallish ones also, for example:
<root> <car> <make>audi</make> </car> <car> <make>sbarro</make> </car> </root>
However, if there is only one element, such as:
<root> <car> <make>audi</make> </car> </root>
Then I get this error: Not an ARRAY reference at transForm.pm line 60.

I am starting to feel a little bit out of my depth here... Can anybody help me?

Thank you, O holy ones

Dalgetty

In reply to XML::Simple, but not for me by dalgetty

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.