jeanluca has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I try to read the following xml file
<ABC> <A1> <01>100</01> </A1> </ABC>
This is the code that should do it:
#! /usr/bin/perl use XML::Simple ; use strict ; use warnings ; my $obj = XML::Simple->new() ; my $xml = $obj->XMLin("fl.xml") ;
The result I get running this scrupt is
not well-formed (invalid token) at line 3, column 5, byte 18 at /usr/l +ib/perl5/vendor_perl/5.8.2/i686-linux/XML/Parser.pm line 187
I noticed that the error message disapeared when I changed <01> to <xx>
So why do I get this error ?

Thanks
Luca

Replies are listed 'Best First'.
Re: XML::Simple cannot parse Simple XML file
by Corion (Patriarch) on Jun 13, 2006 at 08:49 UTC

    Because your tag name is not well-formed. XML seems to require that every tag starts with an alphanumeric alphabetic character, underscore or colon.

    Maybe you can make XML::Simple more lenient, but I recommend changing your datastructure instead.

    Update: Changed wrong "alphanumeric" for "alphabetic"

      XML seems to require that every tag starts with an alphanumeric character, underscore or colon

      But it looks to me that the op's tags do start with "an alphanumeric character, underscore or colon".

      I find this error occurs only if XML::SAX is not installed. If XML::SAX is installed, then it gets used instead of XML::Parser, and the error does not occur ... so, I guess, that's one way to work around the problem.

      Cheers,
      Rob

        Actually, XML tags need to start with a letter. Not an alphanumeric character. See the spec for details.

        If XML::Parser handles tags that start with a number then XML::Parser is broken.

        --
        <http://dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

Re: XML::Simple cannot parse Simple XML file
by rblasch (Monk) on Jun 13, 2006 at 09:52 UTC
A reply falls below the community's threshold of quality. You may see it by logging in.