XML::Mini(3pm)

πŸ“¦
version 1.38 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– XML::Mini πŸ’–

okay bestie, come SIT. we're talking about XML::Mini today β€” it's a Perl implementation of the XML::Mini XML create/parse interface, living in the User Contributed Perl Documentation corner of your friendly neighborhood 3pm man pages. grab a boba, this one's a classic πŸ§‹βœ¨


🌸 NAME 🌸

XML::Mini β€” Perl implementation of the XML::Mini XML create/parse interface. periodt.


✨ SYNOPSIS ✨

use XML::Mini::Document;

use Data::Dumper;

###### PARSING XML #######

# create a new object
my $xmlDoc = XML::Mini::Document->new();

# init the doc from an XML string
$xmlDoc->parse($XMLString);

# You may use the toHash() method to automatically
# convert the XML into a hash reference
my $xmlHash = $xmlDoc->toHash();

print Dumper($xmlHash);

# You can also manipulate the elements like directly, like this:

# Fetch the ROOT element for the document
# (an instance of XML::Mini::Element)
my $xmlRoot = $xmlDoc->getRoot();

# play with the element and its children
# ...
my $topLevelChildren = $xmlRoot->getAllChildren();

foreach my $childElement (@{$topLevelChildren})
{
    # ...
}

###### CREATING XML #######

# Create a new document from scratch

my $newDoc = XML::Mini::Document->new();

# This can be done easily by using a hash:
my $h = {
 'spy'  => {
    'id'    => '007',
    'type'  => 'SuperSpy',
    'name'  => 'James Bond',
    'email' => 'mi5@london.uk',
    'address'    => 'Wherever he is needed most',
    },
};

$newDoc->fromHash($h);

# Or new XML can also be created by manipulating
#elements directly:

my $newDocRoot = $newDoc->getRoot();

# create the <? xml ?> header
my $xmlHeader = $newDocRoot->header('xml');
# add the version
$xmlHeader->attribute('version', '1.0');

my $person = $newDocRoot->createChild('person');

my $name = $person->createChild('name');
$name->createChild('first')->text('John');
$name->createChild('last')->text('Doe');

my $eyes = $person->createChild('eyes');
$eyes->attribute('color', 'blue');
$eyes->attribute('number', 2);

# output the document
print $newDoc->toString();

and this example would output, bestie:

<?xml version="1.0"?>
 <person>
  <name>
   <first>
    John
   </first>
   <last>
    Doe
   </last>
 </name>
 <eyes color="blue" number="2" />
 </person>

it's giving clean. it's giving valid markup. we love to see it πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so XML::Mini is a whole little family of Perl classes that lets you access XML data and create valid XML output using a tree-based hierarchy of elements. the MiniXML API has both a Perl and a PHP implementation β€” bilingual icon behavior ✨

it hands you an easy, object-oriented interface for manipulating XML documents and their elements. it's currently out there being used to send requests and understand responses from remote servers in Perl or PHP applications. and fun fact: an XML::Mini based parser is now being tested inside the RPC::XML framework. main character energy fr fr πŸ”₯

big slay: XML::Mini does not require any external libraries or modules and is pure Perl. if it's available though, XML::Mini will use the Text::Balanced module in order to escape limitations of the regex-only approach (eg "cross-nested" tag parsing). so it'll upgrade itself if it can 🫢

the Mini.pm module includes a number of variables you may use to tweak XML::Mini's behavior. these include:

  • $XML::Mini::AutoEscapeEntities β€” when greater than 0, the values set for nodes are automatically escaped, thus $element->text('4 is > 3') will set the contents of the appended node to '4 is &gt; 3'. default setting is 1.
  • $XML::Mini::IgnoreWhitespaces β€” when greater than 0, extraneous whitespaces will be ignored (maily useful when parsing). thus <mytag> Hello There </mytag> will be parsed as containing a text node with contents 'Hello There' instead of ' Hello There '. default setting is 1.
  • $XML::Mini::CaseSensitive β€” when greater than 0, element names are treated as case sensitive. thus, $element->getElement('subelement') and $element->getElement('SubElement') will be equivalent. defaults to 0.
πŸ’€ heads up bestie: that last one's description is exactly how it reads β€” max out $XML::Mini::CaseSensitive to get case sensitivity. don't come for me, I just write it like I see it πŸ™ˆ

πŸŽ€ Class methods πŸŽ€

⭐ escapeEntites TOENCODE

this method returns TOENCODE with HTML sensitive values (eg '<', '>', '"', etc) HTML encoded. (yes, that spelling is the real one, no cap, we keep it exactly as-is πŸ’…)

⭐ Log MESSAGE

logs the message to STDERR.

⭐ Error MESSAGE

logs MESSAGE and exits the program, calling exit(). dramatic but valid 😭

⭐ ignoreDeepRecursionWarning

XML::Mini uses deep recursion on big XML docs, and that's normal. but the warnings are a pain. $XML::Mini::IgnoreDeepRecursionWarnings is set to TRUE by default, and ignoreDeepRecursionWarning() is called by XML::Mini::Document if it is set. to bypass this behavior:

use XML::Mini;

$XML::Mini::IgnoreDeepRecursionWarnings = 0;

use XML::Mini::Document;

# ...

🌈 AUTHOR 🌈

Copyright (C) 2002-2008 Patrick Deegan, Psychogenic Inc.

Programs that use this code are bound to the terms and conditions of the GNU GPL (see the LICENSE file). if you wish to include these modules in non-GPL code, you need prior written authorisation from the authors.

this library is released under the terms of the GNU GPL version 3, making it available only for free programs ("free" here being used in the sense of the GPL, see http://www.gnu.org for more details). anyone wishing to use this library within a proprietary or otherwise non-GPLed program MUST contact psychogenic.com to acquire a distinct license for their application. this approach encourages the use of free software while allowing for proprietary solutions that support further development. ✨ (lowkey a whole philosophy moment)

πŸ“œ LICENSE πŸ“œ

XML::Mini::Element module, part of the XML::Mini XML parser/generator package.
Copyright (C) 2002-2008 Patrick Deegan
All rights reserved

XML::Mini is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

XML::Mini is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with XML::Mini.  If not, see <http://www.gnu.org/licenses/>.

πŸ’œ SEE ALSO πŸ’œ


and that's the whole page bestie, no notes πŸŽ€ this was XML::Mini(3pm) from perl v5.36.0, dated 2022-10-15 β€” go forth and parse, you absolute icon πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from