NAME
XML::Struct::Simple - Transform MicroXML data structures into simple (unordered) form
SYNOPSIS
my $converter = XML::Struct::Simple->new( root => 'record' );
my $struct = [ root => { xmlns => 'http://example.org/' },
[ '!', [ x => {}, [42] ] ] ];
my $simple = $converter->transform( $xml );
# { record => { xmlns => 'http://example.org/', x => 42 } }
DESCRIPTION
This module implements a transformation from structured XML (MicroXML) to simple key-value format 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.
CONFIGURATION
- root
-
Keep the root element instead of removing. This corresponds to option
KeepRootin XML::Simple. In addition one can set the name of the root element if a non-numeric value is passed. - content
-
With option
simpleenable, text content at elements with attributes is parsed into a hash value with this key. Set to "contentby default. Corresponds to optionContentKeyin XML::Simple. - attributes
-
Assume input without attributes if set to a true value. The special value
removewill first remove attributes, so the following three are equivalent:my @children = (['a'],['b']); simpleXML( [ $name => \@children ], attributes => 0 ); simpleXML( removeXMLAttr( [ $name => \%attributes, \@children ] ), attributes => 0 ); simpleXML( [ $name => \%attributes, \@children ], attributes => 'remove' );
Option KeyAttr, ForceArray, and other fetures of XML::Simple not supported (yet).
METHODS
transform( $element )
Transform XML given as array reference (MicroXML) to XML as hash reference (SimpleXML) as configured.
FUNCTIONS
removeXMLAttr( $element )
Recursively remove XML attributes from XML given as array reference (MicroXML).