http://www.perlmonks.org?node_id=640567

Popcorn Dave has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I'm finally getting my feet wet with XML by trying to combine two XML files in to one. So far so good, but when I write the XML file back, attribute indentation in XML::Simple is being ignored.

open FH, ">", "webcams.xml"; print FH XMLout($combined, KeyAttr => {AttrIndent => 1, xmldecl => '<?xml version="1.0" encoding=" +UTF-8"?>',}); close FH;

As it stands, the code is printing the XML as this:

<opt class="java.beans.XMLDecoder" version="1.6.0-oem"> <object class="java.util.HashSet"> <void method="add" string="baseball" /> <void method="add" string="football" /> </object> </opt>
According to the docs, unless I misread them, the AttrIndent => 1 should indent the tags so it looks like this:

<java version="1.6.0_02" class="java.beans.XMLDecoder"> <object class="java.util.HashSet"> <void method="add"> <string>baseball</string> </void> <void method="add"> <string>football</string> </void> </object> </java>

What have I overlooked to get the indentation to work as in the second XML example?

Thanks in advance!


Revolution. Today, 3 O'Clock. Meet behind the monkey bars.

I would love to change the world, but they won't give me the source code