Hi monks,
As i am trying to learn xml with perl, i implemented a simple script which reads the input xml and modifies the few attributes values to CAPS letter.Below is the xml sample
<?xml versions="1.0"?> <spam-document version="3.5" timestamp="2001-05-13 15:33:45"> <!--Autegenarated by RAJPATIL--> <customer> <first-name>Raj</first-name> <surname>Patil</surname> <address> <street>4th block tajajinagar</street> <city>Bangalore</city> </address> <age>30</age> </customer> <customer> <first-name>Vedanth</first-name> <surname>R.Patil</surname> <address> <street>4th block tajajinagar</street> <city>Bangalore</city> </address> <age>2</age> </customer> </spam-document>

#!/usr/bin/perl -w use strict; use warnings; use XML::Simple; my $cust_xml = XMLin('./customers.xml',forcearray=>1); for my $customer(@{$cust_xml->{customer}}) { foreach (qw(first-name surname)) { $customer->{$_}->[0] = uc($customer->{$_}->[0]); } } print XMLout($cust_xml); print "\n";
The Error message i got after running the script as:
XML or text declaration not at start of entity at line 2, column 0, byte 1 at C: /Perl64/lib/XML/Parser.pm line 187
In order to work this script do i need to install the module manually or is there any error in sample script? Monks, help to fix the issue, so that i will continue my tour of xml with perl

In reply to Getting XML::Simple Module Error by perladdict

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.