XML::Mini::Document 1.2.8 review

Download
by rbytes.net on

XML::Mini::Document is a Perl implementation of the XML::Mini Document API. SYNOPSIS use XML::Mini::Document;

License: Perl Artistic License
File size: 34K
Developer: Patrick Deegan, Psychogenic Inc.
0 stars award from rbytes.net

XML::Mini::Document is a Perl implementation of the XML::Mini Document API.

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();

This example would output :

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

The XML::Mini::Document class is the programmer's handle to XML::Mini functionality.
A XML::Mini::Document instance is created in every program that uses XML::Mini. With the XML::Mini::Document object, you can access the root XML::Mini::Element, find/fetch/create elements and read in or output XML strings.

Requirements:
Perl

XML::Mini::Document 1.2.8 keywords