XMLout() output causes "not well-formed (invalid token)" in XMLin()

Discussion in 'Perl Misc' started by pt, Sep 22, 2004.

  1. pt

    pt Guest

    use XML::Simple;
    # %List is a hash of hashes.
    # Key is an IP number (stored as string, not v-string)
    XMLout(\%List, OutputFile => $Fname) or die "XMLout : $Fname" ;

    produces:
    <opt>
    <211.57.214.74 ProbeCount="1" LastProbe="1092087541" />
    <204.251.212.93 ProbeCount="1" LastProbe="1095511410" />
    <210.40.224.10 ProbeCount="1" LastProbe="1090939270" />
    <159.226.50.10 ProbeCount="2" LastProbe="1093911681" />
    <213.114.91.47 ProbeCount="1" LastProbe="1093988795" />
    ....etc...
    </opt>


    Reading it back in with:
    my $HRef = XMLin($Fname) or die "XMLin : $Fname" ;

    returns this error:
    Uncaught exception from user code:

    not well-formed (invalid token) at line 2, column 3, byte 9 at
    C:/Program Files/ActiveState/Perl/site/lib/XML/Parser.pm line 187
    XML::parser::parse('XML::parser=HASH(0x1b64be8)','*XML::Simple::XML_FILE')
    called at C:/Program Files/ActiveState/Perl/site/lib/XML/Simple.pm
    line 334

    [snip]

    I'm guessing it's because my hash key looks like a number, but I can't
    find an option to have it quoted during XMLout().
     
    pt, Sep 22, 2004
    #1
    1. Advertising

  2. pt

    Joe Smith Guest

    pt wrote:

    > use XML::Simple;
    > # %List is a hash of hashes.
    > # Key is an IP number (stored as string, not v-string)
    > XMLout(\%List, OutputFile => $Fname) or die "XMLout : $Fname" ;
    >
    > produces:
    > <opt>
    > <211.57.214.74 ProbeCount="1" LastProbe="1092087541" />
    > </opt>


    I would have expected to use something more like this:

    <opt>
    <xx addr="211.57.214.74" ProbeCount="1" LastProbe="1092087541" />
    <xx addr="204.251.212.93" ProbeCount="1" LastProbe="1095511410" />
    </opt>
     
    Joe Smith, Sep 22, 2004
    #2
    1. Advertising

  3. pt

    Eric Amick Guest

    On 21 Sep 2004 17:51:49 -0700, (pt) wrote:

    >use XML::Simple;
    ># %List is a hash of hashes.
    ># Key is an IP number (stored as string, not v-string)
    >XMLout(\%List, OutputFile => $Fname) or die "XMLout : $Fname" ;
    >
    >produces:
    ><opt>
    > <211.57.214.74 ProbeCount="1" LastProbe="1092087541" />
    > <204.251.212.93 ProbeCount="1" LastProbe="1095511410" />
    > <210.40.224.10 ProbeCount="1" LastProbe="1090939270" />
    > <159.226.50.10 ProbeCount="2" LastProbe="1093911681" />
    > <213.114.91.47 ProbeCount="1" LastProbe="1093988795" />
    >...etc...
    ></opt>
    >
    >
    >Reading it back in with:
    >my $HRef = XMLin($Fname) or die "XMLin : $Fname" ;
    >
    >returns this error:
    >Uncaught exception from user code:
    >
    >not well-formed (invalid token) at line 2, column 3, byte 9 at
    > C:/Program Files/ActiveState/Perl/site/lib/XML/Parser.pm line 187
    > XML::parser::parse('XML::parser=HASH(0x1b64be8)','*XML::Simple::XML_FILE')
    > called at C:/Program Files/ActiveState/Perl/site/lib/XML/Simple.pm
    >line 334
    >
    >[snip]
    >
    >I'm guessing it's because my hash key looks like a number, but I can't
    >find an option to have it quoted during XMLout().


    Element names in XML must start with a letter, underscore, or colon, so
    you'll have to change the data somehow. Maybe you could make the IP
    address an attribute instead?

    --
    Eric Amick
    Columbia, MD
     
    Eric Amick, Sep 23, 2004
    #3
  4. pt

    pt Guest

    Joe Smith <> wrote in message
    >

    [snip]

    > I would have expected to use something more like this:
    >
    > <opt>
    > <xx addr="211.57.214.74" ProbeCount="1" LastProbe="1092087541" />
    > <xx addr="204.251.212.93" ProbeCount="1" LastProbe="1095511410" />
    > </opt>


    I guess I wasn't clear .... I'm using XMLout() to generate this file
    which I figured XMLin() should be able to read, but I get the error.
     
    pt, Sep 23, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Schmidt

    CDATA in XMLout

    Stefan Schmidt, Dec 28, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,300
    Andy R
    Dec 31, 2003
  2. Replies:
    4
    Views:
    671
    Diez B. Roggisch
    Mar 27, 2007
  3. Pablo Rey
    Replies:
    8
    Views:
    3,472
    Lawrence D'Oliveiro
    Aug 31, 2007
  4. Rossz
    Replies:
    0
    Views:
    96
    Rossz
    Jun 23, 2005
  5. Replies:
    2
    Views:
    124
Loading...

Share This Page