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

Howdy Bros. I've got a script that reads an XML file with XML::Treebuilder. I'd like to update data in one of the elements and write the file back out. What is the most straightforward way of doing this? Neither XML::Treebuilder nor XML::Parser seems to have a method for doing output. TIA... Steve

Replies are listed 'Best First'.
Re: How to update an XML element
by GrandFather (Saint) on Apr 08, 2008 at 21:22 UTC

    See HTML::Element. The tree build by XML::TreeBuilder is built of XML::Elements which are a subclass of HTML::Elements. From the XML::TreeBuilder documentation:

    This module uses XML::Parser to make XML document trees constructed of XML::Element objects (and XML::Element is a subclass of HTML::Element adapted for XML).

    The HTML::Element member you are probably looking for is as_XML().


    Perl is environmentally friendly - it saves trees
Re: How to update an XML element
by Fletch (Bishop) on Apr 08, 2008 at 22:18 UTC

    Alternately you might look at XML::Twig instead as it offers a very nice API for munging XML DOM trees in place.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.