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

P

pt

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().
 
J

Joe Smith

pt said:
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>
 
E

Eric Amick

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?
 
P

pt

Joe Smith said:
[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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top