I usually use XML::Simple, because it is just that - simple. Together with Data::Dumper to peek at the structure, you can accomplish the tasks really easily. However, as people has pointed out, XML::Simple builds a reference structure in-memory which might be big - whether this is a problem or not depends on your situation, of course.

Next time I will do any more serious XML, I will most definetely look into XML::Twig - it seems to be very easy and simple to do things with too, with the added benefit of making it possible to "stream" your XML through it without the memory footprint. I've seen lots of great programmers here use that module, and without having actually used it myself - yet - I am very impressed.

In the recent thread XML Search and Replace there are quite a few examples on different modules being used to manipulate XML.

I don't think that is a typo. You can use XML::Simple to emit HTML, as long as you conform to XML rules, as XHTML does. It is just a warning that if you are trying to emit HTML, you can't/shouldn't do it HTML 4.0 (and down) style, but rather XHTML, which means, among other things, that all attributes must have a value. Just saying checked isn't enough in a checkbox, for instance, you must say checked="checked" or some such to be conformant. Which means, that an attribute, say as a hash key, is not a good idea to define as checked => '' (or undef), but should be checked => 'checked'. Hope that makes some sense. :)

Update: See jeffa's response below, and don't take this as a recommendation to use XMLout() to generate HTML, only a clarification to what it meant. :)


You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.

In reply to Re: Which XML module to use? by Dog and Pony
in thread Which XML module to use? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.