++ed by:
2 non-PAUSE users
Author image Jakob Voß
and 2 contributors


XML::Struct::Simple - Transform MicroXML data structures into simple (unordered) form


    my $micro = [
        root => { xmlns => 'http://example.org/' },
        [ '!', [ x => {}, [42] ] ]
    my $converter = XML::Struct::Simple->new( root => 'record' );
    my $simple = $converter->transform( $micro );
    # { record => { xmlns => 'http://example.org/', x => 42 } }


This module implements a transformation from structured XML (MicroXML) to simple key-value format (SimpleXML) as known from XML::Simple: Attributes and child elements are treated as hash keys with their content as value. Text elements without attributes are converted to text and empty elements without attributes are converted to empty hashes.

XML::Struct can export the function simpleXML for easy use. Function readXML and XML::Struct::Reader apply transformation to SimpleXML with option simple.


transform( $element )

Transform XML given as array reference (MicroXML) to XML as hash reference (SimpleXML) as configured.

transform_content( $element [, $depth ] )

Transform child nodes and attributes of an XML element given as array reference at a given depth (0 by default). Returns a hash reference, a scalar, or the element unmodified.



Keep the root element instead of removing. This corresponds to option KeepRoot in XML::Simple. In addition a non-numeric value can be used to override the name of the root element. Disabled by default.


Include XML attributes. Enabled by default. The special value remove is equivalent to false. Corresponds to option NoAttr in XML::Simple.


Name of a field to put text content in. Set to "content by default. Corresponds to option ContentKey in XML::Simple.


Only transform up to a given depth. Set to a negative value by default for unlimited depth. Elements below depth are not cloned but copied by reference. Depth 0 will return the element unmodified.

Option KeyAttr, ForceArray, and other fetures of XML::Simple not supported. Options NsExpand and NsStrip supported in XML::LibXML::Simple are not supported yet.