CC: | "Breitenbach Jaco" <Jaco.Breitenbach [...] comptel.com> |
Subject: | XMLin() mapping of an element changes when there is an attribute called "name". |
Date: | Thu, 12 Nov 2009 19:22:33 -0000 |
To: | <bug-XML-Simple [...] rt.cpan.org> |
From: | "Consultant Julian Robin" <ext.Robin.Julian [...] comptel.com> |
Hello,
Below are two simple examples where I call XMLin and XMLout for a simple
piece of XML.
In the first example, the elements have an attribute called "name" and
in the second, the attribute is called "not_name".
The behaviour is different in the two cases and I could not find any
documented reason for it.
What I am trying to do is produce XML output that is the same as the XML
input. However with the different treatment of the "name" attribute, I
have not been able to do this.
(I did notice that while trying to create a simple example for this
defect description, that with an encoding of less nested elements, the
output XML is correct in both cases).
The Perl Code
use strict;
use XML::SAX;
use XML::Simple;
use Data::Dumper;
my $decode = XMLin ("fred.xml", ForceArray => 1);
print Dumper ($decode);
my $encode = XMLout($decode, RootName => "stream", XMLDecl => 1);
print $encode;
exit 0;
EXAMPLE 1 (FAILS IMHO):
Input XML:
<stream>
<nodes>
<node name="X">
</node>
<node name="Y">
</node>
</nodes>
</stream>
Data::Dumper Output:
$VAR1 = {
'nodes' => [
{
'node' => {
'X' => {}, # This looks like I
have specified "Variables =>{'name'} in the code but I have not.
'Y' => {}
}
}
]
};
Output XML:
<stream>
<nodes name="node">
<X></X>
<Y></Y>
</nodes>
</stream>
EXAMPLE 2 (WORKS AS I EXPECT IT TO):
Input XML:
<stream>
<nodes>
<node not_name="X">
</node>
<node not_name="Y">
</node>
</nodes>
</stream>
Data::Dumper Output:
$VAR1 = {
'nodes' => [
{
'node' => [
{
'not_name' => 'X'
},
{
'not_name' => 'Y'
}
]
}
]
};
Output XML:
<stream>
<nodes>
<node not_name="X" />
<node not_name="Y" />
</nodes>
</stream>
Regards, Robin Julian.
------------------------------------------------------------------------
------------
Robin Julian
Mediation Consultant
Comptel Corporation
Address: Axiom Systems, 69 Suttons Business Park, Reading, RG6 1AZ
Mobile: +44 75 2667 4693
Fax: +44 118 929 4001
ext.Robin.Julian@comptel.com
Message body is not shown because it is too large.