Why does this module require two attributes to be set in order to make output have the same structure as input?
XML::Simple is optimised for reading XML. Some of the things it does to make your life easier when it reads XML make things more difficult if you try and write XML back out again. But if you're anything like me then you read XML far more often than you write it. The two operations have very little in common so one tool is unlikely to be well suited to both.
I'd be the first to admit that the XML::Simple API is a mess. The primary reason is that it wasn't planned as a general purpose XML manipulation tool. It was designed for reading XML config files. The code to write XML back out again was added on later. If I had set out to write a tool that could round-trip XML perfectly every time then I would have ended up designing some sort of DOM-type thing and at some point I would have seen the error of my ways and given up.
I'd say this is rapidly becoming a Frequently Asked Question
Perhaps, but I'd wager that most people who are asking have not read the XML::Simple documentation sitting on their own hard drive, or the XML::Simple FAQ sitting next to it. The original poster for example had a choice of 22 options and apparently didn't even try one! The ForceArray option which would be one solution to the original question is even singled out in the documentation as one of the two most important options you need to read about before you use the module. You can lead a horse to water ...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|