Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Recomendations for a XML writer module

by sundialsvc4 (Abbot)
on Jul 13, 2017 at 13:16 UTC ( #1195020=note: print w/replies, xml ) Need Help??

in reply to Recomendations for a XML writer module

I tend to fall back on either XML::LibXML or XML::Twig, depending on exactly what I am doing, and how enormous the XML file is.   Twig is good for processing a great big file incrementally – it is a parser that can call your code at strategic points, but which does not transform the XML file structure into an in-memory structure.   XML::LibXML’s advantage is that under the hood it leverages libxml2, which is an industry-standard binary that I think is the actual source of most of the XML files that you are likely to receive.   So, if compatibility with a distant planet is an important consideration (and if you want to pre-flight your files to be sure that they will be acceptable), this is a good way to go.   This binary library implements everything associated with XML processing, in an industry-standard way.

“Handwritten” XML is also seen a lot, especially when you know that it will not change or when one in-house app is talking to another, but there was a recent thread here where someone seems to have gotten bitten by “character sets” with such a program.   (Switch from Latin1 to UTF-8.)   XML read/writers will categorically take care of all that, if used correctly.

The third most-common contender, XML::Simple, is a little too simple for my taste.   I have experienced various problems with both reading and writing if the use-case gets anywhere close to being an edge-case.   (However, it is simple, and sometimes functional XML requirements are simple, too.)

  • Comment on Re: Recomendations for a XML writer module

Replies are listed 'Best First'.
Re^2: Recomendations for a XML writer module
by haukex (Abbot) on Jul 13, 2017 at 17:48 UTC
    XML::Simple ... it is simple, and sometimes functional XML requirements are simple, too

    Sorry, but I have to strongly recommend against XML::Simple for any XML output, and don't even think about trying to round-trip XML files with XML::Simple. Reading simple XML files with the module might be acceptable if and only if the user is aware of all of the issues, but most people who come here to ask for help with XML::Simple are clearly not aware of those issues, and that's a problem with that module. Despite the fact that I really like the idea behind the module, unfortunately XML::Simple's output format is just too brittle and most XML schemas are too strict for the module to be a reliable XML writer.

    XML::Rules is a pretty good replacement for XML::Simple for reading XML files into data structures, but I've noticed it's also still not always able to perfectly round-trip XML files. Personally, for writing XML files, I usually find myself using XML::LibXML (despite the relative verbosity of its API, since a few short helper subs take care of that), and for reading or filtering XML files, especially large ones, XML::Twig.

Re^2: Recomendations for a XML writer module
by karlgoethebier (Monsignor) on Jul 13, 2017 at 19:07 UTC


    "The use of this module in new code is discouraged. Other modules are available which provide more straightforward and consistent interfaces. In particular, XML::LibXML is highly recommended and XML::Twig is an excellent alternative."

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1195020]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-07-22 07:19 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (452 votes). Check out past polls.