Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Getting XML::Simple Module Error

by perladdict (Chaplain)
on Feb 23, 2012 at 11:17 UTC ( #955702=perlquestion: print w/ replies, xml ) Need Help??
perladdict has asked for the wisdom of the Perl Monks concerning the following question:

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/ 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

Comment on Getting XML::Simple Module Error
Select or Download Code
Replies are listed 'Best First'.
Re: Getting XML::Simple Module Error
by rovf (Priest) on Feb 23, 2012 at 12:18 UTC
    I don't know whether this is the reason for the error, but the attribute in <?xml ...> should be version, not versions.

    Ronald Fischer <>
Re: Getting XML::Simple Module Error
by runrig (Abbot) on Feb 23, 2012 at 15:48 UTC
    It might be the version of the expat library (I have 2.0.1), but I get:
    XML declaration not well-formed at line 1, column 6, byte 6 at ... /XM +L/ line 187
    which points towards your "versions=", and is fixed by changing it to "version=".
Re: Getting XML::Simple Module Error
by ww (Bishop) on Feb 23, 2012 at 13:30 UTC
    While I find rovf's analysis entirely plausible, /me (admittedly, knowing next to nothing about this topic) wonders about:
    <spam-document... at line 2, closed at 22
    "<spam ...." ? (emphasis supplied)

    Apologies in advance if this is irrelevant, but your error message does mention line 2.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://955702]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (12)
As of 2016-02-09 21:11 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (326 votes), past polls