Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Recomendations for a XML writer module

by sundialsvc4 (Abbot)
on Jul 13, 2017 at 13:16 UTC ( [id://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.)

Replies are listed 'Best First'.
Re^2: Recomendations for a XML writer module
by haukex (Archbishop) 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 (Abbot) on Jul 13, 2017 at 19:07 UTC

    FYI:

    "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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1195020]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-19 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found