Firstly, I am confused by your Perl code. I have no experience using XML::Simple (but I have used XML::Parser), but it seems odd that you specify the output file as $conf in your constructor statement, then you use $conf as an input file in your call to XMLin.

Secondly, when I try to read your XML code in using XMLin, I get the following error trace:

Uncaught exception from user code: not well-formed (invalid token) at line 2, column 10, byte 17 at /usr/ +lib64/perl5/vendor_perl/5.8.0/x86_64-linux-thread-multi/XML/Parser.pm + line 185 XML::Parser::parse('XML::Parser=HASH(0x803ab0)','*XML::Simple: +:XML_FILE') called at /usr/lib/perl5/vendor_perl/5.8.0/XML/Simple.pm +line 334 XML::Simple::build_tree_xml_parser('XML::Simple=HASH(0x8227a0) +','foo.xml','foo.xml') called at /usr/lib/perl5/vendor_perl/5.8.0/XML +/Simple.pm line 277 XML::Simple::build_tree('XML::Simple=HASH(0x8227a0)','foo.xml' +,'foo.xml') called at /usr/lib/perl5/vendor_perl/5.8.0/XML/Simple.pm +line 220 XML::Simple::XMLin('XML::Simple=HASH(0x8227a0)','foo.xml') cal +led at ./655609.pl line 15

Here is my hacked code:

#!/usr/bin/env perl use warnings; use strict; use diagnostics; use XML::Simple; my $conf = 'out.xml'; # I made this up my $xmlfile = new XML::Simple ( Outputfile => $conf, ForceArray => 1, RootName=>'exec' ); #my $xml = $xmlfile->XMLin($conf); my $xml = $xmlfile->XMLin('foo.xml');
However, if I add double-quotes around the attribute values (001, 002, 003), I can read the XML file in without errors.

Please be more specific about what problem you are having. Are you getting any warning or error messages? If so, please post them here.


In reply to Re: xml::simple foreach by toolic
in thread xml::simple foreach by hakana

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.