XML::S...:Simple(3pm)
β¨ NAME β¨
XML::Struct::Simple β the glow-up machine that turns MicroXML data structures into the simple (unordered) form π
π SYNOPSIS π
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 } }
π¦ DESCRIPTION π¦
okay bestie, so this module does a transformation. It takes structured XML (MicroXML) and converts it into the simple key-value format (SimpleXML) that you already know and love from XML::Simple. The way it works is lowkey elegant: attributes and child elements both become hash keys, and their content becomes the value. That's it, that's the whole vibe. β¨
A couple of specifics so you're not confused later:
- Text elements with no attributes get converted to text πΈ
- Empty elements with no attributes get converted to empty hashes π«
Also, XML::Struct can export the function simpleXML for easy use β iconic. And the function readXML plus XML::Struct::Reader can apply this whole transformation to SimpleXML if you pass the option simple. iykyk π
π METHODS π
transform( $element )
Transform XML given as an array reference (that's your MicroXML) into XML as a hash reference (that's your SimpleXML), using whatever configuration you set up. Slay. π
transform_content( $element [, $depth ] )
This one transforms the child nodes and attributes of an XML element given as an array reference, at a given depth (0 by default, babes). What does it hand back? A hash reference, a scalar, or the element completely unmodified. No cap. π¦
π CONFIGURATION π
rootβ Keeps the root element instead of removing it (main character energy fr). This corresponds to the optionKeepRootinXML::Simple. Bonus: you can also pass a non-numeric value to override the name of the root element. Disabled by default.attributesβ Include XML attributes. Enabled by default. The special value"remove"is equivalent to false. Corresponds to the optionNoAttrinXML::Simple.contentβ The name of the field where text content gets put. Set to"content"by default. Corresponds to the optionContentKeyinXML::Simple.depthβ Only transform up to a given depth. Set to a negative value by default, which means unlimited depth. Heads up though: elements below the depth are not cloned β they're copied by reference. And depth0will return the element unmodified. π
ngl there are some things this module simply does not do. The optionsKeyAttr,ForceArray, and other features ofXML::Simpleare not supported. And the optionsNsExpandandNsStripthat are supported inXML::LibXML::Simpleare not supported yet. Just so you know before you go looking for them bestie π
and that's the whole page, gorgeous π«Ά this was XML::S...:Simple(3pm) from perl v5.28.1, dated 2019-02-21, straight out of the User Contributed Perl Documentation. go forth and transform β¨πβ
π¦ where this page comes from
- debian bookworm: libxml-struct-perl 0.27-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libxml-struct-perl 0.27-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libxml-struct-perl 0.27-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libxml-struct-perl 0.27-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms