id="abcd" in XML

J

John

Hi

Odd problem with XML.

If you have the following one line XML and then use::Dumper to view it you
get the correct hash references.

<session sid="abcde12345" city="boston"/>
$VAR1 = [ { 'sid' => 'abcde12345', 'city' => 'boston' } ];

However, if you use "id" instead of "sid" as in the following
<session id="abcde12345" city="boston"/>

The reference id="abcde12345" does not appear and you get

$VAR1 = { 'abcde12345' => { 'city' => 'boston' } };

What is so special about 'id' that causes this behaviour?

Regards
John
 
T

Tad McClellan

John said:
If you have the following one line XML and then use::Dumper to view it you
get the correct hash references.


Maybe you do, but I don't.

<session sid="abcde12345" city="boston"/>
$VAR1 = [ { 'sid' => 'abcde12345', 'city' => 'boston' } ];


----------------
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

my $xml = '<session sid="abcde12345" city="boston"/>';
print Dumper \$xml;
----------------


You must surely be processing the XML in some way.

Which way would that be?

Please post a short and complete program that we can run that
illustrates your problem.
 
J

Juha Laiho

John said:
Odd problem with XML.

If you have the following one line XML and then use::Dumper to view it you
get the correct hash references.

<session sid="abcde12345" city="boston"/>
$VAR1 = [ { 'sid' => 'abcde12345', 'city' => 'boston' } ];

However, if you use "id" instead of "sid" as in the following
<session id="abcde12345" city="boston"/>

The reference id="abcde12345" does not appear and you get

$VAR1 = { 'abcde12345' => { 'city' => 'boston' } };

What is so special about 'id' that causes this behaviour?

That's impossible to understand without knowing anything of your code
which produces this behaviour.
 
J

John Bokma

John said:
Hi

Odd problem with XML.

If you have the following one line XML and then use::Dumper to view it
you get the correct hash references.

<session sid="abcde12345" city="boston"/>
$VAR1 = [ { 'sid' => 'abcde12345', 'city' => 'boston' } ];

However, if you use "id" instead of "sid" as in the following
<session id="abcde12345" city="boston"/>

The reference id="abcde12345" does not appear and you get

$VAR1 = { 'abcde12345' => { 'city' => 'boston' } };

What is so special about 'id' that causes this behaviour?

id's are often used for unique ids, and this way you have an easy look-up
based on ids (they have become hash keys). I am sure it's an option you
can turn off. Which module are you using? XML::Simple?

http://search.cpan.org/~grantm/XML-Simple-2.16/lib/XML/Simple.pm#OPTIONS

Guess: (look up array folding):

KeyAttr => [ list ] # in+out - important

:
:

The default value for 'KeyAttr' is ['name', 'key', 'id']. If you do not
want folding on input or unfolding on output you must setting this option
to an empty list to disable the feature.
 
J

John

Hi

Many thanks for those replies. Sorry, if I only put part of the code in my
query.
John was right. I am using XML::Simple and I had forgotten to set KeyAttr.

Regards
John
 
J

John Bokma

John said:
Hi

Many thanks for those replies. Sorry, if I only put part of the code
in my query.
John was right. I am using XML::Simple and I had forgotten to set
KeyAttr.

:) The thing is, with insufficient information less people are able to
help you. I often read the documentation of a module I haven't used before
just to see if I can help anyway. You were lucky I have a good memory,
since I used XML::Simple ages ago once or so :-D.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top