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

Report information
The Basics

grantm [...]
dwest1975 [...]

(no value)
Broken in:
(no value)
Fixed in:
(no value)

MIME-Version: 1.0
X-Spam-Status: No, score=0.362 tagged_above=-99.9 required=10 tests=[BAYES_20=-0.001, DKIM_SIGNED=0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, MSGID_FROM_MTA_HEADER=0.001, T_DKIM_INVALID=0.01] autolearn=no
X-Mailer: 5.0
X-Spam-Flag: NO
X-Virus-Checked: Checked
Content-Type: multipart/alternative; boundary="=-bXsXmIaVvOmaLplJMyJB"
Message-ID: <>
X-Virus-Scanned: Debian amavisd-new at
X-Spam-Score: 0.362
Received: from localhost (localhost []) by (Postfix) with ESMTP id E139561E01F for <>; Thu, 22 May 2014 10:08:55 -0400 (EDT)
Received: from ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id Np+PrRWokBTh for <>; Thu, 22 May 2014 10:08:54 -0400 (EDT)
Received: from ( []) by (Postfix) with SMTP id 5736161E01D for <>; Thu, 22 May 2014 10:08:54 -0400 (EDT)
Received: (qmail 15027 invoked by alias); 22 May 2014 14:08:53 -0000
Received: from (HELO ( by (qpsmtpd/0.28) with ESMTP; Thu, 22 May 2014 07:08:47 -0700
Received: from [] ( by with smtp ID 1WnTfl-000F1q-Jx for; Thu, 22 May 2014 17:08:41 +0300
Received: from by; Thu, 22 May 2014 17:08:41 +0300
Authentication-Results: (amavisd-new); dkim=softfail (fail, body has been altered)
Subject: Incorrect XML is produced with empty nested arrays
Return-Path: <>
X-RT-Mail-Extension: xml-simple
Dkim-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;; s=ffe; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:To:Subject:From:Date; bh=zWg1t+FMU23zW/DsCW/wNAPB8r62Q94Ed1OBid3HAdc=; b=LtJ1s96+jutG2UsGUkwKE71AXQauP052APCwPjzXH1V5jiwZq7ncMaTB7AZ3Ed6AW0DVbX9pQaVS6i8CeHPzD9/oMY4eWKNEEqFYW7B44j0rD5RUCWUAZx+DaLlkI3rJ1BlM5NVroY7n7wVUJi87iwvsCkEcBKf0N5M0enFAQoU=;
Date: Thu, 22 May 2014 17:08:41 +0300
Content-Transfer-Encoding: binary
From: Dean West <>
X-RT-Interface: Email
Content-Length: 0
Content-Length: 1889
content-type: text/plain; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 3379
content-type: text/html; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8


Recently I noticed, that XML::Simple generates incorrect XML with default options if data has empty nested array(s). Generated node with empty nested array(s) looks like it contains data whereas it actually does not. Here is a simple demonstration:

Show quoted text
> perl -w <<'EOF'
> use XML::Simple;
> my $data = {
>     user => [
>         {
>             login => 'bob',
>             password => 'qwerty',
>             options => [],
>         },
>         {
>             login => 'alice',
>             password => 'ytrewq',
>             options => [],
>         },
>     ],
> };
> print XMLout($data);

It produces the following XML:

  <user login="bob" password="qwerty">
  <user login="alice" password="ytrewq">

As you can see content for each 'user' node here is new line and 2 spaces. It stands to reason, that there should be no content at all in this case.

I have prepared a small patch which fixes this issue:

--- a/lib/XML/
+++ b/lib/XML/
@@ -1564,8 +1564,8 @@ sub value_to_xml {

         if(ref($value)  or  $self->{opt}->{noattr}) {
-          push @nested,
-            $self->value_to_xml($value, $key, "$indent  ");
+          $value = $self->value_to_xml($value, $key, "$indent  ");
+          push @nested, $value if($value ne '');
         else {
           $value = $self->escape_value($value) unless($self->{opt}->{noescape});

With this patch the following XML is produced:

  <user login="bob" password="qwerty" />
  <user login="alice" password="ytrewq" />

Please consider including it in future version.


MIME-Version: 1.0
In-Reply-To: <>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <>
Content-Type: text/plain; charset="utf-8"
Message-ID: <>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 680
Apologies for the delay in reviewing this patch. You referred to XML::Simple producing this output: <user login="bob" password="qwerty"> </user> And said "it stands to reason, that there should be no content at all in this case.". i.e.: <user login="bob" password="qwerty" /> Whilst I can see an argument either way, XMLin() will discard the extra whitespace so it makes no material difference. If you need that level of control over the generated XML then XML::Simple is a very poor tool for the job. Although it is a minor change, the upside is also small so I'm choosing not to accept the patch due to the potential risk of breaking downstream code. Regards Grant

This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with to