Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have an xml file of the form
<foo>
  <bar>7</bar>
  <baz>
    <blah>12</blah>
  </baz>
</foo>
I'd like to be able to create an object that represents this such that
$self->bar()
returns 7 and
$self->bar(12)
will change the value of bar and write the new xml to disk. I'm happy to provide some sort of mapping so
$self->baz
would do as expected. Is there an existing (combination of) modules to do this? I'm using moose if that would help

Replies are listed 'Best First'.
Re: XML file and objects
by jeffa (Bishop) on Jan 19, 2009 at 15:11 UTC
Re: XML file and objects
by stvn (Monsignor) on Jan 19, 2009 at 15:57 UTC
    I'm using moose if that would help

    Take a look at XML::Toolkit, it will do pretty much all that you are looking for. The POD claims it to be alpha, but we have used a pre-alpha version of it very successfully in production for many months now, it is quite solid and well thought out. It is a new module though so it is weak on tests and docs, but trust me, it is worth it.

    -stvn
Re: XML file and objects
by zwon (Abbot) on Jan 19, 2009 at 13:49 UTC

    I don't know modules with exact syntax you want, but maybe you would like XML::Smart or XML::Twig.

Re: XML file and objects
by dHarry (Abbot) on Jan 19, 2009 at 14:19 UTC

    Not sure if I understand you correctly. Do you want to serialize your objects in XML and vice versa? You might want to take a look at

    XML-Dumper or MooseX-DOM as well.