Item Description: A simple interface to XML documents
Review Synopsis: Very convenient for config file and simple XML files
Description
XML::Simple - Trivial API for reading and writing XML (esp config files)
XML::Simple loads an XML file in memory, in a convenient
structure, that can be accessed and updated, then output
back.
A number of options allow users to specify how the
structure should be built. It can also be cached using
Data::Dumper
Why use XML::Simple?
- XML configuration files, small table, data-oriented XML
- simple XML processing
- you don't care much about XML but find it convenient as a standard file format, to replace csv or a home-brewed format
Why NOT use XML::Simple?
- your XML data is too complex for XML::Simple to
deal with:
- it includes mixed content (<elt>th<is>_</is>_ mixed content</elt>)
- your documents are too big to fit in memory
- you are dealing with XML documents - you want to use a standard-based module (XML::DOM for example)
Personal notes
I don't use XML::Simple in production but the module seems quite mature, and very convenient for "light" XML: config files, tables, generally data-oriented, shallow XML (the XML tree is not really deep), as opposed to document-oriented XML.
Update: make sure you read the documentation
about the forcearray option or you might get bitten
by repeated elements being turned into an array (which is OK)
_except_ when there is only one of them, in which case
they become just a hash value (bad!).
for example this document:
when loaded with XMLin and not forcearray option becomes<config dir="/usr/local/etc" log="/usr/local/log"> <user id="user1"> <group>root</group> <group>webadmin</group> </user> <user id="user2"> <group>staff</group> </user> </config>
Note the 2 different ways the group elements are processed.{ 'dir' => '/usr/local/etc', 'log' => '/usr/local/log', 'user' => {'user1' => {'group' => ['root', 'webadmin']}, 'user2' => {'group' => 'staff'} } };
I also found that XML::Simple can be a little dangerous in that it leads to writing XML that is a little too simple. Often when using it I end up with an XML structure that's as shallow as I can possibly make it, which might not be really clean.
|
---|
Replies are listed 'Best First'. | |
---|---|
XML::Simple design decisions
by grantm (Parson) on Nov 09, 2002 at 07:26 UTC | |
by alw (Sexton) on Dec 24, 2007 at 19:52 UTC | |
by Jenda (Abbot) on Dec 29, 2007 at 00:53 UTC | |
by alw (Sexton) on Dec 29, 2007 at 03:33 UTC | |
by ysth (Canon) on Dec 25, 2007 at 10:06 UTC | |
RE: XML::Simple
by Anonymous Monk on Oct 30, 2000 at 14:58 UTC | |
by mirod (Canon) on Oct 30, 2000 at 19:03 UTC | |
by htoug (Deacon) on Oct 02, 2001 at 13:05 UTC | |
by mirod (Canon) on Oct 02, 2001 at 13:58 UTC | |
by moodster (Hermit) on Oct 23, 2001 at 22:40 UTC | |
by Anonymous Monk on Mar 14, 2001 at 03:54 UTC | |
Re: XML::Simple
by vbrtrmn (Pilgrim) on Nov 06, 2002 at 23:25 UTC | |
by grantm (Parson) on Nov 07, 2002 at 00:06 UTC |