Skip Menu |

This queue is for tickets about the XML-Simple CPAN distribution.

Report information
The Basics
Id: 29896
Status: rejected
Priority: 0/
Queue: XML-Simple

People
Owner: Nobody in particular
Requestors: joni.laaksonen [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Bug in XMLout
Date: Wed, 10 Oct 2007 17:27:05 +0300
To: bug-XML-Simple [...] rt.cpan.org
From: "Joni Laaksonen" <joni.laaksonen [...] gmail.com>
Hi. I wonder if I found a bug from the code or if I'm using it in the wrong way. Here's what's happening: ------------------------------------------------------------------------------------- First: my $hashref = $parser->XMLin($file, KeepRoot => 1); $file contains: <settings> <test_1> <test_2> <test_3> <test_4>abcd</test_4> <test_5>1234</test_5> </test_3> </test_2> </test_1> </settings> ------------------------------------------------------------------------------------- Second: print Dumper $xmlref; Result: $VAR1 = { 'settings' => { 'test_1' => { 'test_2' => { 'test_3' => { 'test_4' => 'abcd', 'test_5' => '1234' } } } } }; ------------------------------------------------------------------------------------- Third: my $xml = XMLout( $hashref, AttrIndent => 1, KeepRoot => 1, NoAttr => 1 ); print Dumper $xml; Result: $VAR1 = '<settings> <test_1> <name>test_2</name> <test_3> <test_4>abcd</test_4> <test_5>1234</test_5> </test_3> </test_1> </settings> '; ------------------------------------------------------------------------------------- Fault: Nested <test_2> has turned into <name>test_2</name>. ------------------------------------------------------------------------------------- Environment: # $Id: Simple.pm,v 1.40 2007/08/15 10:36:48 grantm Exp $ ($VERSION = '2.18';) This is perl, v5.6.1 built for MSWin32-x86-multi-thread (ActiveState) - Joni
The introduction of the 'name' element is due to the default value of the KeyAttr option. If you're trying to round-trip XML then you will at the very least want to set the ForceArray option as well. However, if you want to round-trip XML then you're probably better off with a module like XML::LibXML which retains much more information about the source document in it's DOM object. XML::Simple's simplicity comes from the fact that it discards a lot of information from the source XML document. If you want to persist with XML::Simple, please read this article: http://www.perlmonks.org/index.pl?node_id=218480 If you want to look at XML::LibXML then this article may be useful: http://www.perlmonks.org/index.pl?node_id=490846