XML::S...:Simple(3pm)

πŸ“¦
version 0.27 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

✨ 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 option KeepRoot in XML::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 option NoAttr in XML::Simple.
  • content β€” The name of the field where text content gets put. Set to "content" by default. Corresponds to the option ContentKey in XML::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 depth 0 will return the element unmodified. πŸ™ˆ
ngl there are some things this module simply does not do. The options KeyAttr, ForceArray, and other features of XML::Simple are not supported. And the options NsExpand and NsStrip that are supported in XML::LibXML::Simple are 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